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
980
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
日本 Fintech 未来予測レポート 2027〜2028年(オリジナル版)
8maki
0
950
生成 AI × MCP で切り拓く次世代 SRE!自律型運用への挑戦と開発者体験の進化
_awache
0
190
Oracle Cloud Infrastructure IaaS 新機能アップデート 2026/3 - 2026/5
oracle4engineer
PRO
1
250
作って終わりにしない タイミーのセマンティックレイヤー育成の現在地
chanyou0311
3
2.1k
DevOps Agentで始めるAWS運用 〜フロンティアエージェントが変える運用の現場〜
nyankotaro
1
360
社内 AI エージェント Synapse と セマンティックレイヤーの育て方
hiroakis
2
1.5k
Building applications in the Gemini API family.
line_developers_tw
PRO
0
2.8k
FDE という解 ― 暗黙知と明示知をつなぐ、伴走型エンジニアリング ―
otanet
0
120
中期計画、2回作ってみた ~業務委託と正社員、両方の視点から~
demaecan
1
620
SIer20年! 培ったスキルがスタートアップで輝く時
shucho0103
0
820
Bucharest Tech Week 2026 - Reinventing testing practices in the AI era
edeandrea
PRO
1
130
"何を作るか"を任される エンジニアは、どう育つのか
yutaokafuji
1
540
Featured
See All Featured
The agentic SEO stack - context over prompts
schlessera
0
800
Site-Speed That Sticks
csswizardry
13
1.2k
Fireside Chat
paigeccino
42
3.9k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
340
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
160
Skip the Path - Find Your Career Trail
mkilby
1
140
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
160
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
Bash Introduction
62gerente
615
220k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
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ͱ͔ྑͦ͞͏