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
独自ファイル形式にStructTagで立ち向かう
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
atsushi-ishibashi
June 10, 2019
Technology
0
71
独自ファイル形式にStructTagで立ち向かう
atsushi-ishibashi
June 10, 2019
Tweet
Share
More Decks by atsushi-ishibashi
See All by atsushi-ishibashi
コンテナ運用におけるアプリケーション設定管理
atsushi51
0
500
モダンなアーキテクチャでゼロから作る証券基盤
atsushi51
1
2.8k
Goによるスキーマ駆動開発
atsushi51
1
1.8k
AWSにおけるクラウドネイティブでセキュアな証券システムの運用
atsushi51
0
140
クラウドインフラの権限
atsushi51
0
67
AWSとGo言語とコンテナによる証券プラットフォーム
atsushi51
0
81
StepFunctionsフルコース
atsushi51
0
110
DevSecOps実践
atsushi51
0
140
Other Decks in Technology
See All in Technology
Tebiki Engineering Team Deck
tebiki
0
27k
visionOS 開発向けの MCP / Skills をつくり続けることで XR の探究と学習を最大化
karad
1
1.2k
20260321_エンベディングってなに?RAGってなに?エンベディングの説明とGemini Embedding 2 の紹介
tsho
0
150
テストプロセスにおけるAI活用 :人間とAIの共存
hacomono
PRO
0
140
品質を経営にどう語るか #jassttokyo / Communicating the Strategic Value of Quality to Executive Leadership
kyonmm
PRO
2
1.1k
AgentCoreとLINEを使った飲食店おすすめアプリを作ってみた
yakumo
2
170
スピンアウト講座04_ルーティン処理
overflowinc
0
860
Copilot 宇宙へ 〜生成AIで「専門データの壁」を壊す方法〜
nakasho
0
150
スピンアウト講座01_GitHub管理
overflowinc
0
990
A4)シラバスを超えて語る、テストマネジメント
moritamasami
0
110
Phase05_ClaudeCode入門
overflowinc
0
1.6k
SaaSに宿る21g
kanyamaguc
2
110
Featured
See All Featured
エンジニアに許された特別な時間の終わり
watany
106
240k
SEO for Brand Visibility & Recognition
aleyda
0
4.4k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
180
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
RailsConf 2023
tenderlove
30
1.4k
A better future with KSS
kneath
240
18k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
110k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
89
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
500
Six Lessons from altMBA
skipperchong
29
4.2k
Transcript
ಠࣗϑΝΠϧܗࣜʹ StructTagͰཱ͔ͪ͏ Finatext ੴڮ ३ࢤ
Finatext
None
None
ࣗݾհ - ੴڮ३ࢤ • ࡏֶதʹFinatextʹؔΘΔ • εϚʔτϓϥεͷূ݊γεςϜͷઃܭɾߏஙΛ ୲ • ࠒ͍ͬͯΔݴޠɿGoݴޠ
• terraform-provider-awsʹͦͦ͜͜ߩݙ • झຯɿαφ • @bashi0501
StructTagͬͯ·͔͢ʁ
• json, xml • form, query • db • validate
(gopkg.in/go- playground/validator.v9) Α͘͏λά
• ͋ΔϑΥʔϚοτͷΤϯίʔυ/ σίʔυΛָ͍ͨ͠ • ΞϊςʔγϣϯͰॲཧ༰Λઃఆ ͍ͨ͠ ༻్
TagΛࣗ࡞ͨ͜͠ͱ͋Δਓ!
ͲΜͳϑΝΠϧʁ • SHIFT_JIS • ݻఆ
encoding/jsonύοέʔδʹ฿ͬͯ 2ͭͷؔΛ࣮ package custom func Unmarshal(p []byte, v interface{}) error
func Marshal(v interface{}) ([]byte, error)
func Unmarshal(p []byte, v interface{}) error { //reflect.Value tt :=
reflect.ValueOf(v) // reflect.Kind // ΈࠐΈܕ,Ptr,Interface,StructͳͲͷܕΛද͢enum if tt.Kind() != reflect.Ptr { return error } // PtrͷnilνΣοΫ if tt.IsNil() { return error } // Elem returns the value that interface contains or that pointer points to elem := tt.Elem() fmt.Println(elem.Kind()) // struct … Unmarshal
func Unmarshal(p []byte, v interface{}) error { … elem :=
tt.Elem() //reflect.Type // t := elem.Type() //֤fieldʹରͯ͠ॲཧΛ͍ͯ͘͠ for i := 0; i < t.NumField(); i++ { //reflect.StructField //Field໊ܕɺTagͳͲͷใΛࢀরͰ͖Δ field := t.Field(i) fmt.Println(field.Name) //field໊ fmt.Println(field.Type.Kind()) //reflect.Kindͱͯ͠ͷܕ fmt.Println(field.Type.Name()) //typeએݴΛࣝผ͍ͨ͠ͱ͖ tag, ok := field.Tag.Lookup(“tagName”) //͋ͱtagΛύʔεͯ͠p []byte͔Β͏·͍͜ͱσʔλऔ͖ͬͯͯ elem.Field(i).SetXXX(foo(p)) } }
func Marshal(v interface{}) ([]byte, error) { tt := reflect.ValueOf(v) switch
rv.Kind() { case reflect.Ptr, reflect.Interface: if rv.IsNil() { return nil, error } tt = tt.Elem() case reflect.Struct: default: return nil, error } t := tt.Type() for i := 0; i < t.NumField(); i++ { field := rt.Field(i) tag, ok := field.Tag.Lookup(“tagName”) // do something ttf := tt.Field(i) switch ttf.Kind() { case reflect.String: stringValue := ttf.String() // ग़ྗ͢Δ[]byteʹରͯ͠ૢ࡞ Marshal
type Hoge struct { ID string `custom:”1,5”` // 1byte͔Β5byte Count
int64 `custom:”6,2”` IsFlag bool `custom:"8,1"` Price float64 `custom:"9,5"` Abs uint64 `custom:"14,3"` } p := []byte(`abcde101002.3543`) var hoge Hoge Unmarshal(p, &hoge) hoge.ID // abcde hoge.Count // 10 hoge.IsFlag // true hoge.Price // 2.3 hoge.Abs // 543 Unmarshalͷྫ
type Hoge struct { ID string `custom:”1,5"` Count int64 `custom:”6,2”`
IsFlag bool `custom:"8,1"` Price float64 `custom:"9,5"` Abs uint64 `custom:"14,3"` } hoge := Hoge{ ID: “abcde”, Count: “10”, IsFlag: true, Price: 2.3, Abs: 543, } p, err := Marshal(hoge) fmt.Println(string(p)) // abcde101002.3543 Marshalͷྫ
ಠ༷ࣗͷϑΝΠϧ Ͱͷ࿈ܞ ಠࣗϑΥʔϚοτ Ͱͷ௨৴ ؆୯ʹѻ͑Δ
͍ɺ ͦͦಠࣗϑΥʔϚοτ ࠷ޙͷखஈ$
• ৭Μͳ͜ͱग़དྷͦ͏ͳؾʹͳΔ ͕ɺͦΕͨͿΜTagͰΔ͜ ͱ͡Όͳ͍ • ࡞Βͳͯ͘ྑ͍ʹӽͨ͜͠ͱ ͳ͍ ·ͱΊ