Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Modules #176

Merged
merged 7 commits into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ jobs:
- <<: *test
go: '1.10'

- <<: *test-e2e
name: "E2E test (go 1.10.5)"
env:
- GO_VERSION=1.10.5
# TODO: Skip this because --HEAD option does not work with --use-dep option
# - <<: *test-e2e
# name: "E2E test (go 1.10.5)"
# env:
# - GO_VERSION=1.10.5
# - USE_DEP=1

- stage: deploy
install: make setup
Expand Down
6 changes: 6 additions & 0 deletions _tests/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func Test_Integration(t *testing.T) {

srcDir := filepath.Dir(wd)

os.Setenv("GO111MODULE", "on")

name := "sample"
rootPath := filepath.Join(srcDir, name)

Expand All @@ -35,6 +37,9 @@ func Test_Integration(t *testing.T) {
} else {
args = append(args, "--HEAD")
}
if os.Getenv("USE_DEP") == "1" {
args = append(args, "--use-dep")
}
args = append(args, name)

run(t, srcDir, exec.Command("grapi", args...))
Expand Down Expand Up @@ -269,6 +274,7 @@ func run(t *testing.T, dir string, cmd *exec.Cmd) {
cmd.Dir = dir
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = append(os.Environ(), "GO111MODULE=on")
err := cmd.Run()
if err != nil {
t.Fatalf("failed to execute command %v: %v", cmd, err)
Expand Down
1 change: 1 addition & 0 deletions _tests/e2e/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ docker build -t $IMAGE_NAME --build-arg GO_VERSION=$GO_VERSION -f ./$DIR/Dockerf
docker run \
-v $(pwd)/$DIR:/go/src/e2e \
--env TARGET_REVISION=$TARGET_REVISION \
--env USE_DEP=${USE_DEP:-0} \
$IMAGE_NAME \
sh -c 'go test -v -timeout 2m'
3 changes: 2 additions & 1 deletion pkg/grapicmd/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ func newInitCommand(ctx *grapicmd.Ctx) *cobra.Command {

cmd.PersistentFlags().StringVar(&cfg.Revision, "revision", "", "Specify grapi revision")
cmd.PersistentFlags().StringVar(&cfg.Branch, "branch", "", "Specify grapi branch")
cmd.PersistentFlags().StringVar(&cfg.Version, "version", ctx.Build.Version, "Specify grapi version")
cmd.PersistentFlags().StringVar(&cfg.Version, "version", "", "Specify grapi version")
cmd.PersistentFlags().BoolVar(&cfg.HEAD, "HEAD", false, "Use HEAD grapi")
cmd.PersistentFlags().StringVarP(&cfg.Package, "package", "p", "", `Package name of the application(default: "<parent_package_or_username>.<app_name>")`)
cmd.PersistentFlags().BoolVar(&cfg.Dep, "use-dep", false, "Use dep instead of Modules")

return cmd
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/grapicmd/di/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ func ProvideScriptLoader(ctx *grapicmd.Ctx, executor excmd.Executor) module.Scri
return script.NewLoader(ctx.FS, executor, ctx.RootDir.String())
}

func ProvideInitializeProjectUsecase(ctx *grapicmd.Ctx, gexCfg *gex.Config, ui cli.UI, generator module.Generator) usecase.InitializeProjectUsecase {
func ProvideInitializeProjectUsecase(ctx *grapicmd.Ctx, gexCfg *gex.Config, ui cli.UI, generator module.Generator, excmd excmd.Executor) usecase.InitializeProjectUsecase {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported function ProvideInitializeProjectUsecase should have comment or be unexported

return usecase.NewInitializeProjectUsecase(
ui,
generator,
excmd,
gexCfg,
)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/grapicmd/di/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ 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",
'{{ module "github.com/grpc-ecosystem/grpc-gateway" }}',
'{{ module "github.com/grpc-ecosystem/grpc-gateway" }}/third_party/googleapis',
]

[[protoc.plugins]]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// +build tools

package tools

// tool dependencies
import (
_ "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"
_ "github.com/izumin5210/grapi/cmd/grapi"
_ "github.com/izumin5210/grapi/cmd/grapi-gen-command"
_ "github.com/izumin5210/grapi/cmd/grapi-gen-scaffold-service"
_ "github.com/izumin5210/grapi/cmd/grapi-gen-service"
_ "github.com/izumin5210/grapi/cmd/grapi-gen-type"
)

2 changes: 1 addition & 1 deletion pkg/grapicmd/internal/module/generator/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func TestProjectGenerator_GenerateProject(t *testing.T) {

files := []string{
".gitignore",
"Gopkg.toml",
"grapi.toml",
"tools.go",
"app/run.go",
"cmd/server/run.go",
}
Expand Down
118 changes: 59 additions & 59 deletions pkg/grapicmd/internal/module/generator/template/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,94 +7,94 @@ import (
)

var _Init50bb4ac2099b3758964058926b3c90524e478a2c = ""
var _Init23b808cac963edf44a497827f2a6eff5ddac970f = ""
var _Init38e76c5db8962fa825cf2bd8b23a2dc985c4513e = "*.so\n/vendor\n/bin\n/tmp\n"
var _Init8d21956ba8abe388f964e47be0f7e5d170a2fce5 = ""
var _Init71ed560e812a4261bc8b56d9feaef4800830e0b7 = ""
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 name = \"go\"\n args = { plugins = \"grpc\", paths = \"source_relative\" }\n\n [[protoc.plugins]]\n name = \"grpc-gateway\"\n args = { logtostderr = true, paths = \"source_relative\" }\n\n [[protoc.plugins]]\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 _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 _Init38e76c5db8962fa825cf2bd8b23a2dc985c4513e = "*.so\n/vendor\n/bin\n/tmp\n"
var _Init881d845139e03b8e1e2dafd175e793d03f9bacaf = "// +build tools\n\npackage tools\n\n// tool dependencies\nimport (\n\t_ \"github.com/golang/protobuf/protoc-gen-go\"\n\t_ \"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway\"\n\t_ \"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger\"\n\t_ \"github.com/izumin5210/grapi/cmd/grapi\"\n\t_ \"github.com/izumin5210/grapi/cmd/grapi-gen-command\"\n\t_ \"github.com/izumin5210/grapi/cmd/grapi-gen-scaffold-service\"\n\t_ \"github.com/izumin5210/grapi/cmd/grapi-gen-service\"\n\t_ \"github.com/izumin5210/grapi/cmd/grapi-gen-type\"\n)\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 = ""
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 '{{`{{ module \"github.com/grpc-ecosystem/grpc-gateway\" }}`}}',\n '{{`{{ module \"github.com/grpc-ecosystem/grpc-gateway\" }}`}}/third_party/googleapis',\n]\n\n [[protoc.plugins]]\n name = \"go\"\n args = { plugins = \"grpc\", paths = \"source_relative\" }\n\n [[protoc.plugins]]\n name = \"grpc-gateway\"\n args = { logtostderr = true, paths = \"source_relative\" }\n\n [[protoc.plugins]]\n name = \"swagger\"\n args = { logtostderr = true }\n"

// Init returns go-assets FileSystem
var Init = assets.NewFileSystem(map[string][]string{"/app": []string{"run.go.tmpl"}, "/app/server": []string{".keep.tmpl"}, "/cmd": []string{}, "/": []string{".gitignore.tmpl", "Gopkg.toml.tmpl", "grapi.toml.tmpl"}, "/api": []string{}, "/cmd/server": []string{"run.go.tmpl"}, "/api/protos": []string{".keep.tmpl"}, "/api/protos/type": []string{".keep.tmpl"}}, map[string]*assets.File{
"/cmd/server/run.go.tmpl": &assets.File{
Path: "/cmd/server/run.go.tmpl",
var Init = assets.NewFileSystem(map[string][]string{"/api/protos": []string{".keep.tmpl"}, "/api/protos/type": []string{".keep.tmpl"}, "/app": []string{"run.go.tmpl"}, "/app/server": []string{".keep.tmpl"}, "/": []string{".gitignore.tmpl", "tools.go", "grapi.toml.tmpl"}, "/cmd": []string{}, "/cmd/server": []string{"run.go.tmpl"}, "/api": []string{}}, map[string]*assets.File{
"/app/server/.keep.tmpl": &assets.File{
Path: "/app/server/.keep.tmpl",
FileMode: 0x1a4,
Mtime: time.Unix(1540629396, 1540629396000000000),
Data: []byte(_Initd135936e91856b6159ac2eedcf89aa9f07773f82),
}, "/": &assets.File{
Path: "/",
Mtime: time.Unix(1546318740, 1546318740833081345),
Data: []byte(_Init71ed560e812a4261bc8b56d9feaef4800830e0b7),
}, "/grapi.toml.tmpl": &assets.File{
Path: "/grapi.toml.tmpl",
FileMode: 0x1a4,
Mtime: time.Unix(1553208226, 1553208226821968880),
Data: []byte(_Initc051c9ff1a8e446bc9636d3144c2775a7e235322),
}, "/api/protos/type": &assets.File{
Path: "/api/protos/type",
FileMode: 0x800001ed,
Mtime: time.Unix(1541934989, 1541934989000000000),
Mtime: time.Unix(1546318740, 1546318740832742956),
Data: nil,
}, "/app/run.go.tmpl": &assets.File{
Path: "/app/run.go.tmpl",
}, "/api/protos/type/.keep.tmpl": &assets.File{
Path: "/api/protos/type/.keep.tmpl",
FileMode: 0x1a4,
Mtime: time.Unix(1540629396, 1540629396000000000),
Data: []byte(_Initbc4053f4dd26ceb67e4646e8c1d2cc75897c4dd0),
Mtime: time.Unix(1546318740, 1546318740832736215),
Data: []byte(_Init50bb4ac2099b3758964058926b3c90524e478a2c),
}, "/api/protos/.keep.tmpl": &assets.File{
Path: "/api/protos/.keep.tmpl",
FileMode: 0x1a4,
Mtime: time.Unix(1546318740, 1546318740832594918),
Data: []byte(_Init8d21956ba8abe388f964e47be0f7e5d170a2fce5),
}, "/cmd": &assets.File{
Path: "/cmd",
FileMode: 0x800001ed,
Mtime: time.Unix(1540629396, 1540629396000000000),
Mtime: time.Unix(1546318740, 1546318740833267962),
Data: nil,
}, "/cmd/server": &assets.File{
Path: "/cmd/server",
FileMode: 0x800001ed,
Mtime: time.Unix(1540629396, 1540629396000000000),
Mtime: time.Unix(1546318740, 1546318740833342619),
Data: nil,
}, "/api/protos/type/.keep.tmpl": &assets.File{
Path: "/api/protos/type/.keep.tmpl",
}, "/cmd/server/run.go.tmpl": &assets.File{
Path: "/cmd/server/run.go.tmpl",
FileMode: 0x1a4,
Mtime: time.Unix(1542064098, 1542064098000000000),
Data: []byte(_Init50bb4ac2099b3758964058926b3c90524e478a2c),
}, "/app": &assets.File{
Path: "/app",
Mtime: time.Unix(1546318740, 1546318740833383528),
Data: []byte(_Initd135936e91856b6159ac2eedcf89aa9f07773f82),
}, "/.gitignore.tmpl": &assets.File{
Path: "/.gitignore.tmpl",
FileMode: 0x1a4,
Mtime: time.Unix(1546318740, 1546318740832281063),
Data: []byte(_Init38e76c5db8962fa825cf2bd8b23a2dc985c4513e),
}, "/api/protos": &assets.File{
Path: "/api/protos",
FileMode: 0x800001ed,
Mtime: time.Unix(1540629396, 1540629396000000000),
Mtime: time.Unix(1546318740, 1546318740832681569),
Data: nil,
}, "/app/server": &assets.File{
Path: "/app/server",
}, "/": &assets.File{
Path: "/",
FileMode: 0x800001ed,
Mtime: time.Unix(1540629396, 1540629396000000000),
Mtime: time.Unix(1553208226, 1553208226822999213),
Data: nil,
}, "/Gopkg.toml.tmpl": &assets.File{
Path: "/Gopkg.toml.tmpl",
FileMode: 0x1a4,
Mtime: time.Unix(1541934989, 1541934989000000000),
Data: []byte(_Init23b808cac963edf44a497827f2a6eff5ddac970f),
}, "/api/protos": &assets.File{
Path: "/api/protos",
}, "/app": &assets.File{
Path: "/app",
FileMode: 0x800001ed,
Mtime: time.Unix(1542064086, 1542064086000000000),
Mtime: time.Unix(1546318740, 1546318740833025623),
Data: nil,
}, "/api/protos/type": &assets.File{
Path: "/api/protos/type",
}, "/app/server": &assets.File{
Path: "/app/server",
FileMode: 0x800001ed,
Mtime: time.Unix(1542064098, 1542064098000000000),
Mtime: time.Unix(1546318740, 1546318740833088256),
Data: nil,
}, "/api/protos/.keep.tmpl": &assets.File{
Path: "/api/protos/.keep.tmpl",
}, "/tools.go": &assets.File{
Path: "/tools.go",
FileMode: 0x1a4,
Mtime: time.Unix(1540629396, 1540629396000000000),
Data: []byte(_Init8d21956ba8abe388f964e47be0f7e5d170a2fce5),
}, "/app/server/.keep.tmpl": &assets.File{
Path: "/app/server/.keep.tmpl",
FileMode: 0x1a4,
Mtime: time.Unix(1540629396, 1540629396000000000),
Data: []byte(_Init71ed560e812a4261bc8b56d9feaef4800830e0b7),
}, "/grapi.toml.tmpl": &assets.File{
Path: "/grapi.toml.tmpl",
FileMode: 0x1a4,
Mtime: time.Unix(1541934989, 1541934989000000000),
Data: []byte(_Initc051c9ff1a8e446bc9636d3144c2775a7e235322),
}, "/.gitignore.tmpl": &assets.File{
Path: "/.gitignore.tmpl",
Mtime: time.Unix(1552871847, 1552871847434755798),
Data: []byte(_Init881d845139e03b8e1e2dafd175e793d03f9bacaf),
}, "/app/run.go.tmpl": &assets.File{
Path: "/app/run.go.tmpl",
FileMode: 0x1a4,
Mtime: time.Unix(1540629396, 1540629396000000000),
Data: []byte(_Init38e76c5db8962fa825cf2bd8b23a2dc985c4513e),
Mtime: time.Unix(1546318740, 1546318740832927467),
Data: []byte(_Initbc4053f4dd26ceb67e4646e8c1d2cc75897c4dd0),
}, "/api": &assets.File{
Path: "/api",
FileMode: 0x800001ed,
Mtime: time.Unix(1540629396, 1540629396000000000),
Mtime: time.Unix(1546318740, 1546318740832528992),
Data: nil,
}}, "")
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ 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",
'{{`{{ module "github.com/grpc-ecosystem/grpc-gateway" }}`}}',
'{{`{{ module "github.com/grpc-ecosystem/grpc-gateway" }}`}}/third_party/googleapis',
]

[[protoc.plugins]]
Expand Down
15 changes: 15 additions & 0 deletions pkg/grapicmd/internal/module/generator/template/init/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// +build tools

package tools

// tool dependencies
import (
_ "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"
_ "github.com/izumin5210/grapi/cmd/grapi"
_ "github.com/izumin5210/grapi/cmd/grapi-gen-command"
_ "github.com/izumin5210/grapi/cmd/grapi-gen-scaffold-service"
_ "github.com/izumin5210/grapi/cmd/grapi-gen-service"
_ "github.com/izumin5210/grapi/cmd/grapi-gen-type"
)
1 change: 1 addition & 0 deletions pkg/grapicmd/internal/usecase/init_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type InitConfig struct {
Version string
HEAD bool
Package string
Dep bool
}

func (c *InitConfig) BuildSpec() string {
Expand Down
Loading