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
生成 AI × MCP で切り拓く次世代 SRE!自律型運用への挑戦と開発者体験の進化
_awache
0
190
Rancherの紹介&Update情報(RancherJP Online Meetup #09)
yoshiyuki_kono
0
140
新しいVibe Codingと”自走”について
watany
5
270
AI活用を推進するために ファインディが下した、一つの小さな決断
starfish719
0
290
2026.06.13_AI時代に事業会社が「SIer出身エンジニア」を求める理由 / Why Businesses Seek Engineers with a System Integrator Background in the AI Era
jumtech
0
1k
なぜ Platform Engineering の土台に Kubernetes を選ぶのか
r4ynode
1
520
日本 Fintech 未来予測レポート 2027〜2028年(手動編集版)
8maki
0
390
Oracle Cloud Infrastructure IaaS 新機能アップデート 2026/3 - 2026/5
oracle4engineer
PRO
1
240
AWSシリコン最前線 〜AI時代のチップ選択を読み解く〜
htokoyo
2
350
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
6
1.9k
チームで実践する AI-DLC 思考の軌跡を残すチェックポイント設計
belongadmin
0
3.2k
MCP Appsを作ってみよう
iwamot
PRO
4
370
Featured
See All Featured
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
340
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Designing Powerful Visuals for Engaging Learning
tmiket
1
410
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
1.1k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
410
Designing Experiences People Love
moore
143
24k
AI: The stuff that nobody shows you
jnunemaker
PRO
8
700
Joys of Absence: A Defence of Solitary Play
codingconduct
1
390
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ͱ͔ྑͦ͞͏