Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

コードジェネレートとの付き合い方 @Go Conference 2018 Spring

5,567 views

Published on

コードジェネレートとの付き合い方を実例を交えて紹介します。

Published in: Technology
  • Hello! Get Your Professional Job-Winning Resume Here - Check our website! https://vk.cc/818RFv
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

コードジェネレートとの付き合い方 @Go Conference 2018 Spring

  1. 1. Go Conference 2018 Spring @pei0804
  2. 2. • twitter/github @pei0804 • Hatena tikasan • VOYAGE GROUP
 2018 • OSS
 swaggo: GoDoc Swagger
  3. 3. • • •
  4. 4.
  5. 5.
  6. 6. database/sql Scan
  7. 7. github.com/variadico/scaneo
  8. 8. $ scaneo hoge.go
 scans.go
  9. 9. Scan 

  10. 10. github.com/variadico/scaneo
  11. 11. • 
 func ScanCategory
 func ScanCategories • 
 func ScanCategory
 func ScanCategorys
  12. 12. 
 Category 
 Categorys
  13. 13.
  14. 14. tmpl.go 
 PR
  15. 15. OSS
  16. 16. 
 Fork
  17. 17. Fork 
 &&
 

  18. 18. OSS 

  19. 19.
  20. 20. github.com/swaggo/swag
  21. 21. github.com/swaggo/swag Go 
 Swagger Swagger API 
 ※Go
  22. 22. Getting started
  23. 23. $ go get -u github.com/swaggo/swag/cmd/swag
  24. 24. API
  25. 25. $ swag init
  26. 26. docs/swagger/swagger.json
  27. 27. Swagger UI 
 swaggo Middleware
  28. 28. http://localhost:8080/swagger/index.html
  29. 29. 
 

  30. 30. • • • API • • Swagger spec
  31. 31. • • • API • • Swagger spec
  32. 32. 
 ※ • @title • @version • @basepath URI • @host •
  33. 33. parser.go
  34. 34. parser.go
  35. 35. AST go/parser • : abstract syntax tree AST 
 wikipedia
  36. 36. • Go AST Hello, World #golang
 https://qiita.com/tenntenn/items/ 0cbc6f1f00dc579fcd8c • Go Go
 https://motemen.github.io/go-for-go-book/
  37. 37. ParseFile • Go • 
 fset *token.FileSet, filename string, src interface{}, mode Mode • 
 *ast.File, error
  38. 38. ast.File
  39. 39. ast.File
  40. 40. parser.go
  41. 41. • • • API • • Swagger spec
  42. 42. API ( )
 ※ • @param • @success • @failure • @router • @accept, @produce MimeType
  43. 43. parser.go
  44. 44. parser.go
  45. 45. parser.go
  46. 46. parser.go
  47. 47. parser.go
  48. 48. parser.go
  49. 49. parser.go
  50. 50. OK

  51. 51. 
 // @Success 200 {array} model.Account "User"
 @Success {param } 

  52. 52. α 
 

  53. 53.
  54. 54. 
 // @Param default query string false "string default" default(A) Swagger
  55. 55. 
 // @Param default query string false "string default" Enums(A, B ,C) default(A) 
 

  56. 56. 🤔
  57. 57. // @Param default query string false "string default" Enums(A, B ,C) default(A) // @Param default query string false "string default" Enums(A, B ,C) default(A)
  58. 58. 
 
 😇
  59. 59. Model
  60. 60. @Param account body model.Account ~~ model Account 
 
 Model
  61. 61. AST TypeDefinitions map[string]map[string]*ast.TypeSpec
 map[ ][ ] AST model 
 
 
 TypeDefinitions["model"]["Account"] model Account AST 

  62. 62. • • •
  63. 63. • • •
  64. 64. parser.go
  65. 65. parser.go
  66. 66. parser.go
  67. 67. parser.go
  68. 68. parser.go
  69. 69. • • •
  70. 70. parser.go
  71. 71. parser.go
  72. 72. 
 

  73. 73. 
 
 😇
  74. 74. User Family User Family User Family User Family User panic
  75. 75. • • •
  76. 76. 🤔
  77. 77. • 
 
 • •
  78. 78. parser.go
  79. 79. parser.go
  80. 80. User Family User Family User Family User Family User panic
  81. 81. User Family User Family User Family User Family User panic
  82. 82. 😂
  83. 83. • • • API • • Swagger spec
  84. 84. github.com/go-openapi/spec
  85. 85. github.com/go-openapi/spec Swagger2.0 spec 
 go-swagger/go-swagger 
 Swagger
  86. 86. 3.0 
 github.com/go-openapi/spec3
  87. 87. 
 Swagger 

  88. 88.
  89. 89. • 
 • 

  90. 90.
  91. 91.
  92. 92. 
 
 
 OSS swaggo welcome
  93. 93. • github.com/mercari/go-httpdoc
 • github.com/goadesign/goa
 DSL Swagger • github.com/cheekybits/genny
 Go
  94. 94. • Go 
 https://www.slideshare.net/lestrrat/go-86436442 • go generate go/ast 
 https://speakerdeck.com/masashisalvador57f/ast-falsezatukuritositahua • go generate 
 http://agtn.hatenablog.com/entry/2017/08/06/015813

×