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

Go Package Guidelines

Go Package Guidelines

Shintaro Kaneko

August 10, 2017
Tweet

More Decks by Shintaro Kaneko

Other Decks in Programming

Transcript

  1. Copyright © 2017 eureka, Inc. All rights reserved.
    Go Package Guidelines
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy
    Shintaro Kaneko

    View Slide

  2. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    ۚࢠ৻ଠ࿠(kaneshin)
    w CTO at Eureka, Inc.
    w ࣄۀʷςΫϊϩδʔͷઓཱུҊɾ࣮ߦ
    w ΤϯδχΞ૊৫શମͷϚωδϝϯτ
    About me
    Τ΢ϨΧࣥߦ໾һCTOब೚
    2016/10
    2012/10
    2013/10 Τ΢ϨΧϚωʔδϟʔब೚
    ૊ࠐܥاۀ΁ೖࣾ
    Τ΢ϨΧ΁ೖࣾ
    ΧφμͷόϯΫʔόʔ΁ཹֶ
    2010/04
    2011/12

    View Slide

  3. 3 Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    Package Guidelines

    View Slide

  4. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    2(Pͷύοέʔδߏ੒ʹ
    ೰Μͩ͜ͱ͕͋Δํ

    View Slide

  5. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    "೰Ή

    View Slide

  6. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    ׳ΕΔͱγϯϓϧͷԸܙ
    ͨͩ͠ɺݴޠԽ͕গ͠೉͍͠

    View Slide

  7. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    গͣͭ͠஌ݟΛஷΊ͍ͯ͜͏

    View Slide

  8. Package names
    8 Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    View Slide

  9. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    Package names
    1
    2 খจࣈͷΈͰɺεωʔΫέʔεɾΩϟϝϧέʔεΛ༻͍ͳ͍
    3 ෳ਺ܗʹ͠ͳ͍
    4 Don't steal good names from the user.
    ؆ܿͳ୯ޠ΍লུΛ͠ɺ໨త͕໌֬ͳ໊শʹ͢Δ

    View Slide

  10. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    Package names
    ⭕ import "io" // I/O
    ⭕ import "net/http/httputil" // HTTP utility functions
    ⭕ import "strconv" // Abbreviation (string conversion)
    ❌ import "util" // Conventional name
    ❌ import "my_http_util" // Camel case
    ❌ import "myHttpUtil" // Snake case
    ❌ import "models" // Plural
    ❌ import "buf" // `buf` is a good variable name for a buffer.

    View Slide

  11. Package structure
    11 Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    View Slide

  12. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    Package structure
    foo/
    |_ bar/
    | |_ qux/
    | | |_ qux.go
    | |_ bar.go
    |_ foo.go

    View Slide

  13. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    Package structure
    foo/
    |_ bar/
    | |_ qux/
    | | |_ qux.go
    | |_ bar.go
    |_ foo.go

    View Slide

  14. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    Package structure
    foo/
    |_ bar/ // 抽象
    | |_ qux/ // 具象
    | | |_ qux.go
    | |_ bar.go
    |_ foo.go

    View Slide

  15. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    Package structure
    foo/
    |_ bar/ // 抽象
    | |_ qux/ // 具象
    | | |_ qux.go
    | |_ bar.go
    |_ foo.go io/...
    crypto/...
    encoding/...

    View Slide

  16. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    Package names
    1
    2 ۩৅ϨΠϠͰ͸ந৅ϨΠϠͷinterfaceΛຬ͍ͨͯ͘͠
    3 ۩৅ϨΠϠ͸୯७ʹ্ҐϨΠϠͷutilͰ͋Δ͜ͱ΋͋Δ
    4 ݁ߏଟ͘ɺࣦഊ͠ʹ͍͘
    ந৅ϨΠϠͰ͸interfaceΛఆٛ͠ɺۃྗύοέʔδΛബ͘͢Δ

    View Slide

  17. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    Package structure
    foo/
    |_ bar/
    | |_ qux/
    | | |_ qux.go
    | |_ bar.go
    |_ foo.go

    View Slide

  18. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    Package structure
    foo/
    |_ bar/ // 具象
    | |_ qux/ // 具象
    | | |_ qux.go
    | |_ bar.go
    |_ foo.go

    View Slide

  19. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    Package structure
    foo/
    |_ bar/ // 具象
    | |_ qux/ // 具象
    | | |_ qux.go
    | |_ bar.go
    |_ foo.go net/...

    View Slide

  20. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    Package names
    1
    2 ্Ґͷ۩৅ϨΠϠͰ͸γϯϓϧͳػೳ͔͠ఏڙ͠ͳ͍
    3 ୯७ʹ্ҐϨΠϠͷutil΋͋Δʢutilͱ͍͏໊લ͸ආ͚Δʣ
    4 ύοέʔδͷࡉ෼Խͱ૚Λؾʹ͢Δ͜ͱʢ΍Γա͗͸μϝʣ
    ࠷্Ґʹந৅ϨΠϠ͕ఆٛ͞Ε͍ͯΔ͜ͱ͕ྑ͋͘Δ

    View Slide

  21. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    Package structure
    foo/
    |_ bar/
    | |_ qux/
    | | |_ qux.go
    | |_ bar.go
    |_ foo.go

    View Slide

  22. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    Package structure
    foo/
    |_ bar/ // 具象
    | |_ qux/ // 抽象
    | | |_ qux.go
    | |_ bar.go
    |_ foo.go

    View Slide

  23. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    Package structure
    foo/
    |_ bar/ // 具象
    | |_ qux/ // 抽象
    | | |_ qux.go
    | |_ bar.go
    |_ foo.go database/sql/...

    View Slide

  24. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    Package names
    1
    2 ۩৅ϨΠϠͰ͸ந৅ϨΠϠͷinterfaceΛຬ͍ͨͯ͘͠
    3 ۩৅ϨΠϠΛΧελϚΠζՄೳʹ͢Δ
    4 ͜ͷઃܭ͸೉͍͠
    ந৅ϨΠϠͰ͸interfaceΛఆٛ͢Δ

    View Slide

  25. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    Ͳ͏͍͏ߟ͑Ͱॻ͍͍ͯΔͷ͔
    ݟͯ΋Βͬͨ΄͏͕ૣ͍

    View Slide

  26. Others
    26 Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    View Slide

  27. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    Others
    1
    2 internal package
    3 cmd package
    Sub Repositories: golang.org/x

    View Slide

  28. Copyright © 2017 eureka, Inc. All rights reserved.
    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy

    ͱʹ͔͘ɺ໺ྑͰͳ͘
    ඪ४ύοέʔδΛࢀߟʹ

    View Slide

  29. Making a great impact on people’s life.

    View Slide