Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
interfaceとの付き合い
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
michiru shirakawa
November 14, 2017
Programming
2.3k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
interfaceとの付き合い
michiru shirakawa
November 14, 2017
More Decks by michiru shirakawa
See All by michiru shirakawa
2025年予言の書
mishirakawa
1
400
あらゆる変化を受け入れながら 働きつづける - 介護・学業編
mishirakawa
3
3.8k
まだまだ楽しい!あらゆる変化を受け入れながら 働きつづけるコツ
mishirakawa
0
1.7k
技術書典のネタづくり
mishirakawa
0
570
Go の並行処理を体験してみよう
mishirakawa
1
180
VimConf の効用
mishirakawa
0
60
Lose Weight with Vim and Go
mishirakawa
0
220
はじめてのプログラミングにGo
mishirakawa
2
1.7k
Introduction of Women Who Go Tokyo
mishirakawa
2
3.2k
Other Decks in Programming
See All in Programming
AIエージェント時代のコードレビューを設計する
nogu66
6
2.6k
新人はどこまで自力でやり、どこからAIに頼るべきか/エンジニア育成に向き合う_先輩たちの悩みと知見共有会
toppan_digital_dev
1
610
一参加者から『中の人』へ 〜全通PHPerがブースに立って学んだ、カンファレンスを100倍楽しむコツ〜
wp_daisuke
0
140
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
130
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
180
AIは賢い。でも実行環境は? CLIおじさんがAI時代に伝えたいこと ~ CLIおじさんがAI時代に伝えたいこと ~
curekoshimizu
1
240
iOSDC Japan 2026 - Swiftで作って学ぼう!データベース自作入門
kaseken
2
130
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
2.5k
変化を抱擁するドキュメントの作り方 - ビジネスルール駆動開発がもたらす、コードとの新しい関係
ioki
2
150
自分的「カンファレンスの楽しみ方」
syumai
0
200
AWS Step Functions 大規模並列の壁を越える / jaws-sonic-2026-niigata-step-functions
kasacchiful
PRO
1
440
Omarchy Tokyo やると聞いて UMPC 買ってセットアップしてきた
mtsmfm
0
140
Featured
See All Featured
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.3k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Abbi's Birthday
coloredviolet
3
9.9k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Mobile First: as difficult as doing things right
swwweet
225
10k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
240
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Navigating Team Friction
lara
192
16k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
680
The Cult of Friendly URLs
andyhume
79
7k
Thoughts on Productivity
jonyablonski
76
5.4k
Transcript
golang.tokyo #10 x WomenWhoGoTokyo interfaceͱͷ͖߹͍ micchie@WomenWhoGoTokyo ©micchie Women Who go
Tokyo, 2017 1
WomenWhoGoTokyo αϯϑϥϯγείൃͷ, ঁੑͷGoݴޠͷίϛϡχςΟͰ͢ɻ ݱࡏ11Χࠃ(ࢢผͰ25ڌ ❗ )ఔͰߦΘΕ͓ͯΓ, ౦ژ2016 4݄ʹൃ͠·ͨ͠ɻ ݄ʹ1ճ, ฏͷ19͔࣌ΒͰू·Γ,
ษڧձΛߦ͍ͬͯ·͢ɻ ܦݧεΩϧ·͍ͬͨ͘·ͤΜɻॳΊͯͷํࢀՃ͍͢͠ ձΛࢦ͍ͯ͠·͢㷉◔ϖ◔ʔ ©micchie Women Who go Tokyo, 2017 2
ʕ•ᴥ•ʔʻͳ͠Λ͍ͨ͜͠ͱ interfaceʹ͍ͭͯ ͜Μͳ෩ʹΓ·ͨ͠ ©micchie Women Who go Tokyo, 2017 3
͘͢͝టष͍Ͱ͢ɻ ©micchie Women Who go Tokyo, 2017 4
ʕ•ᴥ•ʔʻࢥ͍͜Έ ͔ͬ͠Γͱͨ͠ܕ͚ݴޠͰ͋Δ͕Ώ͑ʹ ॊೈͳऔѻ͍͍͠ͷͰͳ͍͔ ©micchie Women Who go Tokyo, 2017 5
ʕ•̀ᴥ•́ʔʻࣗ༝ͳߏͷJsonϑΝΠϧΛऔΓࠐΈ͍ͨΜͰ͢ ʕ•́ᴥ•̀ʔʻݹʹઃܭ͞Εͨڥ͔Β৽͍͠ͷʹҠߦ͍ͨ͠ΜͰ͢ ©micchie Women Who go Tokyo, 2017 6
͜Μͳײ͡ͷJSONΛ... [ { "11": ["ΞϝϦΧάϚ", "ผ໊ΞϝϦΧΫϩΫϚɻϓʔ͞ΜͷϞσϧɻ", 100] }, { "12":
["πΩϊϫάϚ", "टͷ෦͕ന͍ໟͰࡾ݄ঢ়ʹݟ͑Δ͜ͱ͔ΒπΩϊϫάϚͱݺΕΔɻ", 90] }, { "13": ["ϋΠΠϩάϚ", "ผ໊άϦζϦʔɻώάϚͷؒɻ", 30] }, { "14": ["ϗοΩϣΫάϚ", "γϩΫϚɻۃʹ͍Δ͕ɺೆۃʹ͍ͳ͍ɻ্࠷େͷ৯्ɻݮ͍ͬͯΔɻ", 80] }, { "15": ["ϚϨʔάϚ", "খ͕͘͞ѱ͘ɺઉ͕͍ɻύσΟϯτϯɻ", 50] } ] ©micchie Women Who go Tokyo, 2017 7
͜ΜͳߏͰཧͯ͠, ಉ͡Α͏ʹग़ྗ͍ͨ͠ɻ DataBase: CREATE TABLE `animals` ( `id` bigint NOT
NULL PRIMARY KEY, `name` varchar(255) NOT NULL, `description` text NOT NULL, `rate` int NOT NULL ) Struct: type Animals struct { ID uint `json:"id"` Name string `json:"name"` Description string `json:"description"` Rate int `json:"rate"` } ©micchie Women Who go Tokyo, 2017 8
ૉʹAnimalsߏମΛjson.Marshal͢Δͱ, ԼهͷΑ͏ʹͳΔɻ [ { "id": 11, "name": "ΞϝϦΧάϚ", "description": "ผ໊ΞϝϦΧΫϩΫϚɻϓʔ͞ΜͷϞσϧɻ",
"rate": 100 }, { "id": 12, "name": "πΩϊϫάϚ", "description": "टͷ෦͕ന͍ໟͰࡾ݄ঢ়ʹݟ͑Δ͜ͱ͔ΒπΩϊϫάϚͱݺΕΔɻ", "rate": 90 }, ... ... { "id": 15, "name": "ϚϨʔάϚ", "description": "খ͕͘͞ѱ͘ɺઉ͕͍ɻύσΟϯτϯɻ", "rate": 50 } ] ©micchie Women Who go Tokyo, 2017 9
ͦ͜ͰinterfaceͰΰχϣΰχϣ͢Δͱ... ... var list []interface{} var row Animals for rows.Next()
{ ... ... id := fmt.Sprint(row.ID) // IDΛstringʹ descriptions := map[string]interface{}{id: []interface{}{row.Name, row.Description, row.Rate}} list = append(list, descriptions) } ... j, err := json.Marshal(list) ... ©micchie Women Who go Tokyo, 2017 10
json.Unmarshal͢Δͱ... &[ map[11:[ΞϝϦΧάϚ ผ໊ΞϝϦΧΫϩΫϚɻϓʔ͞ΜͷϞσϧɻ 100]] map[12:[πΩϊϫάϚ टͷ෦͕ന͍ໟͰࡾ݄ঢ়ʹݟ͑Δ͜ͱ͔ΒπΩϊϫάϚͱݺΕΔɻ 90]] map[13:[ϋΠΠϩάϚ ผ໊άϦζϦʔɻώάϚͷؒɻ
30]] map[14:[ϗοΩϣΫάϚ γϩΫϚɻۃʹ͍Δ͕ɺೆۃʹ͍ͳ͍ɻ্࠷େͷ৯्ɻݮ͍ͬͯΔɻ 80]] map[15:[ϚϨʔάϚ খ͕͘͞ѱ͘ɺઉ͕͍ɻύσΟϯτϯɻ 50]] ] ͜ͷΑ͏ʹ֨ೲ͞ΕΔͷͰ, 1ߦͣͭॲཧΛ͍ͯ͘͠ɻ ©micchie Women Who go Tokyo, 2017 11
for _, row := range list { var animal Animals
for k, r := range row.(map[string]interface{}) { i, _ := strconv.Atoi(k) // keyJSON্stringͷͨΊ animal.ID = uint(i) v := r.([]interface{}) // fmt.Println(v) // [ΞϝϦΧάϚ ผ໊ΞϝϦΧΫϩΫϚɻϓʔ͞ΜͷϞσϧɻ 100] animal.Name = v[0].(string) animal.Description = v[1].(string) animal.Rate = int(v[2].(float64)) } ... // insertॲཧ } ©micchie Women Who go Tokyo, 2017 12
ʕ•̀ᴥ•́ʔʻࣗ༝ͳߏͷJsonϑΝΠϧΛऔΓࠐΈ͍ͨΜͰ͢ ʕ•́ᴥ•̀ʔʻݹʹઃܭ͞Εͨڥ͔Β৽͍͠ͷʹҠߦ͍ͨ͠ΜͰ͢ ©micchie Women Who go Tokyo, 2017 13
;Δ͍Ո͔Β͋ͨΒ͍͠ՈʹҾͬӽ͠Λ͍ͨ͠ɻ#1 type ( Before struct { ID uint `db:"id"` PostalCode
sql.NullInt64 `db:"postal_code"` Prefecture string `db:"prefecture"` Address sql.NullString `db:"address"` Hoge sql.NullString `db:"hoge"` } After struct { ID uint `db:"id"` PostalCode sql.NullInt64 `db:"postal_code"` Prefecture string `db:"prefecture"` Address sql.NullString `db:"address"` Hoge string `db:"hoge"` } ) #1 1ςʔϒϧͷΈൈਮ, HogeͷΈ͕ܕ͕ҟͳΔέʔεɻ ©micchie Women Who go Tokyo, 2017 14
ಉ͡ܕಉ࢜interfaceͰѻ͑·ͨ͠ɻ func main() { ... to := &After{ PostalCode: toYurufuwa(Before.PostalCode).(sql.NullInt64)
Prefecture: toYurufuwa(Before.Prefecture).(string) Address: toYurufuwa(Before.Address).()sql.NullString Hoge: toHoge(Before.Hoge) } ... } func toYurufuwa(before interface{}) interface{} { return before } func toHoge(before sql.NullString) string { if !before.Valid { return HOGE_DEFAULT } returne before.String } ©micchie Women Who go Tokyo, 2017 15
ͱ͜ΖͰ, Nullͳ߲Λѻ͏ͱ͖Կ͕࠷దͳΜͰ͠ΐ͏͔...? 1. *string *int 2. sql.NullString sql.NullInt64
3. `ͦͦNullڐՄͳઃܭΛ͠ͳ͍ ©micchie Women Who go Tokyo, 2017 16
ͱ͜ΖͰ, database/sqlͷcolumnsͲ͏ॻ͍͍ͯ·͔͢...? func (b Before) TableName() string { return "before_table_name"
} func (b Before) columns() (s []string) { t := reflect.TypeOf(c) for i := 0; i < t.NumField(); i++ { field := t.Field(i) s = append(s, field.Tag.Get("db")) } return s } ... sql := fmt.Sprintf( "SELECT %s FROM %s", strings.Join(Before.columns(), ","), Before.TableName(), ) ... ©micchie Women Who go Tokyo, 2017 17
• ϥϕϧ • @mi-bear, @micchiebear • Ϩϕϧ • ےઓ࢜ (15.0)
• Gopher (1.5) • Vim (0.3) • ଐੑ, ܕ • ! , " , # , 3DS • גࣜձࣾϦϒηϯε ©micchie Women Who go Tokyo, 2017 18
Thanks! Love Gophers Love Gophers The Go gopher was designed
by Renée French. ©micchie Women Who go Tokyo, 2017 19