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
  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
  3. 3 Copyright © 2017 eureka, Inc. All rights reserved. $0/'*%&/5*"-

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

    for Public Distribution - Do Not Copy   2(Pͷύοέʔδߏ੒ʹ ೰Μͩ͜ͱ͕͋Δํ
  5. Copyright © 2017 eureka, Inc. All rights reserved. $0/'*%&/5*"- Not

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

    for Public Distribution - Do Not Copy   ׳ΕΔͱγϯϓϧͷԸܙ ͨͩ͠ɺݴޠԽ͕গ͠೉͍͠
  7. Copyright © 2017 eureka, Inc. All rights reserved. $0/'*%&/5*"- Not

    for Public Distribution - Do Not Copy   গͣͭ͠஌ݟΛஷΊ͍ͯ͜͏
  8. Package names 8 Copyright © 2017 eureka, Inc. All rights

    reserved. $0/'*%&/5*"- Not for Public Distribution - Do Not Copy  
  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. ؆ܿͳ୯ޠ΍লུΛ͠ɺ໨త͕໌֬ͳ໊শʹ͢Δ
  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.
  11. Package structure 11 Copyright © 2017 eureka, Inc. All rights

    reserved. $0/'*%&/5*"- Not for Public Distribution - Do Not Copy  
  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
  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
  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
  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/...
  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Λఆٛ͠ɺۃྗύοέʔδΛബ͘͢Δ
  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
  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
  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/...
  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 ύοέʔδͷࡉ෼Խͱ૚Λؾʹ͢Δ͜ͱʢ΍Γա͗͸μϝʣ ࠷্Ґʹந৅ϨΠϠ͕ఆٛ͞Ε͍ͯΔ͜ͱ͕ྑ͋͘Δ
  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
  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
  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/...
  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Λఆٛ͢Δ
  25. Copyright © 2017 eureka, Inc. All rights reserved. $0/'*%&/5*"- Not

    for Public Distribution - Do Not Copy   Ͳ͏͍͏ߟ͑Ͱॻ͍͍ͯΔͷ͔ ݟͯ΋Βͬͨ΄͏͕ૣ͍
  26. Others 26 Copyright © 2017 eureka, Inc. All rights reserved.

    $0/'*%&/5*"- Not for Public Distribution - Do Not Copy  
  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
  28. Copyright © 2017 eureka, Inc. All rights reserved. $0/'*%&/5*"- Not

    for Public Distribution - Do Not Copy   ͱʹ͔͘ɺ໺ྑͰͳ͘ ඪ४ύοέʔδΛࢀߟʹ