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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
990
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
SRE歴2ヶ月でも開発6年の知見を活かして、チームで止まっていた環境改善を前に進めた話
a_ono
0
170
打造你的 AI 工作流:Agent Skill + MCP 實戰工作坊
appleboy
0
320
組織における AI-DLC 実践
askul
0
260
フロントエンドイチゲキ実装 ― Figmaデザインと画面設計書からAIに実装・テストを書かせるための”下ごしらえ” / 20260627 Yusuke Mazuka
shift_evolve
PRO
0
120
RAGの精度向上とエージェント活用
kintotechdev
2
110
フルAIで個人開発して学んだあれこれ / yuruai vol.1
isaoshimizu
0
160
飲食店もAIで。レジ締めやハンディシステムをつくってる話 / Using AI for restaurant management
vtryo
0
220
小さいから、全部わかる。— 常駐AI "xangi" のすすめ
sugupoko
0
220
テスト設計の本質を改めて考えてみる~生成AIを活用する時代だからこそ、作ったテストの説明性を高めよう~
yamasaki696
1
260
時期が悪い!それでもRaspberry Piを買って遊んで活用するには / 20260627-osc26do-rpi-jikigawarui
akkiesoft
1
960
AIペネトレーションテスト・ セキュリティ検証「AgenticSec」紹介資料
laysakura
2
7.9k
5分でわかる Amazon Connect_20260608
hwangbyeonghun
0
160
Featured
See All Featured
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
220
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
WENDY [Excerpt]
tessaabrams
11
38k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
250
How STYLIGHT went responsive
nonsquared
100
6.2k
Six Lessons from altMBA
skipperchong
29
4.3k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
240
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
280
How to train your dragon (web standard)
notwaldorf
97
6.7k
Done Done
chrislema
186
16k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
370
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
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ͱ͔ྑͦ͞͏