Skip to content

Commit 3062338

Browse files
committed
fix: client gen fix and reformat
1 parent f21d087 commit 3062338

File tree

76 files changed

+599
-716
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+599
-716
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ test.race:
88
CGO_ENABLED=1 go test -v -race ./...
99

1010
fmt:
11-
goimports -l -w .
11+
go tool gofumpt -l -w .
1212

1313
dep:
1414
go get -u ./...
1515

1616
gen:
17-
go run ./tool/internal/cmd/gen
17+
go generate ./...
1818

1919
serve:
20-
go run ./example/cmd/example
20+
go tool example

devpkg/clientgen/gen.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ func (g *clientGen) generateClient(c gengo.Context, named *types.Named) error {
106106
return err
107107
}
108108
}
109-
110109
}
111110
}
112111

@@ -172,7 +171,7 @@ type @Operation'Parameters struct {
172171
"ResponseData": snippet.Snippets(func(yield func(snippet.Snippet) bool) {
173172
if hasResponse {
174173
if !yield(snippet.T(`
175-
func (r *@Operation) ResponseData() (*@Operation'Response) {
174+
func (@Operation) ResponseData() (*@Operation'Response) {
176175
return new(@Operation'Response)
177176
}
178177
`, snippet.Args{
@@ -185,7 +184,7 @@ func (r *@Operation) ResponseData() (*@Operation'Response) {
185184
}
186185

187186
if !yield(snippet.T(`
188-
func (r *@Operation) ResponseData() (*@courierNoContent) {
187+
func (@Operation) ResponseData() (*@courierNoContent) {
189188
return new(@courierNoContent)
190189
}
191190
@@ -259,7 +258,6 @@ func (r *@Operation) ResponseData() (*@courierNoContent) {
259258
if !yield(snippet.T(`
260259
@Type `+"`"+`in:"body" mime:@mime`+"`"+`
261260
`, snippet.Args{
262-
263261
"mime": snippet.Value("application/octet-stream"),
264262
"Type": snippet.ID("io.ReadCloser"),
265263
})) {
@@ -271,7 +269,6 @@ func (r *@Operation) ResponseData() (*@courierNoContent) {
271269
if !yield(snippet.T(`
272270
@FieldName @Type `+"`"+`in:"body" mime:@mime`+"`"+`
273271
`, snippet.Args{
274-
275272
"mime": snippet.Value(contentType),
276273
"Type": g.typeOfSchema(c, mt.Schema),
277274
"FieldName": func() snippet.Snippet {
@@ -344,7 +341,6 @@ type @Type = @TypeRef
344341
type @Type = @TypeDef
345342
346343
`, snippet.Args{
347-
348344
"Type": snippet.ID(name),
349345
"TypeDef": t.Decl,
350346
})

devpkg/injectablegen/injectable.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ func (g *injectableGen) GenerateAliasType(c gengo.Context, t *types.Alias) error
9999
func (g *injectableGen) genAsProvider(c gengo.Context, t interface {
100100
Obj() *types.TypeName
101101
Underlying() types.Type
102-
}, impl string, forAlias bool) error {
102+
}, impl string, forAlias bool,
103+
) error {
103104
switch x := t.Underlying().(type) {
104105
case *types.Interface:
105106
c.RenderT(`

devpkg/operatorgen/gen.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ import (
99
"strconv"
1010
"strings"
1111

12-
"github.com/octohelm/gengo/pkg/gengo/snippet"
13-
1412
"github.com/octohelm/courier/pkg/courier"
1513
"github.com/octohelm/courier/pkg/courierhttp"
1614
"github.com/octohelm/gengo/pkg/gengo"
15+
"github.com/octohelm/gengo/pkg/gengo/snippet"
1716
gengotypes "github.com/octohelm/gengo/pkg/types"
1817
typex "github.com/octohelm/x/types"
1918
)
@@ -22,8 +21,7 @@ func init() {
2221
gengo.Register(&operatorGen{})
2322
}
2423

25-
type operatorGen struct {
26-
}
24+
type operatorGen struct{}
2725

2826
func (g *operatorGen) Name() string {
2927
return "operator"
@@ -128,7 +126,6 @@ func (*@Type) ResponseData() *@courierNoContent {
128126
"Type": snippet.ID(named.Obj()),
129127
"courierNoContent": snippet.ID("github.com/octohelm/courier/pkg/courier.NoContent"),
130128
})
131-
132129
} else if types.IsInterface(tpe) && !strings.Contains(tpe.String(), "github.com/octohelm/courier/pkg/courierhttp.Response") {
133130
c.Logger().Warn(fmt.Errorf("%s return interface %s will be untyped jsonschema", named, tpe))
134131
} else {

devpkg/operatorgen/statuserr_scanner.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,7 @@ func (s *statusErrScanner) scanStatusErrIsExist(typeFunc *types.Func, pkg gengot
179179
return false
180180
}
181181

182-
var (
183-
rtypeErrorWithStatusCode = typex.FromRType(reflect.TypeOf((*statuserror.WithStatusCode)(nil)).Elem())
184-
)
182+
var rtypeErrorWithStatusCode = typex.FromRType(reflect.TypeOf((*statuserror.WithStatusCode)(nil)).Elem())
185183

186184
func isErrWithStatusCodeInterface(named *types.Named) bool {
187185
if named != nil {

example/apis/api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
//go:generate go tool gen .
12
package apis
23

34
import (
45
"github.com/octohelm/courier/example/apis/blob"
5-
"github.com/octohelm/courier/pkg/courier"
6-
"github.com/octohelm/courier/pkg/courierhttp"
7-
86
"github.com/octohelm/courier/example/apis/org"
97
"github.com/octohelm/courier/example/apis/store"
8+
"github.com/octohelm/courier/pkg/courier"
9+
"github.com/octohelm/courier/pkg/courierhttp"
1010
"github.com/octohelm/courier/pkg/courierhttp/handler/httprouter"
1111
)
1212

example/apis/blob/zz_generated.runtimedoc.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,6 @@ DON'T EDIT THIS FILE
44
*/
55
package blob
66

7-
import _ "embed"
8-
9-
// nolint:deadcode,unused
10-
func runtimeDoc(v any, prefix string, names ...string) ([]string, bool) {
11-
if c, ok := v.(interface {
12-
RuntimeDoc(names ...string) ([]string, bool)
13-
}); ok {
14-
doc, ok := c.RuntimeDoc(names...)
15-
if ok {
16-
if prefix != "" && len(doc) > 0 {
17-
doc[0] = prefix + doc[0]
18-
return doc, true
19-
}
20-
21-
return doc, true
22-
}
23-
}
24-
return nil, false
25-
}
26-
277
func (v *GetFile) RuntimeDoc(names ...string) ([]string, bool) {
288
if len(names) > 0 {
299
switch names[0] {
@@ -47,3 +27,21 @@ func (v *UploadBlob) RuntimeDoc(names ...string) ([]string, bool) {
4727
}
4828
return []string{}, true
4929
}
30+
31+
// nolint:deadcode,unused
32+
func runtimeDoc(v any, prefix string, names ...string) ([]string, bool) {
33+
if c, ok := v.(interface {
34+
RuntimeDoc(names ...string) ([]string, bool)
35+
}); ok {
36+
doc, ok := c.RuntimeDoc(names...)
37+
if ok {
38+
if prefix != "" && len(doc) > 0 {
39+
doc[0] = prefix + doc[0]
40+
return doc, true
41+
}
42+
43+
return doc, true
44+
}
45+
}
46+
return nil, false
47+
}

example/apis/org/operator/zz_generated.runtimedoc.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ DON'T EDIT THIS FILE
44
*/
55
package operator
66

7-
import _ "embed"
7+
func (v *GroupOrgs) RuntimeDoc(names ...string) ([]string, bool) {
8+
if len(names) > 0 {
9+
switch names[0] {
10+
}
11+
12+
return nil, false
13+
}
14+
return []string{}, true
15+
}
816

917
// nolint:deadcode,unused
1018
func runtimeDoc(v any, prefix string, names ...string) ([]string, bool) {
@@ -23,13 +31,3 @@ func runtimeDoc(v any, prefix string, names ...string) ([]string, bool) {
2331
}
2432
return nil, false
2533
}
26-
27-
func (v *GroupOrgs) RuntimeDoc(names ...string) ([]string, bool) {
28-
if len(names) > 0 {
29-
switch names[0] {
30-
}
31-
32-
return nil, false
33-
}
34-
return []string{}, true
35-
}

example/apis/org/zz_generated.runtimedoc.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,6 @@ DON'T EDIT THIS FILE
44
*/
55
package org
66

7-
import _ "embed"
8-
9-
// nolint:deadcode,unused
10-
func runtimeDoc(v any, prefix string, names ...string) ([]string, bool) {
11-
if c, ok := v.(interface {
12-
RuntimeDoc(names ...string) ([]string, bool)
13-
}); ok {
14-
doc, ok := c.RuntimeDoc(names...)
15-
if ok {
16-
if prefix != "" && len(doc) > 0 {
17-
doc[0] = prefix + doc[0]
18-
return doc, true
19-
}
20-
21-
return doc, true
22-
}
23-
}
24-
return nil, false
25-
}
26-
277
func (v *Cookie) RuntimeDoc(names ...string) ([]string, bool) {
288
if len(names) > 0 {
299
switch names[0] {
@@ -173,3 +153,21 @@ func (v *ListOrgOld) RuntimeDoc(names ...string) ([]string, bool) {
173153
"拉取组织列表",
174154
}, true
175155
}
156+
157+
// nolint:deadcode,unused
158+
func runtimeDoc(v any, prefix string, names ...string) ([]string, bool) {
159+
if c, ok := v.(interface {
160+
RuntimeDoc(names ...string) ([]string, bool)
161+
}); ok {
162+
doc, ok := c.RuntimeDoc(names...)
163+
if ok {
164+
if prefix != "" && len(doc) > 0 {
165+
doc[0] = prefix + doc[0]
166+
return doc, true
167+
}
168+
169+
return doc, true
170+
}
171+
}
172+
return nil, false
173+
}

example/apis/store/zz_generated.runtimedoc.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,6 @@ DON'T EDIT THIS FILE
44
*/
55
package store
66

7-
import _ "embed"
8-
9-
// nolint:deadcode,unused
10-
func runtimeDoc(v any, prefix string, names ...string) ([]string, bool) {
11-
if c, ok := v.(interface {
12-
RuntimeDoc(names ...string) ([]string, bool)
13-
}); ok {
14-
doc, ok := c.RuntimeDoc(names...)
15-
if ok {
16-
if prefix != "" && len(doc) > 0 {
17-
doc[0] = prefix + doc[0]
18-
return doc, true
19-
}
20-
21-
return doc, true
22-
}
23-
}
24-
return nil, false
25-
}
26-
277
func (v *GetStoreBlob) RuntimeDoc(names ...string) ([]string, bool) {
288
if len(names) > 0 {
299
switch names[0] {
@@ -57,3 +37,21 @@ func (v *UploadStoreBlob) RuntimeDoc(names ...string) ([]string, bool) {
5737
"上传 blob",
5838
}, true
5939
}
40+
41+
// nolint:deadcode,unused
42+
func runtimeDoc(v any, prefix string, names ...string) ([]string, bool) {
43+
if c, ok := v.(interface {
44+
RuntimeDoc(names ...string) ([]string, bool)
45+
}); ok {
46+
doc, ok := c.RuntimeDoc(names...)
47+
if ok {
48+
if prefix != "" && len(doc) > 0 {
49+
doc[0] = prefix + doc[0]
50+
return doc, true
51+
}
52+
53+
return doc, true
54+
}
55+
}
56+
return nil, false
57+
}

0 commit comments

Comments
 (0)