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

Go開発で実際にやった事一通り

sutetotanuki
August 23, 2017
3.5k

 Go開発で実際にやった事一通り

エウレカ x クラスメソッド 夜の合同勉強会 ~Go言語開発の実際のところ~ in 大阪 発表資料

http://dev.classmethod.jp/news/golang-osaka/

https://classmethod.connpass.com/event/62945/

sutetotanuki

August 23, 2017
Tweet

Transcript

  1. ~go ├── bin ├── gobin │ ├── go1.8.3 │ │

    └── go │ └── go1.8.3.darwin-amd64.tar.gz ├── pkg │ └── darwin_amd64 │ ├── github.com │ └── golang.org └── src ├── github.com │ ├── cm-nishida-masayuki │ ├── codegangsta │ ├── daviddengcn │ ├── hiroshi-manabe │ ├── jteeuwen │ ├── mitchellh │ └── motemen └── golang.org  σΟϨΫτϦߏ੒
  2. ~go ├── bin ├── gobin │ ├── go1.8.3 │ │

    └── go │ └── go1.8.3.darwin-amd64.tar.gz ├── pkg │ └── darwin_amd64 │ ├── github.com │ └── golang.org └── src ├── github.com │ ├── cm-nishida-masayuki │ ├── codegangsta │ ├── daviddengcn │ ├── hiroshi-manabe │ ├── jteeuwen │ ├── mitchellh │ └── motemen └── golang.org (01"5)Λ ௨ͯ͠Δͱ͜Ζ 
  3. ~go ├── bin ├── gobin │ ├── go1.8.3 │ │

    └── go │ └── go1.8.3.darwin-amd64.tar.gz ├── pkg │ └── darwin_amd64 │ ├── github.com │ └── golang.org └── src ├── github.com │ ├── cm-nishida-masayuki │ ├── codegangsta │ ├── daviddengcn │ ├── hiroshi-manabe │ ├── jteeuwen │ ├── mitchellh │ └── motemen └── golang.org ௥Ճͨ͠σΟϨΫτϦ μ΢ϩʔυ͖ͯͨ͠όΠφϦΛ͓͘ 
  4. ~go ├── bin ├── gobin │ ├── go1.8.3 │ │

    └── go │ └── go1.8.3.darwin-amd64.tar.gz ├── pkg │ └── darwin_amd64 │ ├── github.com │ └── golang.org └── src ├── github.com │ ├── cm-nishida-masayuki │ ├── codegangsta │ ├── daviddengcn │ ├── hiroshi-manabe │ ├── jteeuwen │ ├── mitchellh │ └── motemen └── golang.org ࣗ෼ͷϓϩδΣΫτ΋ (01"5)TSDͷԼʹஔ͘ 
  5. HMJEF w HMJEFZBNM w CVOEMFSͰ͍͏(FNpMF w ඞཁͳύοέʔδ͕ॻ͔Ε͍ͯΔ w HMJEFMPDL w

    CVOEMFSͰ͍͏(FNpMFMPDL w ඞཁͳύοέʔδͷ͞Βʹґଘ͍ͯ͠Δύοέʔδ΍ɺ
 Πϯετʔϧͨ͠ίϛοτϋογϡͳͲ͕ॻ͔Ε͍ͯΔ 
  6. type Client struct { *sftp.Client SshConn ssh.Conn } func (c

    *Client) Close() { c.Client.Close() c.SshConn.Close() } ߏ଄ମͷຒΊࠐΈͰͰ͖·͢ 
  7. ྫ͑͹+BWBͰ͔͘ͳΒ͜͏͍͏ॲཧ  public class Main { public static void main(String[]

    args) { Super instance = new Concrete(); instance.execute(); } } public abstract class Super { public void execute() { pre(); doProcess(); after(); } protected abstract void doProcess(); private void pre() { System.out.println("pre"); } private void after() { System.out.println("after"); } } public class Concrete extends Super { @Override protected void doProcess() { System.out.println("process"); } }
  8. package main import "fmt" func Around(f func()) { fmt.Println("pre") f()

    fmt.Println("after") } func main() { Around(func() { fmt.Println("process") }) } ؔ਺͕ϑΝʔετΦϒδΣΫτͳͷͰҾ਺Ͱड͚औΔ͜ͱͰ ࣮ݱͰ͖·͢ *OUFSGBDFΛ࢖ͬͯ΋Ͱ͖·͢ 
  9. ├── awsutils ├── config ├── data ├── handler ├── logger

    ├── main.go ├── model ├── redisutils ├── utils ├── vendor └── version 
  10. func main() { err := func1() if err != nil

    { panic(err) } } func func1() error { if err := func2(); err != nil { return err } return errors.New("crush in func1") } func func2() error { return errors.New("crush in func2") } ωοτϫʔΫӽ͠ʹ˓˓ %#ɺ֎෦"1*౳ Έ͍ͨͳॲཧ͕ ଟ͍ͱͲ͏ͯ͠΋Τϥʔ͕ଟ͘ͳΔͷͰ൥ࡶͳॲཧʹͳΓ·͢  Ͳ͏ͯ͠΋ࣅͨॲཧΛ ෳ਺ॻ͘ඞཁ͕͋Δ
  11. // Fatal is equivalent to Print() followed by a call

    to os.Exit(1). func Fatal(v ...interface{}) { std.Output(2, fmt.Sprint(v...)) os.Exit(1) } ඪ४ͷMPHύοέʔδͷ'BUBMؔ਺͸ தͰPT&YJU  ΛಡΜͰΔͷͰऴྃ͠·͢ 
  12. func TestFunc(t *testing.T) { if Func1() == "" { t.Error("abc")

    } } ඪ४ͷUFTUJOHϞδϡʔϧͷ୯७ͳػೳͱ BTTFSUJPOͱͯ͠UFTUJGZΛ͔ͭͬͯ͘Β͍Ͱ͕͢ ࠓͷͱ͜ΖͳΜͱ͔ͳͬͯ·͢  &SSPSʹԿ͔Λ ॻ͖ࠐΊ͹ςετ͕ࣦഊ͢Δ
  13.  package mock var f1 = func() string { return

    "not mocking" } func Func1() string { return f1() } package mock import ( "fmt" "testing" ) func TestFunc1(t *testing.T) { fmt.Println(Func1()) } func TestFunc1WithMock(t *testing.T) { f1 = func() string { return "mocking" } fmt.Println(Func1()) } NPDL͍ͨؔ͠਺Λ ม਺ʹ͓ͯ͘͠ NPDL͍ͨؔ͠਺Λ ม਺ʹ͓ͯ͘͠ not mocking mocking
  14. HPCJOEBUB  var _configYaml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff go-bindata data/ cBytes, err

    := Asset("config.yaml") HPCJOEBUBίϚϯυΛ࣮ߦ͢Δͱ ϑΝΠϧͷόΠτ഑ྻ͕ຒΊࠐ·ΕͨCJOEBUBHP͕Ͱ͖ "TTFSUؔ਺ʹϑΝΠϧ໊Λ౉͢ͱऔΓग़ͤΔ
  15.  σϓϩΠϑϩʔ &$3 &$4 %PDLFS git push origin v0.0.0 λάΛ1VTI

    docker build go test .
 GOOS=linux GOARCH=amd64 go build docker push ίϯςφ্ͰHPΛϏϧυͯ͠ςετ 0,ͳΒ&$3ʹ1VTI $MPVE'PSNBUJPO UBTLEFpOJUJPOT࡞੒ ίϯςφͷೖΕସ͑
  16.  FROM alpine RUN apk add --no-cache ca-certificates RUN mkdir

    /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 COPY ./app /app ENTRYPOINT ["/app"] ϦϦʔε༻ͷ%PDLFSpMF ࣮ߦϑΝΠϧΛΠϝʔδʹؚΊ ΤϯτϦϙΠϯτʹࢦఆ͢Δ͚ͩ ΠϝʔδͷαΠζ͸.΄Ͳ
 ಉϓϩδΣΫτͷ3BJMTͩͱ.