Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Gunosy APIチームGo開発フロー

kyokomi
March 11, 2015

Gunosy APIチームGo開発フロー

Gunosy.go#11の発表内容です

kyokomi

March 11, 2015
Tweet

More Decks by kyokomi

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • Twi%er:)@k_yokomi)ʢ͖ΐ͜Έʣ※1 • 2015೥1݄ʹGunosy΁స৬ • GoΤϯδχΞ΍ͬͯ·͢ • Ҏલ͸ɺौ୩ͷ๭ήʔϜձࣾͰ Cocos2d;xΛ࢖ͬͨεϚϗήʔϜ։ൃ

    • ࠷ۙgo:generate͕ϚΠϒʔϜ ※1"ΞΠίϯ͸݄ඣͷᘡᘚ͞ΜͰ͢ɻ @k_yokomi,)2015)ʮGunosy)APIνʔϜ)Go։ൃϑϩʔʯ 2
  2. ΤσΟλ • IntelliJ)IDEA)Community)Edi3on • Sublime • Vim • Emacs gofmt

    -sͱ͔goimportsΛߦ͍ͬͯΔͷͰɺجຊతʹΤσΟλ ͷҧ͍Ͱࠔͬͨέʔε͸ͳ͍ɻ @k_yokomi,)2015)ʮGunosy)APIνʔϜ)Go։ൃϑϩʔʯ 8
  3. IntelliJ(IDEAͰGo • ࣗ෼͸IntelliJ)IDEAਪ͠ • Community)Edi3onʢແྉʣ • ࠷ۙɺGolang)Pulginͷ։ൃ͕IntelliJຊ ՈͷਓʁʹมΘͬͨΒ͍͠ • ver0.9ͷࠒͱ͘Β΂ͯɺ։ൃ΋׆ൃʹ

    ͳΓɺ͔ͳΓ࢖͍উखྑ͘ͳͬͨ • packageิ׬ɾίʔυิ׬ɾࢀরݩݕࡧ ͳͲͳͲ @k_yokomi,)2015)ʮGunosy)APIνʔϜ)Go։ൃϑϩʔʯ 9
  4. ϩʔΧϧͰͷಈ࡞֬ೝ • go test͢Δ • ΋͘͠͸build࣮ͯ͠ߦ͢Δ • gdb౳ͷσόοΨ͸جຊతʹ࢖͍ͬͯͳ͍ • printσόοάͰे෼

    • MySQL,Redis,MongoDB౳͸ɺϩʔΧϧͷ΋ͷΛར༻ @k_yokomi,)2015)ʮGunosy)APIνʔϜ)Go։ൃϑϩʔʯ 11
  5. ίʔσΟϯάΨΠυ ࠓ͸ɺίʔσΟϯάΨΠυ͸ͳ͍ɻҎԼ͘Β͍Ͱे෼ͳೝࣝɻ • A tour of goΛͻͱ௨Γ΍͓ͬͯ͘ • Effec&veGoΛҰಡ͢Δ •

    ӏࣂจහ͞ΜͷʮGoʹೖͬͯ͸Goʹै͑ʯΛҰಡ͢Δ※2 • golintͰͷfiled໊͸ରԠ͢ΔʢId34>3ID,3hogeUrl34>3hogeURL౳ʣ ※2"h$p:/ /ukai,go,talks.appspot.com/2014/gocon.slide#1 @k_yokomi,)2015)ʮGunosy)APIνʔϜ)Go։ൃϑϩʔʯ 12
  6. GitHubެ։͍ͯ͠ΔϥΠϒϥϦ ओͳϥΠϒϥϦΛൈਮʢଞʹ΋৭ʑ͋Γ·͢ʣ - gopkg.in/guregu/null.v2: nullՄೳSQLΛѻ͏ - github.com/guregu/toki: SQLTIMEܕͷnull஋Մೳ - github.com/guregu/buildver:

    build versionʢ4.1.10.5ʣͱ͔Λѻ͏ - github.com/guregu/mogi: sqlͷελϒ - github.com/guregu/kami: gojiϕʔεͷWebϑϨʔϜϫʔΫ - github.com/kyokomi/goebi: errbitΫϥΠΞϯτ @k_yokomi,)2015)ʮGunosy)APIνʔϜ)Go։ൃϑϩʔʯ 18
  7. package main import ( "fmt" "net/http" "strconv" "github.com/guregu/kami" "golang.org/x/net/context" )

    func main() { kami.Get("/foo/:id", fooHandler) kami.Get("/bar/:name", barHandler) } // fooHandler IDΛࢦఆͯ͠FooͳΜ͔औಘ͢ΔAPI func fooHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) { idStr := kami.Param(ctx, "id") // UserΛҰҙʹࣝผ͢ΔID numStr := r.FormValue("num") // ΞϨͷ݅਺ʢ1ʙ10ʣ key := r.FormValue("key") // ͦΕΛऔಘ͢ΔKey userID, err := strconv.Atoi(idStr) num, _ := strconv.Atoi(numStr) fmt.Println(userID, err, num, key) } // barHandler NameΛࢦఆͯ͠BarͳΜ͔औಘ͢ΔAPI func barHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) { // hogehoge } @k_yokomi,)2015)ʮGunosy)APIνʔϜ)Go։ൃϑϩʔʯ 27
  8. // NOTE: THIS FILE WAS PRODUCED BY THE // RENKIN

    APIDOC GENERATION TOOL (github.com/kyokomi/renkin) // DO NOT EDIT /* RENKIN APIDOC GENERATION TOOL (https://github.com/kyokomi/renkin). Get fooHandler ɾɾɾ IDΛࢦఆͯ͠FooͳΜ͔औಘ͢ΔAPI Path: "/foo/:id" Params: 1. `"id"`: UserΛҰҙʹࣝผ͢ΔID (kami.Param) 2. `"num"`: ΞϨͷ݅਺ʢ1ʙ10ʣ (r.FormValue) 3. `"key"`: ͦΕΛऔಘ͢ΔKey (r.FormValue) file at example/main.go. Get barHandler ɾɾɾ NameΛࢦఆͯ͠BarͳΜ͔औಘ͢ΔAPI Path: "/bar/:name" Params: none file at example/main.go. */ package main @k_yokomi,)2015)ʮGunosy)APIνʔϜ)Go։ൃϑϩʔʯ 28