From ad2f9720fb9294022fc4624803bd60b198ef75cd Mon Sep 17 00:00:00 2001 From: Hieu Nguyen Date: Wed, 15 Aug 2018 13:42:48 +0700 Subject: [PATCH] Change project layout, add api, add doc (#2) Update template layout, swagger api + doc --- sao.js | 8 +-- template/api/swagger.yaml | 55 +++++++++++++++++++ template/cmd/server/main.go | 12 ++-- template/doc/.gitkeep | 0 template/{ => src}/endpoints/add.go | 4 +- template/{ => src}/endpoints/endpoints.go | 2 +- template/{ => src}/http/encode.go | 0 template/{ => src}/http/http.go | 4 +- template/{ => src}/middlewares/compose.go | 0 template/{ => src}/postgres/postgres.go | 0 template/{ => src}/service/add/add.go | 0 template/{ => src}/service/add/error.go | 0 template/{ => src}/service/add/mw_logging.go | 0 .../{ => src}/service/add/mw_validation.go | 0 template/{ => src}/service/add/pg.go | 0 template/{ => src}/service/add/service.go | 0 template/{ => src}/service/service.go | 2 +- 17 files changed, 71 insertions(+), 16 deletions(-) create mode 100644 template/api/swagger.yaml create mode 100644 template/doc/.gitkeep rename template/{ => src}/endpoints/add.go (84%) rename template/{ => src}/endpoints/endpoints.go (85%) rename template/{ => src}/http/encode.go (100%) rename template/{ => src}/http/http.go (92%) rename template/{ => src}/middlewares/compose.go (100%) rename template/{ => src}/postgres/postgres.go (100%) rename template/{ => src}/service/add/add.go (100%) rename template/{ => src}/service/add/error.go (100%) rename template/{ => src}/service/add/mw_logging.go (100%) rename template/{ => src}/service/add/mw_validation.go (100%) rename template/{ => src}/service/add/pg.go (100%) rename template/{ => src}/service/add/service.go (100%) rename template/{ => src}/service/service.go (58%) diff --git a/sao.js b/sao.js index ae3a20b..5982578 100644 --- a/sao.js +++ b/sao.js @@ -9,14 +9,14 @@ module.exports = { gitInit: false, installDependencies: false, prompts: { - namespace: { - message: 'What is your vsc namespace?', - default: 'dwarvesf', - }, domain: { message: 'What is your vsc domain?', default: 'github.com', }, + namespace: { + message: 'What is your vsc namespace?', + default: ':gitUser:', + }, description: { message: 'How would you describe the new project?', default: `my ${superb()} Go project`, diff --git a/template/api/swagger.yaml b/template/api/swagger.yaml new file mode 100644 index 0000000..67bba34 --- /dev/null +++ b/template/api/swagger.yaml @@ -0,0 +1,55 @@ +swagger: "2.0" +info: + description: "<%= description %>" + version: "1.0.0" + title: "<%= _.folderName %> API Document" +host: "localhost:3000" +basePath: "/" +tags: +- name: "add" + description: "add service" +schemes: +- "http" +paths: + /add: + post: + tags: + - "add" + summary: "Add 2 value" + description: "add 2 value and return response" + operationId: "add" + consumes: + - "application/json" + produces: + - "application/json" + parameters: + - in: "body" + name: "body" + description: "add 2 value and return response" + required: true + schema: + $ref: "#/definitions/add_post_req" + responses: + 200: + description: "successful operation" + schema: + $ref: "#/definitions/add_post_res" + +definitions: + add_post_req: + type: "object" + properties: + add: + type: "object" + properties: + x: + type: "integer" + format: "int32" + y: + type: "integer" + format: "int32" + add_post_res: + properties: + result: + type: "integer" + format: "int32" diff --git a/template/cmd/server/main.go b/template/cmd/server/main.go index 7fb26ba..300592a 100644 --- a/template/cmd/server/main.go +++ b/template/cmd/server/main.go @@ -10,12 +10,12 @@ import ( "github.com/go-kit/kit/log" - "<%= domainDir + _.folderName %>/endpoints" - serviceHttp "<%= domainDir + _.folderName %>/http" - "<%= domainDir + _.folderName %>/middlewares" - "<%= domainDir + _.folderName %>/postgres" - "<%= domainDir + _.folderName %>/service" - "<%= domainDir + _.folderName %>/service/add" + "<%= domainDir + _.folderName %>/src/endpoints" + serviceHttp "<%= domainDir + _.folderName %>/src/http" + "<%= domainDir + _.folderName %>/src/middlewares" + "<%= domainDir + _.folderName %>/src/postgres" + "<%= domainDir + _.folderName %>/src/service" + "<%= domainDir + _.folderName %>/src/service/add" ) func main() { diff --git a/template/doc/.gitkeep b/template/doc/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/template/endpoints/add.go b/template/src/endpoints/add.go similarity index 84% rename from template/endpoints/add.go rename to template/src/endpoints/add.go index abc2ea2..45c1847 100644 --- a/template/endpoints/add.go +++ b/template/src/endpoints/add.go @@ -5,8 +5,8 @@ import ( "github.com/go-kit/kit/endpoint" - "<%= domainDir + _.folderName %>/service" - "<%= domainDir + _.folderName %>/service/add" + "<%= domainDir + _.folderName %>/src/service" + "<%= domainDir + _.folderName %>/src/service/add" ) type AddRequest struct { diff --git a/template/endpoints/endpoints.go b/template/src/endpoints/endpoints.go similarity index 85% rename from template/endpoints/endpoints.go rename to template/src/endpoints/endpoints.go index ea56a79..64017a9 100644 --- a/template/endpoints/endpoints.go +++ b/template/src/endpoints/endpoints.go @@ -3,7 +3,7 @@ package endpoints import ( "github.com/go-kit/kit/endpoint" - "<%= domainDir + _.folderName %>/service" + "<%= domainDir + _.folderName %>/src/service" ) type Endpoints struct { diff --git a/template/http/encode.go b/template/src/http/encode.go similarity index 100% rename from template/http/encode.go rename to template/src/http/encode.go diff --git a/template/http/http.go b/template/src/http/http.go similarity index 92% rename from template/http/http.go rename to template/src/http/http.go index 29420d5..8495a08 100644 --- a/template/http/http.go +++ b/template/src/http/http.go @@ -10,8 +10,8 @@ import ( "github.com/go-kit/kit/log" httptransport "github.com/go-kit/kit/transport/http" - "<%= domainDir + _.folderName %>/endpoints" - "<%= domainDir + _.folderName %>/service" + "<%= domainDir + _.folderName %>/src/endpoints" + "<%= domainDir + _.folderName %>/src/service" ) // NewHTTPHandler ... diff --git a/template/middlewares/compose.go b/template/src/middlewares/compose.go similarity index 100% rename from template/middlewares/compose.go rename to template/src/middlewares/compose.go diff --git a/template/postgres/postgres.go b/template/src/postgres/postgres.go similarity index 100% rename from template/postgres/postgres.go rename to template/src/postgres/postgres.go diff --git a/template/service/add/add.go b/template/src/service/add/add.go similarity index 100% rename from template/service/add/add.go rename to template/src/service/add/add.go diff --git a/template/service/add/error.go b/template/src/service/add/error.go similarity index 100% rename from template/service/add/error.go rename to template/src/service/add/error.go diff --git a/template/service/add/mw_logging.go b/template/src/service/add/mw_logging.go similarity index 100% rename from template/service/add/mw_logging.go rename to template/src/service/add/mw_logging.go diff --git a/template/service/add/mw_validation.go b/template/src/service/add/mw_validation.go similarity index 100% rename from template/service/add/mw_validation.go rename to template/src/service/add/mw_validation.go diff --git a/template/service/add/pg.go b/template/src/service/add/pg.go similarity index 100% rename from template/service/add/pg.go rename to template/src/service/add/pg.go diff --git a/template/service/add/service.go b/template/src/service/add/service.go similarity index 100% rename from template/service/add/service.go rename to template/src/service/add/service.go diff --git a/template/service/service.go b/template/src/service/service.go similarity index 58% rename from template/service/service.go rename to template/src/service/service.go index fad3e9d..40d777a 100644 --- a/template/service/service.go +++ b/template/src/service/service.go @@ -1,6 +1,6 @@ package service -import "<%= domainDir + _.folderName %>/service/add" +import "<%= domainDir + _.folderName %>/src/service/add" // Service ... type Service struct {