diff --git a/Gopkg.lock b/Gopkg.lock index 8574802b..6009bff5 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -85,7 +85,7 @@ version = "v1.0.0" [[projects]] - digest = "1:6a06217fc753e65aea71446b777393009ef6797dadc0086c4f75bd16590be04d" + digest = "1:ee73ed01fc93b8aa38a7f25543afed400df661992eeb7d3b250100b8b8f989b9" name = "github.com/grpc-ecosystem/grpc-gateway" packages = [ "runtime", @@ -93,8 +93,8 @@ "utilities", ] pruneopts = "UT" - revision = "92583770e3f01b09a0d3e9bdf64321d8bebd48f2" - version = "v1.4.1" + revision = "8558711daa6c2853489043207b563dceacbc19cf" + version = "v1.5.0" [[projects]] branch = "master" @@ -134,6 +134,18 @@ revision = "fdfd45e15564e04a472c90a37fb1a5d8035fe050" version = "v0.1.0" +[[projects]] + digest = "1:90d34344be1899b2c4f614a5bb59ed829346f3f00d8a2009c254b1d060578240" + name = "github.com/izumin5210/gex" + packages = [ + "cmd/gex", + "pkg/command", + "pkg/tool", + ] + pruneopts = "UT" + revision = "c4c75fc151408fb0f769b01a333c904774eb65d7" + version = "v0.2.0" + [[projects]] branch = "master" digest = "1:446f04b6b59c2cfacf8e9784c431afda6708d72a7a09eaefb2ab96d2b9cf8536" @@ -482,6 +494,7 @@ "github.com/grpc-ecosystem/grpc-gateway/utilities", "github.com/izumin5210/clicontrib/pkg/ccmd", "github.com/izumin5210/clicontrib/pkg/clog", + "github.com/izumin5210/gex/cmd/gex", "github.com/jessevdk/go-assets", "github.com/jessevdk/go-assets-builder", "github.com/jinzhu/inflection", diff --git a/Gopkg.toml b/Gopkg.toml index d82d21a7..c7392856 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -40,7 +40,7 @@ required = [ [[constraint]] name = "github.com/grpc-ecosystem/grpc-gateway" - version = "^1.4.1" + version = "^1.5.0" [[constraint]] name = "github.com/pkg/errors" diff --git a/go.mod b/go.mod index 959ea553..ae9ef2f0 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/golang/protobuf v1.2.0 github.com/google/go-cmp v0.2.0 github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 - github.com/grpc-ecosystem/grpc-gateway v1.4.1 + github.com/grpc-ecosystem/grpc-gateway v1.5.0 github.com/hashicorp/hcl v0.0.0-20171017181929-23c074d0eceb // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/izumin5210/clicontrib v0.1.0 diff --git a/go.sum b/go.sum index 0ca6d2c2..b8e493c1 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:BWIsLfhgKhV5g/oF34aRjniBHLTZe5DNekSjbAjIS6c= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= -github.com/grpc-ecosystem/grpc-gateway v1.4.1 h1:pX7cnDwSSmG0dR9yNjCQSSpmsJOqFdT7SzVp5Yl9uVw= -github.com/grpc-ecosystem/grpc-gateway v1.4.1/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= +github.com/grpc-ecosystem/grpc-gateway v1.5.0 h1:WcmKMm43DR7RdtlkEXQJyo5ws8iTp98CyhCCbOHMvNI= +github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= github.com/hashicorp/hcl v0.0.0-20171017181929-23c074d0eceb h1:1OvvPvZkn/yCQ3xBcM8y4020wdkMXPHLB4+NfoGWh4U= github.com/hashicorp/hcl v0.0.0-20171017181929-23c074d0eceb/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= diff --git a/pkg/grapicmd/internal/module/generator.go b/pkg/grapicmd/internal/module/generator.go index 5fe2eedb..07283e3f 100644 --- a/pkg/grapicmd/internal/module/generator.go +++ b/pkg/grapicmd/internal/module/generator.go @@ -9,7 +9,12 @@ type Generator interface { // ProjectGenerator is an interface to build a new project. type ProjectGenerator interface { - GenerateProject(rootDir, pkgName string, useHead bool) error + GenerateProject(rootDir, pkgName string, cfg ProjectGenerationConfig) error +} + +// ProjectGenerationConfig contains configurations for generating a new project. +type ProjectGenerationConfig struct { + UseHEAD bool } // ServiceGenerator is an interface to create or destroy gRPC services and implementations. diff --git a/pkg/grapicmd/internal/module/generator/.snapshots/Test_ProjectGenerator-.gitignore b/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-no_config-.gitignore similarity index 100% rename from pkg/grapicmd/internal/module/generator/.snapshots/Test_ProjectGenerator-.gitignore rename to pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-no_config-.gitignore diff --git a/pkg/grapicmd/internal/module/generator/.snapshots/Test_ProjectGenerator-Gopkg.toml b/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-no_config-Gopkg.toml similarity index 50% rename from pkg/grapicmd/internal/module/generator/.snapshots/Test_ProjectGenerator-Gopkg.toml rename to pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-no_config-Gopkg.toml index 63d4115d..e8c7a3a1 100644 --- a/pkg/grapicmd/internal/module/generator/.snapshots/Test_ProjectGenerator-Gopkg.toml +++ b/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-no_config-Gopkg.toml @@ -6,16 +6,9 @@ required = [ [[constraint]] name = "github.com/izumin5210/grapi" - version = "" + version = "v1.0.0" [[override]] name = "github.com/grpc-ecosystem/grpc-gateway" - # To use `paths` option in `protoc-gen-grpc-gateway` - # See https://github.com/grpc-ecosystem/grpc-gateway/pull/711 - revision = "42fa2028fd3ba4a546dd525d9db71573f1992ba1" - -[[override]] - name = "google.golang.org/grpc" - # To ignore grpc-gateway@42fa2028's constraints - version = "^1.11.3" + version = "^1.5.0" diff --git a/pkg/grapicmd/internal/module/generator/.snapshots/Test_ProjectGenerator-app-run.go b/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-no_config-app-run.go similarity index 100% rename from pkg/grapicmd/internal/module/generator/.snapshots/Test_ProjectGenerator-app-run.go rename to pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-no_config-app-run.go diff --git a/pkg/grapicmd/internal/module/generator/.snapshots/Test_ProjectGenerator-cmd-server-run.go b/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-no_config-cmd-server-run.go similarity index 100% rename from pkg/grapicmd/internal/module/generator/.snapshots/Test_ProjectGenerator-cmd-server-run.go rename to pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-no_config-cmd-server-run.go diff --git a/pkg/grapicmd/internal/module/generator/.snapshots/Test_ProjectGenerator-grapi.toml b/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-no_config-grapi.toml similarity index 100% rename from pkg/grapicmd/internal/module/generator/.snapshots/Test_ProjectGenerator-grapi.toml rename to pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-no_config-grapi.toml diff --git a/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-with_UseHEAD-.gitignore b/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-with_UseHEAD-.gitignore new file mode 100644 index 00000000..9746e024 --- /dev/null +++ b/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-with_UseHEAD-.gitignore @@ -0,0 +1,5 @@ +*.so +/vendor +/bin +/tmp + diff --git a/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-with_UseHEAD-Gopkg.toml b/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-with_UseHEAD-Gopkg.toml new file mode 100644 index 00000000..13af18f5 --- /dev/null +++ b/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-with_UseHEAD-Gopkg.toml @@ -0,0 +1,14 @@ +required = [ + "github.com/golang/protobuf/protoc-gen-go", + "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway", + "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger", +] + +[[constraint]] + branch = "master" + name = "github.com/izumin5210/grapi" + +[[override]] + name = "github.com/grpc-ecosystem/grpc-gateway" + version = "^1.5.0" + diff --git a/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-with_UseHEAD-app-run.go b/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-with_UseHEAD-app-run.go new file mode 100644 index 00000000..13226b76 --- /dev/null +++ b/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-with_UseHEAD-app-run.go @@ -0,0 +1,17 @@ +package app + +import ( + "github.com/izumin5210/grapi/pkg/grapiserver" +) + +// Run starts the grapiserver. +func Run() error { + s := grapiserver.New( + grapiserver.WithDefaultLogger(), + grapiserver.WithServers( + // TODO + ), + ) + return s.Serve() +} + diff --git a/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-with_UseHEAD-cmd-server-run.go b/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-with_UseHEAD-cmd-server-run.go new file mode 100644 index 00000000..c659dd72 --- /dev/null +++ b/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-with_UseHEAD-cmd-server-run.go @@ -0,0 +1,23 @@ +package main + +import ( + "os" + + "google.golang.org/grpc/grpclog" + + "testcompany/testapp/app" +) + +func main() { + os.Exit(run()) +} + +func run() int { + err := app.Run() + if err != nil { + grpclog.Errorf("server was shutdown with errors: %v", err) + return 1 + } + return 0 +} + diff --git a/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-with_UseHEAD-grapi.toml b/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-with_UseHEAD-grapi.toml new file mode 100644 index 00000000..6fb7a1b5 --- /dev/null +++ b/pkg/grapicmd/internal/module/generator/.snapshots/TestProjectGenerator_GenerateProject-with_UseHEAD-grapi.toml @@ -0,0 +1,29 @@ +package = "testcompany.testapp" + +[grapi] +server_dir = "./app/server" + +[protoc] +protos_dir = "./api/protos" +out_dir = "./api" +import_dirs = [ + "./api/protos", + "./vendor/github.com/grpc-ecosystem/grpc-gateway", + "./vendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis", +] + + [[protoc.plugins]] + path = "./vendor/github.com/golang/protobuf/protoc-gen-go" + name = "go" + args = { plugins = "grpc", paths = "source_relative" } + + [[protoc.plugins]] + path = "./vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway" + name = "grpc-gateway" + args = { logtostderr = true, paths = "source_relative" } + + [[protoc.plugins]] + path = "./vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger" + name = "swagger" + args = { logtostderr = true } + diff --git a/pkg/grapicmd/internal/module/generator/project.go b/pkg/grapicmd/internal/module/generator/project.go index a30829ed..9147a1fc 100644 --- a/pkg/grapicmd/internal/module/generator/project.go +++ b/pkg/grapicmd/internal/module/generator/project.go @@ -21,7 +21,7 @@ func newProjectGenerator(fs afero.Fs, ui module.UI, version string) module.Proje } } -func (g *projectGenerator) GenerateProject(rootDir, pkgName string, useHead bool) error { +func (g *projectGenerator) GenerateProject(rootDir, pkgName string, cfg module.ProjectGenerationConfig) error { importPath, err := fs.GetImportPath(rootDir) if err != nil { return errors.WithStack(err) @@ -38,7 +38,7 @@ func (g *projectGenerator) GenerateProject(rootDir, pkgName string, useHead bool "packageName": pkgName, "importPath": importPath, "version": g.version, - "headUsed": useHead, + "headUsed": cfg.UseHEAD, } return g.Generate(rootDir, data, generationConfig{}) } diff --git a/pkg/grapicmd/internal/module/generator/project_test.go b/pkg/grapicmd/internal/module/generator/project_test.go index ef4c2dd6..5088a8d9 100644 --- a/pkg/grapicmd/internal/module/generator/project_test.go +++ b/pkg/grapicmd/internal/module/generator/project_test.go @@ -8,11 +8,12 @@ import ( "github.com/golang/mock/gomock" "github.com/spf13/afero" + "github.com/izumin5210/grapi/pkg/grapicmd/internal/module" moduletesting "github.com/izumin5210/grapi/pkg/grapicmd/internal/module/testing" "github.com/izumin5210/grapi/pkg/grapicmd/util/fs" ) -func Test_ProjectGenerator(t *testing.T) { +func TestProjectGenerator_GenerateProject(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() @@ -23,33 +24,49 @@ func Test_ProjectGenerator(t *testing.T) { ui := moduletesting.NewMockUI(ctrl) ui.EXPECT().ItemSuccess(gomock.Any()).AnyTimes() - fs := afero.NewMemMapFs() - generator := newProjectGenerator(fs, ui, "") - - err := generator.GenerateProject(rootDir, "", false) - - if err != nil { - t.Errorf("returned an error %v", err) + cases := []struct { + test string + cfg module.ProjectGenerationConfig + }{ + { + test: "no config", + }, + { + test: "with UseHEAD", + cfg: module.ProjectGenerationConfig{UseHEAD: true}, + }, } - files := []string{ - ".gitignore", - "Gopkg.toml", - "grapi.toml", - "app/run.go", - "cmd/server/run.go", - } - - for _, file := range files { - t.Run(file, func(t *testing.T) { - data, err := afero.ReadFile(fs, filepath.Join(rootDir, file)) + for _, tc := range cases { + t.Run(tc.test, func(t *testing.T) { + fs := afero.NewMemMapFs() + generator := newProjectGenerator(fs, ui, "v1.0.0") + err := generator.GenerateProject(rootDir, "", tc.cfg) if err != nil { t.Errorf("returned an error %v", err) } - cupaloy.SnapshotT(t, string(data)) + files := []string{ + ".gitignore", + "Gopkg.toml", + "grapi.toml", + "app/run.go", + "cmd/server/run.go", + } + + for _, file := range files { + t.Run(file, func(t *testing.T) { + data, err := afero.ReadFile(fs, filepath.Join(rootDir, file)) + + if err != nil { + t.Errorf("returned an error %v", err) + } + + cupaloy.SnapshotT(t, string(data)) + }) + } }) } } diff --git a/pkg/grapicmd/internal/module/generator/template/init.go b/pkg/grapicmd/internal/module/generator/template/init.go index d7612d0e..2297e836 100644 --- a/pkg/grapicmd/internal/module/generator/template/init.go +++ b/pkg/grapicmd/internal/module/generator/template/init.go @@ -6,41 +6,41 @@ import ( "github.com/jessevdk/go-assets" ) -var _Initbc4053f4dd26ceb67e4646e8c1d2cc75897c4dd0 = "package app\n\nimport (\n\t\"github.com/izumin5210/grapi/pkg/grapiserver\"\n)\n\n// Run starts the grapiserver.\nfunc Run() error {\n\ts := grapiserver.New(\n\t\tgrapiserver.WithDefaultLogger(),\n\t\tgrapiserver.WithServers(\n\t\t// TODO\n\t\t),\n\t)\n\treturn s.Serve()\n}\n" -var _Init23b808cac963edf44a497827f2a6eff5ddac970f = "required = [\n \"github.com/golang/protobuf/protoc-gen-go\",\n \"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway\",\n \"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger\",\n]\n\n[[constraint]]\n{{- if .headUsed }}\n branch = \"master\"\n{{- end }}\n name = \"github.com/izumin5210/grapi\"\n{{- if not .headUsed }}\n version = \"{{ .version }}\"\n{{- end }}\n\n[[override]]\n name = \"github.com/grpc-ecosystem/grpc-gateway\"\n # To use `paths` option in `protoc-gen-grpc-gateway`\n # See https://github.com/grpc-ecosystem/grpc-gateway/pull/711\n revision = \"42fa2028fd3ba4a546dd525d9db71573f1992ba1\"\n\n[[override]]\n name = \"google.golang.org/grpc\"\n # To ignore grpc-gateway@42fa2028's constraints\n version = \"^1.11.3\"\n" -var _Initc051c9ff1a8e446bc9636d3144c2775a7e235322 = "package = \"{{.packageName}}\"\n\n[grapi]\nserver_dir = \"./app/server\"\n\n[protoc]\nprotos_dir = \"./api/protos\"\nout_dir = \"./api\"\nimport_dirs = [\n \"./api/protos\",\n \"./vendor/github.com/grpc-ecosystem/grpc-gateway\",\n \"./vendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis\",\n]\n\n [[protoc.plugins]]\n path = \"./vendor/github.com/golang/protobuf/protoc-gen-go\"\n name = \"go\"\n args = { plugins = \"grpc\", paths = \"source_relative\" }\n\n [[protoc.plugins]]\n path = \"./vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway\"\n name = \"grpc-gateway\"\n args = { logtostderr = true, paths = \"source_relative\" }\n\n [[protoc.plugins]]\n path = \"./vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger\"\n name = \"swagger\"\n args = { logtostderr = true }\n" -var _Initd135936e91856b6159ac2eedcf89aa9f07773f82 = "package main\n\nimport (\n\t\"os\"\n\n\t\"google.golang.org/grpc/grpclog\"\n\n\t\"{{ .importPath }}/app\"\n)\n\nfunc main() {\n\tos.Exit(run())\n}\n\nfunc run() int {\n\terr := app.Run()\n\tif err != nil {\n\t\tgrpclog.Errorf(\"server was shutdown with errors: %v\", err)\n\t\treturn 1\n\t}\n\treturn 0\n}\n" -var _Init8d21956ba8abe388f964e47be0f7e5d170a2fce5 = "" var _Init38e76c5db8962fa825cf2bd8b23a2dc985c4513e = "*.so\n/vendor\n/bin\n/tmp\n" +var _Init8d21956ba8abe388f964e47be0f7e5d170a2fce5 = "" +var _Initd135936e91856b6159ac2eedcf89aa9f07773f82 = "package main\n\nimport (\n\t\"os\"\n\n\t\"google.golang.org/grpc/grpclog\"\n\n\t\"{{ .importPath }}/app\"\n)\n\nfunc main() {\n\tos.Exit(run())\n}\n\nfunc run() int {\n\terr := app.Run()\n\tif err != nil {\n\t\tgrpclog.Errorf(\"server was shutdown with errors: %v\", err)\n\t\treturn 1\n\t}\n\treturn 0\n}\n" +var _Init23b808cac963edf44a497827f2a6eff5ddac970f = "required = [\n \"github.com/golang/protobuf/protoc-gen-go\",\n \"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway\",\n \"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger\",\n]\n\n[[constraint]]\n{{- if .headUsed }}\n branch = \"master\"\n{{- end }}\n name = \"github.com/izumin5210/grapi\"\n{{- if not .headUsed }}\n version = \"{{ .version }}\"\n{{- end }}\n\n[[override]]\n name = \"github.com/grpc-ecosystem/grpc-gateway\"\n version = \"^1.5.0\"\n" +var _Initc051c9ff1a8e446bc9636d3144c2775a7e235322 = "package = \"{{.packageName}}\"\n\n[grapi]\nserver_dir = \"./app/server\"\n\n[protoc]\nprotos_dir = \"./api/protos\"\nout_dir = \"./api\"\nimport_dirs = [\n \"./api/protos\",\n \"./vendor/github.com/grpc-ecosystem/grpc-gateway\",\n \"./vendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis\",\n]\n\n [[protoc.plugins]]\n path = \"./vendor/github.com/golang/protobuf/protoc-gen-go\"\n name = \"go\"\n args = { plugins = \"grpc\", paths = \"source_relative\" }\n\n [[protoc.plugins]]\n path = \"./vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway\"\n name = \"grpc-gateway\"\n args = { logtostderr = true, paths = \"source_relative\" }\n\n [[protoc.plugins]]\n path = \"./vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger\"\n name = \"swagger\"\n args = { logtostderr = true }\n" +var _Initbc4053f4dd26ceb67e4646e8c1d2cc75897c4dd0 = "package app\n\nimport (\n\t\"github.com/izumin5210/grapi/pkg/grapiserver\"\n)\n\n// Run starts the grapiserver.\nfunc Run() error {\n\ts := grapiserver.New(\n\t\tgrapiserver.WithDefaultLogger(),\n\t\tgrapiserver.WithServers(\n\t\t// TODO\n\t\t),\n\t)\n\treturn s.Serve()\n}\n" var _Init71ed560e812a4261bc8b56d9feaef4800830e0b7 = "" // Init returns go-assets FileSystem -var Init = assets.NewFileSystem(map[string][]string{"/api/protos": []string{".keep.tmpl"}, "/app": []string{"run.go.tmpl"}, "/app/server": []string{".keep.tmpl"}, "/cmd": []string{}, "/cmd/server": []string{"run.go.tmpl"}, "/": []string{".gitignore.tmpl", "Gopkg.toml.tmpl", "grapi.toml.tmpl"}, "/api": []string{}}, map[string]*assets.File{ - "/api/protos/.keep.tmpl": &assets.File{ - Path: "/api/protos/.keep.tmpl", - FileMode: 0x1a4, +var Init = assets.NewFileSystem(map[string][]string{"/": []string{".gitignore.tmpl", "Gopkg.toml.tmpl", "grapi.toml.tmpl"}, "/api": []string{}, "/api/protos": []string{".keep.tmpl"}, "/app": []string{"run.go.tmpl"}, "/app/server": []string{".keep.tmpl"}, "/cmd": []string{}, "/cmd/server": []string{"run.go.tmpl"}}, map[string]*assets.File{ + "/api/protos": &assets.File{ + Path: "/api/protos", + FileMode: 0x800001ed, Mtime: time.Unix(1520753819, 1520753819000000000), - Data: []byte(_Init8d21956ba8abe388f964e47be0f7e5d170a2fce5), + Data: nil, }, "/app": &assets.File{ Path: "/app", FileMode: 0x800001ed, Mtime: time.Unix(1521995193, 1521995193000000000), Data: nil, + }, "/app/run.go.tmpl": &assets.File{ + Path: "/app/run.go.tmpl", + FileMode: 0x1a4, + Mtime: time.Unix(1521995193, 1521995193000000000), + Data: []byte(_Initbc4053f4dd26ceb67e4646e8c1d2cc75897c4dd0), }, "/app/server": &assets.File{ Path: "/app/server", FileMode: 0x800001ed, Mtime: time.Unix(1521042119, 1521042119000000000), Data: nil, - }, "/cmd/server/run.go.tmpl": &assets.File{ - Path: "/cmd/server/run.go.tmpl", - FileMode: 0x1a4, - Mtime: time.Unix(1530424640, 1530424640000000000), - Data: []byte(_Initd135936e91856b6159ac2eedcf89aa9f07773f82), - }, "/.gitignore.tmpl": &assets.File{ - Path: "/.gitignore.tmpl", + }, "/app/server/.keep.tmpl": &assets.File{ + Path: "/app/server/.keep.tmpl", FileMode: 0x1a4, - Mtime: time.Unix(1520753819, 1520753819000000000), - Data: []byte(_Init38e76c5db8962fa825cf2bd8b23a2dc985c4513e), + Mtime: time.Unix(1521042119, 1521042119000000000), + Data: []byte(_Init71ed560e812a4261bc8b56d9feaef4800830e0b7), }, "/cmd/server": &assets.File{ Path: "/cmd/server", FileMode: 0x800001ed, @@ -49,41 +49,41 @@ var Init = assets.NewFileSystem(map[string][]string{"/api/protos": []string{".ke }, "/": &assets.File{ Path: "/", FileMode: 0x800001ed, - Mtime: time.Unix(1534689869, 1534689869000000000), + Mtime: time.Unix(1537186773, 1537186773000000000), Data: nil, }, "/api": &assets.File{ Path: "/api", FileMode: 0x800001ed, Mtime: time.Unix(1520753819, 1520753819000000000), Data: nil, - }, "/app/server/.keep.tmpl": &assets.File{ - Path: "/app/server/.keep.tmpl", - FileMode: 0x1a4, - Mtime: time.Unix(1521042119, 1521042119000000000), - Data: []byte(_Init71ed560e812a4261bc8b56d9feaef4800830e0b7), }, "/cmd": &assets.File{ Path: "/cmd", FileMode: 0x800001ed, Mtime: time.Unix(1520753819, 1520753819000000000), Data: nil, - }, "/api/protos": &assets.File{ - Path: "/api/protos", - FileMode: 0x800001ed, + }, "/.gitignore.tmpl": &assets.File{ + Path: "/.gitignore.tmpl", + FileMode: 0x1a4, Mtime: time.Unix(1520753819, 1520753819000000000), - Data: nil, - }, "/app/run.go.tmpl": &assets.File{ - Path: "/app/run.go.tmpl", + Data: []byte(_Init38e76c5db8962fa825cf2bd8b23a2dc985c4513e), + }, "/api/protos/.keep.tmpl": &assets.File{ + Path: "/api/protos/.keep.tmpl", FileMode: 0x1a4, - Mtime: time.Unix(1521995193, 1521995193000000000), - Data: []byte(_Initbc4053f4dd26ceb67e4646e8c1d2cc75897c4dd0), + Mtime: time.Unix(1520753819, 1520753819000000000), + Data: []byte(_Init8d21956ba8abe388f964e47be0f7e5d170a2fce5), + }, "/cmd/server/run.go.tmpl": &assets.File{ + Path: "/cmd/server/run.go.tmpl", + FileMode: 0x1a4, + Mtime: time.Unix(1530424640, 1530424640000000000), + Data: []byte(_Initd135936e91856b6159ac2eedcf89aa9f07773f82), }, "/Gopkg.toml.tmpl": &assets.File{ Path: "/Gopkg.toml.tmpl", FileMode: 0x1a4, - Mtime: time.Unix(1534681778, 1534681778000000000), + Mtime: time.Unix(1537186773, 1537186773000000000), Data: []byte(_Init23b808cac963edf44a497827f2a6eff5ddac970f), }, "/grapi.toml.tmpl": &assets.File{ Path: "/grapi.toml.tmpl", FileMode: 0x1a4, - Mtime: time.Unix(1534689869, 1534689869000000000), + Mtime: time.Unix(1537184177, 1537184177000000000), Data: []byte(_Initc051c9ff1a8e446bc9636d3144c2775a7e235322), }}, "") diff --git a/pkg/grapicmd/internal/module/generator/template/init/Gopkg.toml.tmpl b/pkg/grapicmd/internal/module/generator/template/init/Gopkg.toml.tmpl index 8b11e96c..ea3d8e66 100644 --- a/pkg/grapicmd/internal/module/generator/template/init/Gopkg.toml.tmpl +++ b/pkg/grapicmd/internal/module/generator/template/init/Gopkg.toml.tmpl @@ -15,11 +15,4 @@ required = [ [[override]] name = "github.com/grpc-ecosystem/grpc-gateway" - # To use `paths` option in `protoc-gen-grpc-gateway` - # See https://github.com/grpc-ecosystem/grpc-gateway/pull/711 - revision = "42fa2028fd3ba4a546dd525d9db71573f1992ba1" - -[[override]] - name = "google.golang.org/grpc" - # To ignore grpc-gateway@42fa2028's constraints - version = "^1.11.3" + version = "^1.5.0" diff --git a/pkg/grapicmd/internal/module/testing/generator_mock.go b/pkg/grapicmd/internal/module/testing/generator_mock.go index 532bf747..227684a3 100644 --- a/pkg/grapicmd/internal/module/testing/generator_mock.go +++ b/pkg/grapicmd/internal/module/testing/generator_mock.go @@ -34,15 +34,15 @@ func (m *MockGenerator) EXPECT() *MockGeneratorMockRecorder { } // GenerateProject mocks base method -func (m *MockGenerator) GenerateProject(rootDir, pkgName string, useHead bool) error { - ret := m.ctrl.Call(m, "GenerateProject", rootDir, pkgName, useHead) +func (m *MockGenerator) GenerateProject(rootDir, pkgName string, cfg module.ProjectGenerationConfig) error { + ret := m.ctrl.Call(m, "GenerateProject", rootDir, pkgName, cfg) ret0, _ := ret[0].(error) return ret0 } // GenerateProject indicates an expected call of GenerateProject -func (mr *MockGeneratorMockRecorder) GenerateProject(rootDir, pkgName, useHead interface{}) *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GenerateProject", reflect.TypeOf((*MockGenerator)(nil).GenerateProject), rootDir, pkgName, useHead) +func (mr *MockGeneratorMockRecorder) GenerateProject(rootDir, pkgName, cfg interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GenerateProject", reflect.TypeOf((*MockGenerator)(nil).GenerateProject), rootDir, pkgName, cfg) } // GenerateService mocks base method @@ -129,15 +129,15 @@ func (m *MockProjectGenerator) EXPECT() *MockProjectGeneratorMockRecorder { } // GenerateProject mocks base method -func (m *MockProjectGenerator) GenerateProject(rootDir, pkgName string, useHead bool) error { - ret := m.ctrl.Call(m, "GenerateProject", rootDir, pkgName, useHead) +func (m *MockProjectGenerator) GenerateProject(rootDir, pkgName string, cfg module.ProjectGenerationConfig) error { + ret := m.ctrl.Call(m, "GenerateProject", rootDir, pkgName, cfg) ret0, _ := ret[0].(error) return ret0 } // GenerateProject indicates an expected call of GenerateProject -func (mr *MockProjectGeneratorMockRecorder) GenerateProject(rootDir, pkgName, useHead interface{}) *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GenerateProject", reflect.TypeOf((*MockProjectGenerator)(nil).GenerateProject), rootDir, pkgName, useHead) +func (mr *MockProjectGeneratorMockRecorder) GenerateProject(rootDir, pkgName, cfg interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GenerateProject", reflect.TypeOf((*MockProjectGenerator)(nil).GenerateProject), rootDir, pkgName, cfg) } // MockServiceGenerator is a mock of ServiceGenerator interface diff --git a/pkg/grapicmd/internal/usecase/initialize_project_usecase.go b/pkg/grapicmd/internal/usecase/initialize_project_usecase.go index e8ce555d..bbd20626 100644 --- a/pkg/grapicmd/internal/usecase/initialize_project_usecase.go +++ b/pkg/grapicmd/internal/usecase/initialize_project_usecase.go @@ -51,7 +51,7 @@ func (u *initializeProjectUsecase) Perform(rootDir, pkgName string, depSkipped, } func (u *initializeProjectUsecase) GenerateProject(rootDir, pkgName string, headUsed bool) error { - return errors.WithStack(u.generator.GenerateProject(rootDir, pkgName, headUsed)) + return errors.WithStack(u.generator.GenerateProject(rootDir, pkgName, module.ProjectGenerationConfig{UseHEAD: true})) } func (u *initializeProjectUsecase) InstallDeps(rootDir string) error {