Compare commits
52 Commits
feat/ci-bo
...
main
Author | SHA1 | Date |
---|---|---|
LinXiaoWei | bffc1a0989 | 1 year ago |
包子 | 32b1d13f90 | 1 year ago |
dependabot[bot] | db2a565d1c | 1 year ago |
jessetang | fcd3b18e83 | 1 year ago |
freezeChen | 3445f3ea8e | 1 year ago |
Tony Chen | 32c0d2dd97 | 1 year ago |
xu0o0 | e86ad248c3 | 1 year ago |
liaochuntao | 69d73225a9 | 1 year ago |
Fengbin Shi | 49ffd95a0c | 1 year ago |
haiyux | 96480c11ee | 2 years ago |
dependabot[bot] | 1d50f50262 | 2 years ago |
dependabot[bot] | 6d741828c2 | 2 years ago |
Xudong Cai | 4a56b5669d | 2 years ago |
包子 | 56777ee655 | 2 years ago |
dependabot[bot] | b1cd1d3cf8 | 2 years ago |
dependabot[bot] | 37a521d59f | 2 years ago |
dependabot[bot] | 6cf407b9bd | 2 years ago |
dependabot[bot] | a904794546 | 2 years ago |
chen quan | a837603c6d | 2 years ago |
dependabot[bot] | 0b1fdbe51c | 2 years ago |
dependabot[bot] | 81988e6a85 | 2 years ago |
Haibo | 1f10166028 | 2 years ago |
dependabot[bot] | c6a4604839 | 2 years ago |
Bin | aed172b8dd | 2 years ago |
dependabot[bot] | 520b321fe9 | 2 years ago |
ibrahim albarghouthi | 3958f9d5c0 | 2 years ago |
dependabot[bot] | e9870cb48f | 2 years ago |
dependabot[bot] | f8c19c37af | 2 years ago |
woniu317 | d0847cd462 | 2 years ago |
jessetang | f03f5f8988 | 2 years ago |
jessetang | d470886977 | 2 years ago |
Bin | 446774f9e5 | 2 years ago |
yonwoo9 | e273c5188a | 2 years ago |
jessetang | 393bf4dbcb | 2 years ago |
虫子樱桃 | 6a4d17d79a | 2 years ago |
Bin | 99ccd00434 | 2 years ago |
dependabot[bot] | f47a238478 | 2 years ago |
dependabot[bot] | 3d1af9af38 | 2 years ago |
jessetang | 9a973d29c2 | 2 years ago |
jessetang | 0c2d2632ac | 2 years ago |
包子 | 78a2089f2b | 2 years ago |
Xin | d05729399e | 2 years ago |
包子 | 8af9ca33bd | 2 years ago |
dependabot[bot] | bd26120ec6 | 2 years ago |
jessetang | 6369db2e8e | 2 years ago |
jessetang | 492248d032 | 2 years ago |
虫子樱桃 | ae4dd7f4a8 | 2 years ago |
包子 | 33cb4576e9 | 2 years ago |
包子 | 768ffd71d4 | 2 years ago |
jessetang | 9ee4fcb48a | 2 years ago |
jessetang | ae2dcb04c0 | 2 years ago |
Xin | 6602dc325e | 2 years ago |
@ -0,0 +1,12 @@ |
|||||||
|
daysUntilStale: 30 |
||||||
|
daysUntilClose: 3 |
||||||
|
exemptLabels: |
||||||
|
- pinned |
||||||
|
- security |
||||||
|
- bug |
||||||
|
staleLabel: wontfix |
||||||
|
markComment: > |
||||||
|
This issue has been automatically marked as stale because it has not had |
||||||
|
recent activity. It will be closed if no further activity occurs. Thank you |
||||||
|
for your contributions. |
||||||
|
closeComment: true |
@ -0,0 +1,144 @@ |
|||||||
|
package project |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
"go/parser" |
||||||
|
"go/token" |
||||||
|
"os" |
||||||
|
"path/filepath" |
||||||
|
"testing" |
||||||
|
|
||||||
|
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base" |
||||||
|
) |
||||||
|
|
||||||
|
// TestCmdNew tests the `kratos new` command.
|
||||||
|
func TestCmdNew(t *testing.T) { |
||||||
|
cwd := changeCurrentDir(t) |
||||||
|
projectName := "helloworld" |
||||||
|
|
||||||
|
// create a new project
|
||||||
|
CmdNew.SetArgs([]string{projectName}) |
||||||
|
if err := CmdNew.Execute(); err != nil { |
||||||
|
t.Fatalf("executing command: %v", err) |
||||||
|
} |
||||||
|
|
||||||
|
// check that the expected files were created
|
||||||
|
for _, file := range []string{ |
||||||
|
"go.mod", |
||||||
|
"go.sum", |
||||||
|
"README.md", |
||||||
|
"cmd/helloworld/main.go", |
||||||
|
} { |
||||||
|
if _, err := os.Stat(filepath.Join(cwd, projectName, file)); err != nil { |
||||||
|
t.Errorf("expected file %s to exist", file) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// check that the go.mod file contains the expected module name
|
||||||
|
assertGoMod(t, filepath.Join(cwd, projectName, "go.mod"), projectName) |
||||||
|
|
||||||
|
assertImportsInclude(t, filepath.Join(cwd, projectName, "cmd", projectName, "wire.go"), fmt.Sprintf(`"%s/internal/biz"`, projectName)) |
||||||
|
} |
||||||
|
|
||||||
|
// TestCmdNewNoMod tests the `kratos new` command with the --nomod flag.
|
||||||
|
func TestCmdNewNoMod(t *testing.T) { |
||||||
|
cwd := changeCurrentDir(t) |
||||||
|
|
||||||
|
// create a new project
|
||||||
|
CmdNew.SetArgs([]string{"project"}) |
||||||
|
if err := CmdNew.Execute(); err != nil { |
||||||
|
t.Fatalf("executing command: %v", err) |
||||||
|
} |
||||||
|
|
||||||
|
// add new app with --nomod flag
|
||||||
|
CmdNew.SetArgs([]string{"--nomod", "project/app/user"}) |
||||||
|
if err := CmdNew.Execute(); err != nil { |
||||||
|
t.Fatalf("executing command: %v", err) |
||||||
|
} |
||||||
|
|
||||||
|
// check that the expected files were created
|
||||||
|
for _, file := range []string{ |
||||||
|
"go.mod", |
||||||
|
"go.sum", |
||||||
|
"README.md", |
||||||
|
"cmd/project/main.go", |
||||||
|
"app/user/cmd/user/main.go", |
||||||
|
} { |
||||||
|
if _, err := os.Stat(filepath.Join(cwd, "project", file)); err != nil { |
||||||
|
t.Errorf("expected file %s to exist", file) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
assertImportsInclude(t, filepath.Join(cwd, "project/app/user/cmd/user/wire.go"), `"project/app/user/internal/biz"`) |
||||||
|
} |
||||||
|
|
||||||
|
// assertImportsInclude checks that the file at path contains the expected import.
|
||||||
|
func assertImportsInclude(t *testing.T, path, expected string) { |
||||||
|
t.Helper() |
||||||
|
|
||||||
|
got, err := imports(path) |
||||||
|
if err != nil { |
||||||
|
t.Fatalf("getting imports: %v", err) |
||||||
|
} |
||||||
|
|
||||||
|
for _, imp := range got { |
||||||
|
if imp == expected { |
||||||
|
return |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
t.Errorf("expected imports to include %s, got %v", expected, got) |
||||||
|
} |
||||||
|
|
||||||
|
// imports returns the imports in the file at path.
|
||||||
|
func imports(path string) ([]string, error) { |
||||||
|
fset := token.NewFileSet() |
||||||
|
f, err := parser.ParseFile(fset, path, nil, parser.ImportsOnly) |
||||||
|
if err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
|
||||||
|
imports := make([]string, 0, len(f.Imports)) |
||||||
|
for _, s := range f.Imports { |
||||||
|
imports = append(imports, s.Path.Value) |
||||||
|
} |
||||||
|
|
||||||
|
return imports, nil |
||||||
|
} |
||||||
|
|
||||||
|
// assertGoMod checks that the go.mod file contains the expected module name.
|
||||||
|
func assertGoMod(t *testing.T, path, expected string) { |
||||||
|
t.Helper() |
||||||
|
|
||||||
|
got, err := base.ModulePath(path) |
||||||
|
if err != nil { |
||||||
|
t.Fatalf("getting module path: %v", err) |
||||||
|
} |
||||||
|
|
||||||
|
if got != expected { |
||||||
|
t.Errorf("expected module name %s, got %s", expected, got) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// change the working directory to the tempdir
|
||||||
|
func changeCurrentDir(t *testing.T) string { |
||||||
|
t.Helper() |
||||||
|
|
||||||
|
tmp := t.TempDir() |
||||||
|
|
||||||
|
oldCWD, err := os.Getwd() |
||||||
|
if err != nil { |
||||||
|
t.Fatalf("getting working directory: %v", err) |
||||||
|
} |
||||||
|
|
||||||
|
if err := os.Chdir(tmp); err != nil { |
||||||
|
t.Fatalf("changing working directory: %v", err) |
||||||
|
} |
||||||
|
t.Cleanup(func() { |
||||||
|
if err := os.Chdir(oldCWD); err != nil { |
||||||
|
t.Fatalf("restoring working directory: %v", err) |
||||||
|
} |
||||||
|
}) |
||||||
|
|
||||||
|
return tmp |
||||||
|
} |
@ -1,4 +1,4 @@ |
|||||||
package main |
package main |
||||||
|
|
||||||
// release is the current kratos tool version.
|
// release is the current kratos tool version.
|
||||||
const release = "v2.6.1" |
const release = "v2.6.3" |
||||||
|
@ -0,0 +1,17 @@ |
|||||||
|
{{ range .Errors }} |
||||||
|
|
||||||
|
{{ if .HasComment }}{{ .Comment }}{{ end -}} |
||||||
|
func Is{{.CamelValue}}(err error) bool { |
||||||
|
if err == nil { |
||||||
|
return false |
||||||
|
} |
||||||
|
e := errors.FromError(err) |
||||||
|
return e.Reason == {{ .Name }}_{{ .Value }}.String() && e.Code == {{ .HTTPCode }} |
||||||
|
} |
||||||
|
|
||||||
|
{{ if .HasComment }}{{ .Comment }}{{ end -}} |
||||||
|
func Error{{ .CamelValue }}(format string, args ...interface{}) *errors.Error { |
||||||
|
return errors.New({{ .HTTPCode }}, {{ .Name }}_{{ .Value }}.String(), fmt.Sprintf(format, args...)) |
||||||
|
} |
||||||
|
|
||||||
|
{{- end }} |
@ -1,4 +1,4 @@ |
|||||||
package main |
package main |
||||||
|
|
||||||
// release is the current protoc-gen-go-errors version.
|
// release is the current protoc-gen-go-errors version.
|
||||||
const release = "v2.6.1" |
const release = "v2.6.3" |
||||||
|
@ -0,0 +1,93 @@ |
|||||||
|
{{$svrType := .ServiceType}} |
||||||
|
{{$svrName := .ServiceName}} |
||||||
|
|
||||||
|
{{- range .MethodSets}} |
||||||
|
const Operation{{$svrType}}{{.OriginalName}} = "/{{$svrName}}/{{.OriginalName}}" |
||||||
|
{{- end}} |
||||||
|
|
||||||
|
type {{.ServiceType}}HTTPServer interface { |
||||||
|
{{- range .MethodSets}} |
||||||
|
{{- if ne .Comment ""}} |
||||||
|
{{.Comment}} |
||||||
|
{{- end}} |
||||||
|
{{.Name}}(context.Context, *{{.Request}}) (*{{.Reply}}, error) |
||||||
|
{{- end}} |
||||||
|
} |
||||||
|
|
||||||
|
func Register{{.ServiceType}}HTTPServer(s *http.Server, srv {{.ServiceType}}HTTPServer) { |
||||||
|
r := s.Route("/") |
||||||
|
{{- range .Methods}} |
||||||
|
r.{{.Method}}("{{.Path}}", _{{$svrType}}_{{.Name}}{{.Num}}_HTTP_Handler(srv)) |
||||||
|
{{- end}} |
||||||
|
} |
||||||
|
|
||||||
|
{{range .Methods}} |
||||||
|
func _{{$svrType}}_{{.Name}}{{.Num}}_HTTP_Handler(srv {{$svrType}}HTTPServer) func(ctx http.Context) error { |
||||||
|
return func(ctx http.Context) error { |
||||||
|
var in {{.Request}} |
||||||
|
{{- if .HasBody}} |
||||||
|
if err := ctx.Bind(&in{{.Body}}); err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
|
||||||
|
{{- if not (eq .Body "")}} |
||||||
|
if err := ctx.BindQuery(&in); err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
{{- end}} |
||||||
|
{{- else}} |
||||||
|
if err := ctx.BindQuery(&in{{.Body}}); err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
{{- end}} |
||||||
|
{{- if .HasVars}} |
||||||
|
if err := ctx.BindVars(&in); err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
{{- end}} |
||||||
|
http.SetOperation(ctx,Operation{{$svrType}}{{.OriginalName}}) |
||||||
|
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { |
||||||
|
return srv.{{.Name}}(ctx, req.(*{{.Request}})) |
||||||
|
}) |
||||||
|
out, err := h(ctx, &in) |
||||||
|
if err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
reply := out.(*{{.Reply}}) |
||||||
|
return ctx.Result(200, reply{{.ResponseBody}}) |
||||||
|
} |
||||||
|
} |
||||||
|
{{end}} |
||||||
|
|
||||||
|
type {{.ServiceType}}HTTPClient interface { |
||||||
|
{{- range .MethodSets}} |
||||||
|
{{.Name}}(ctx context.Context, req *{{.Request}}, opts ...http.CallOption) (rsp *{{.Reply}}, err error) |
||||||
|
{{- end}} |
||||||
|
} |
||||||
|
|
||||||
|
type {{.ServiceType}}HTTPClientImpl struct{ |
||||||
|
cc *http.Client |
||||||
|
} |
||||||
|
|
||||||
|
func New{{.ServiceType}}HTTPClient (client *http.Client) {{.ServiceType}}HTTPClient { |
||||||
|
return &{{.ServiceType}}HTTPClientImpl{client} |
||||||
|
} |
||||||
|
|
||||||
|
{{range .MethodSets}} |
||||||
|
func (c *{{$svrType}}HTTPClientImpl) {{.Name}}(ctx context.Context, in *{{.Request}}, opts ...http.CallOption) (*{{.Reply}}, error) { |
||||||
|
var out {{.Reply}} |
||||||
|
pattern := "{{.Path}}" |
||||||
|
path := binding.EncodeURL(pattern, in, {{not .HasBody}}) |
||||||
|
opts = append(opts, http.Operation(Operation{{$svrType}}{{.OriginalName}})) |
||||||
|
opts = append(opts, http.PathTemplate(pattern)) |
||||||
|
{{if .HasBody -}} |
||||||
|
err := c.cc.Invoke(ctx, "{{.Method}}", path, in{{.Body}}, &out{{.ResponseBody}}, opts...) |
||||||
|
{{else -}} |
||||||
|
err := c.cc.Invoke(ctx, "{{.Method}}", path, nil, &out{{.ResponseBody}}, opts...) |
||||||
|
{{end -}} |
||||||
|
if err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
return &out, err |
||||||
|
} |
||||||
|
{{end}} |
@ -1,4 +1,4 @@ |
|||||||
package main |
package main |
||||||
|
|
||||||
// release is the current protoc-gen-go-http version.
|
// release is the current protoc-gen-go-http version.
|
||||||
const release = "v2.6.1" |
const release = "v2.6.3" |
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue