Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
GoとTOML
Search
Tatsuhiko Kubo
April 13, 2015
Technology
6.6k
8
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
GoとTOML
Tatsuhiko Kubo
April 13, 2015
More Decks by Tatsuhiko Kubo
See All by Tatsuhiko Kubo
Mackerel in さくらのクラウド
cubicdaiya
1
1k
Handling a tremendous amount of images with Fastly / Yamagoya Traverse 2020
cubicdaiya
2
1.6k
System Integration with Fastly
cubicdaiya
0
680
実例で学ぶ画像最適化集 with ImageFlux / ImageFlux meetup#2
cubicdaiya
4
20k
Software Engineer, Infrastructure
cubicdaiya
4
3.3k
High Performance Count Up!
cubicdaiya
0
430
ImageFluxを利用した画像配信の最適化 / ImageFlux meetup 201801
cubicdaiya
0
3.1k
Building high performance push notification server in Go
cubicdaiya
5
3.4k
メルカリのデータ分析基盤 / mercari data analysis infrastructure
cubicdaiya
11
12k
Other Decks in Technology
See All in Technology
AWS環境のセキュリティ不安を解消した企業事例 ~よくある課題と対策を一挙公開~
asanoharuki
0
200
GoでCコンパイラを作った話
repunit
0
170
それでも、技術なブログを書く理由 #kichijojipm / Why I Still Write Tech Blogs Even Now
shinkufencer
0
1k
StepFunctionsとGraphRAGを活用した暗黙知活用のためのRAG基盤
yakumo
0
180
AIが当たり前の組織で エンジニアはどう育つか
nishihira
1
1.4k
Claude CodeとAmazon Bedrock AgentCoreでつくる、自分だけのAIアシスタント
ymae
0
110
QA・ソフトウェアテスト研修【MIXI 26新卒技術研修】
mixi_engineers
PRO
2
980
脱Jenkins、インターン生が挑んだCIツールGitHubActions移行
mixi_engineers
PRO
1
130
OPENLOGI Company Profile for engineer
hr01
1
75k
ここは地獄!つらい朝会を体験することで、チームとしてのより良い振る舞いに気づくワークショップ / The stand-up meeting from hell in the game industry
scrummasudar
0
340
変更し続けられるシステムをどう保つか — AI時代のSSoTという設計原則
kawauso
1
1.3k
AI工学特論: MLOps・継続的評価
asei
11
2.8k
Featured
See All Featured
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
Utilizing Notion as your number one productivity tool
mfonobong
4
470
Faster Mobile Websites
deanohume
310
32k
The Spectacular Lies of Maps
axbom
PRO
1
870
Speed Design
sergeychernyshev
33
1.9k
Test your architecture with Archunit
thirion
1
2.3k
Rails Girls Zürich Keynote
gr2m
96
14k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
350
The World Runs on Bad Software
bkeepers
PRO
72
12k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
4k
Transcript
GoͱTOML Tatsuhiko Kubo@cubicdaiya Gunosy.go#12@2015/04/13
ࣗݾհ • ٱอୡ(Tatsuhiko Kubo) • bokko@cubicdaiya • Software Engineer in
Infrastructure Engineering • Mercari, Inc.
OSS࡞ͬͨΓίϯτϦϏϡʔτͨ͠Γ
Agenda GoͰϓϩάϥϜΛॻ͘ࡍͷઃఆϑΝΠϧʹ͍ͭͯ
Έͳ͞ΜɺઃఆϑΝΠϧʹ ීஈԿΛͬͯ·͔͢ʁ
JSONYAMLʹINIɺ ࠷ۙͩͱTOML ͳΜ͔͋Γ·͢ΑͶ
ࠓճ͕ීஈGoͰ։ൃ͢Δࡍʹ ར༻͢ΔઃఆϑΝΠϧܗࣜͷTOMLʹ ͍࣮ͭͯྫΛ౿·͑ͳ͕Βղઆ͠·͢
ͦͦઃఆϑΝΠϧ͕ඞཁͳཧ༝ • ͨ͘͞ΜͷίϚϯυϥΠϯҾ • ϓϩάϥϜͷύϥϝʔλ੍ޚ • ϓϩάϥϜ෦ͷৄࡉ͕Θ͔Βͳ͍ਓͰϓ ϩάϥϜͷมߋΛՄೳʹ͍ͨ͠
ઃఆهड़ݴޠ(ͱͯ͑ͦ͠͏ͳͷ) • XML • INI • JSON • YAML •
TOML • ܰྔݴޠ(Lua, mruby, etc…)
ݸਓతʹ͏͍͍ͱࢥͬͯΔͭ • XML • ਓ͕ؒॻ͘ͷ͡Όͳ͍ • YAML • ਓؒʹॻ͖͍͚͢Ͳ༷͕ෳࡶ •
JSON • ίϝϯτ͕ॻ͚ͳ͍ • 8ਐ͕͑ͳ͍(e.g. ύʔϛογϣϯͱ͔) • ඌͷΧϯϚফ͠ΕͯγϯλοΫεΤϥʔorz • σʔλϑΥʔϚοτͱͯ͠༏ल͕ͩઃఆϑΝΠϧͱͯͭ͠Β͍
ઃఆهड़ݴޠ(ͱͯ͑ͦ͠͏ͳͷ) • INI • TOML • ܰྔݴޠ(Lua, mruby, etc…)
ઃఆهड़ݴޠ(ͱͯ͑ͦ͠͏ͳͷ) • INI • TOML • ܰྔݴޠ(Lua, mruby, etc…) ࠓճ͕࣌ؒͳ͍ͷͰল͖·͢
TOML • ͋ΔҙຯAdvanced-INI • ਓ͕ؒಡΈॻ͖͍͢͠ • ྻɺ֊ߏ͕ѻ͑Δ • ࠷͕ۙࣗGoͰ։ൃ͢Δ࣌΄΅͜Ε
TOMLͷGo࣮ • ͍Ζ͍Ζ͋Δ͚ͲˣΛͬͯ·͢ • github.com/BurntSushi/toml • ઃఆϑΝΠϧͷΛͦͷ··ߏମʹϚοϐϯάՄೳ • encoding/jsonͷMarshalͱUnMarshalΈ͍ͨͳײ͡ •
TOMLͷઃఆࣗମΛੜ͢Δ͜ͱՄೳ
TOML in Go cachectlͷ߹
cachectl • GoͰॻ͔ΕͨOSͷϖʔδΩϟογϡ֬ೝɾআπʔϧ • https://github.com/cubicdaiya/cachectl • ແବͳϖʔδΩϟογϡΛղ์͢Δͷʹར༻ • cachectld͍ͬͯ͏σʔϞϯ͕͍ͯΔ •
͜ͷσʔϞϯͷઃఆϑΝΠϧ͕TOML
cachectld.toml
slackboard • GoͰॻ͔ΕͨSlackϓϩΩγ • https://github.com/cubicdaiya/slackboard • ͜ΕͷઃఆϑΝΠϧTOML
slackboard.toml [core] port = "29800" slack_url = "https://hooks.slack.com/services/..." [[tags]] tag
= "general" channel = "#general" [[tags]] tag = "random" channel = "#random" username = "slackboard" icon_emoji = ":clipboard:" parse = "full" [log] access_log = "stdout" error_log = "stderr" level = "error" [ui] root = "/var/www/slackboard"
TOMLઃఆ༻ͷߏମఆٛ(cachectld.toml) type ConfToml struct { Targets []SectionTarget `toml:"targets"` } type
SectionTarget struct { Path string `toml:"path"` PurgeInterval uint64 `toml:"purge_interval"` Filter string `toml:"filter"` Rate float64 `toml:"rate"` } encoding/jsonϥΠΫͳΞϊςʔγϣϯ
TOMLઃఆ༻ͷߏମఆٛ(slackboard.toml) type ConfToml struct { Core SectionCore `toml:"core"` Tags []SectionTag
`toml:"tags"` Log SectionLog `toml:"log"` UI SectionUI `toml:"ui"` } type SectionCore struct { Port string `toml:"port"` SlackURL string `toml:"slack_url"` } type SectionTag struct { Tag string `toml:"tag"` Channel string `toml:"channel"` Username string `toml:"username"` IconEmoji string `toml:"icon_emoji"` Parse string `toml:"parse"` } type SectionLog struct { AccessLog string `toml:"access_log"` ErrorLog string `toml:"error_log"` Level string `toml:"level"` } type SectionUI struct { Root string `toml:"root"` }
TOMLϑΝΠϧͷϩʔυ func LoadConf(confPath string, confToml *ConfToml) error { _, err
:= toml.DecodeFile(confPath, confToml) if err != nil { return err } return nil } ؆୯Ͱ͢Ͷ
TOMLઃఆͷΤΫεϙʔτ var b bytes.Buffer // ݱࡏͷTOMLͷઃఆΛόοϑΝʹॻ͖ग़͢ e := toml.NewEncoder(&b) err
:= e.Encode(confToml) if err != nil { log.Fatal(err.Error()) } // ઃఆϑΝΠϧͷ༰Λग़ྗ fmt.Println(b.String())
·ͱΊ • TOML͍͍ΑTOML • GoͳΒˣ͕͓͢͢Ί • github.com/BurntSushi/toml • P.S. •
հ͢Δ࣌ؒͳ͔͚ͬͨͲgopher-luaͱ͔ྑͦ͞͏