Skip to content

Commit f3dce5e

Browse files
committed
feat: r
Signed-off-by: ashing <[email protected]>
1 parent e20ef15 commit f3dce5e

File tree

17 files changed

+69
-63
lines changed

17 files changed

+69
-63
lines changed

Makefile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
254254
$(GOLANGCI_LINT): $(LOCALBIN)
255255
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
256256

257+
gofmt: ## Apply go fmt
258+
@gofmt -w -r 'interface{} -> any' .
259+
@gofmt -w -r 'ginkgo.FIt -> ginkgo.It' test
260+
@gofmt -w -r 'ginkgo.FContext -> ginkgo.Context' test
261+
@gofmt -w -r 'ginkgo.FDescribe -> ginkgo.Describe' test
262+
@gofmt -w -r 'ginkgo.FDescribeTable -> ginkgo.DescribeTable' test
263+
@go fmt ./...
264+
.PHONY: gofmt
265+
257266
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
258267
# $1 - target path with name of binary
259268
# $2 - package url which can be installed
@@ -269,6 +278,3 @@ mv $(1) $(1)-$(3) ;\
269278
} ;\
270279
ln -sf $(1)-$(3) $(1)
271280
endef
272-
273-
274-

api/dashboard/v1/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func (s *StringOrSlice) UnmarshalJSON(p []byte) error {
237237
return err
238238
}
239239

240-
type Plugins map[string]interface{}
240+
type Plugins map[string]any
241241

242242
func (p *Plugins) DeepCopyInto(out *Plugins) {
243243
b, _ := json.Marshal(&p)

pkg/dashboard/cache/cache.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ type Cache interface {
5757
GetPluginConfig(string) (*v1.PluginConfig, error)
5858

5959
// ListRoutes lists all routes in cache.
60-
ListRoutes(...interface{}) ([]*v1.Route, error)
60+
ListRoutes(...any) ([]*v1.Route, error)
6161
// ListStreamRoutes lists all stream_route objects in cache.
6262
ListStreamRoutes() ([]*v1.StreamRoute, error)
6363
// ListSSL lists all ssl objects in cache.
64-
ListSSL(...interface{}) ([]*v1.Ssl, error)
64+
ListSSL(...any) ([]*v1.Ssl, error)
6565
// ListUpstreams lists all upstreams in cache.
66-
ListServices(...interface{}) ([]*v1.Service, error)
66+
ListServices(...any) ([]*v1.Service, error)
6767
// ListGlobalRules lists all global_rule objects in cache.
6868
ListGlobalRules() ([]*v1.GlobalRule, error)
6969
// ListConsumers lists all consumer objects in cache.

pkg/dashboard/cache/memdb.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (c *dbCache) InsertPluginConfig(pc *v1.PluginConfig) error {
7777
return c.insert("plugin_config", pc.DeepCopy())
7878
}
7979

80-
func (c *dbCache) insert(table string, obj interface{}) error {
80+
func (c *dbCache) insert(table string, obj any) error {
8181
txn := c.db.Txn(true)
8282
defer txn.Abort()
8383
if err := txn.Insert(table, obj); err != nil {
@@ -151,7 +151,7 @@ func (c *dbCache) GetPluginConfig(name string) (*v1.PluginConfig, error) {
151151
return obj.(*v1.PluginConfig).DeepCopy(), nil
152152
}
153153

154-
func (c *dbCache) get(table, id string) (interface{}, error) {
154+
func (c *dbCache) get(table, id string) (any, error) {
155155
txn := c.db.Txn(false)
156156
defer txn.Abort()
157157
obj, err := txn.First(table, "id", id)
@@ -167,7 +167,7 @@ func (c *dbCache) get(table, id string) (interface{}, error) {
167167
return obj, nil
168168
}
169169

170-
func (c *dbCache) ListRoutes(args ...interface{}) ([]*v1.Route, error) {
170+
func (c *dbCache) ListRoutes(args ...any) ([]*v1.Route, error) {
171171
raws, err := c.list("route", args...)
172172
if err != nil {
173173
return nil, err
@@ -179,7 +179,7 @@ func (c *dbCache) ListRoutes(args ...interface{}) ([]*v1.Route, error) {
179179
return routes, nil
180180
}
181181

182-
func (c *dbCache) ListSSL(args ...interface{}) ([]*v1.Ssl, error) {
182+
func (c *dbCache) ListSSL(args ...any) ([]*v1.Ssl, error) {
183183
raws, err := c.list("ssl", args...)
184184
if err != nil {
185185
return nil, err
@@ -191,7 +191,7 @@ func (c *dbCache) ListSSL(args ...interface{}) ([]*v1.Ssl, error) {
191191
return ssl, nil
192192
}
193193

194-
func (c *dbCache) ListServices(args ...interface{}) ([]*v1.Service, error) {
194+
func (c *dbCache) ListServices(args ...any) ([]*v1.Service, error) {
195195
raws, err := c.list("service", args...)
196196
if err != nil {
197197
return nil, err
@@ -263,7 +263,7 @@ func (c *dbCache) ListPluginConfigs() ([]*v1.PluginConfig, error) {
263263
return pluginConfigs, nil
264264
}
265265

266-
func (c *dbCache) list(table string, args ...interface{}) ([]interface{}, error) {
266+
func (c *dbCache) list(table string, args ...any) ([]any, error) {
267267
txn := c.db.Txn(false)
268268
defer txn.Abort()
269269
index := "id"
@@ -279,7 +279,7 @@ func (c *dbCache) list(table string, args ...interface{}) ([]interface{}, error)
279279
if err != nil {
280280
return nil, err
281281
}
282-
var objs []interface{}
282+
var objs []any
283283
for obj := iter.Next(); obj != nil; obj = iter.Next() {
284284
objs = append(objs, obj)
285285
}
@@ -324,7 +324,7 @@ func (c *dbCache) DeletePluginConfig(pc *v1.PluginConfig) error {
324324
return c.delete("plugin_config", pc)
325325
}
326326

327-
func (c *dbCache) delete(table string, obj interface{}) error {
327+
func (c *dbCache) delete(table string, obj any) error {
328328
txn := c.db.Txn(true)
329329
defer txn.Abort()
330330
if err := txn.Delete(table, obj); err != nil {

pkg/dashboard/cache/noop_db.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ func (c *noopCache) GetPluginConfig(name string) (*v1.PluginConfig, error) {
7676
return nil, nil
7777
}
7878

79-
func (c *noopCache) ListRoutes(...interface{}) ([]*v1.Route, error) {
79+
func (c *noopCache) ListRoutes(...any) ([]*v1.Route, error) {
8080
return nil, nil
8181
}
8282

83-
func (c *noopCache) ListSSL(...interface{}) ([]*v1.Ssl, error) {
83+
func (c *noopCache) ListSSL(...any) ([]*v1.Ssl, error) {
8484
return nil, nil
8585
}
8686

87-
func (c *noopCache) ListServices(...interface{}) ([]*v1.Service, error) {
87+
func (c *noopCache) ListServices(...any) ([]*v1.Service, error) {
8888
return nil, nil
8989
}
9090

pkg/dashboard/cache/schema.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var (
5858
AllowMissing: true,
5959
Indexer: &LabelIndexer{
6060
LabelKeys: []string{"kind", "namespace", "name"},
61-
GetLabels: func(obj interface{}) map[string]string {
61+
GetLabels: func(obj any) map[string]string {
6262
service, ok := obj.(*v1.Route)
6363
if !ok {
6464
return nil
@@ -89,7 +89,7 @@ var (
8989
AllowMissing: true,
9090
Indexer: &LabelIndexer{
9191
LabelKeys: []string{"kind", "namespace", "name"},
92-
GetLabels: func(obj interface{}) map[string]string {
92+
GetLabels: func(obj any) map[string]string {
9393
service, ok := obj.(*v1.Service)
9494
if !ok {
9595
return nil
@@ -189,10 +189,10 @@ var (
189189
// LabelIndexer is a custom indexer for exact match indexing
190190
type LabelIndexer struct {
191191
LabelKeys []string
192-
GetLabels func(interface{}) map[string]string
192+
GetLabels func(any) map[string]string
193193
}
194194

195-
func (emi *LabelIndexer) FromObject(obj interface{}) (bool, []byte, error) {
195+
func (emi *LabelIndexer) FromObject(obj any) (bool, []byte, error) {
196196
labels := emi.GetLabels(obj)
197197
var labelValues []string
198198
for _, key := range emi.LabelKeys {
@@ -208,7 +208,7 @@ func (emi *LabelIndexer) FromObject(obj interface{}) (bool, []byte, error) {
208208
return true, []byte(strings.Join(labelValues, "/")), nil
209209
}
210210

211-
func (emi *LabelIndexer) FromArgs(args ...interface{}) ([]byte, error) {
211+
func (emi *LabelIndexer) FromArgs(args ...any) ([]byte, error) {
212212
if len(args) != len(emi.LabelKeys) {
213213
return nil, fmt.Errorf("expected %d arguments, got %d", len(emi.LabelKeys), len(args))
214214
}

pkg/dashboard/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ func (c *cluster) getList(ctx context.Context, url, resource string) ([]string,
793793
}
794794
return listResponse, nil
795795
}
796-
var listResponse map[string]interface{}
796+
var listResponse map[string]any
797797
dec := json.NewDecoder(resp.Body)
798798
if err := dec.Decode(&listResponse); err != nil {
799799
return nil, err

pkg/dashboard/consumer_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ import (
3131
)
3232

3333
type fakeAPISIXConsumerSrv struct {
34-
consumer map[string]map[string]interface{}
34+
consumer map[string]map[string]any
3535
}
3636

37-
type Value map[string]interface{}
37+
type Value map[string]any
3838

3939
type fakeListResp struct {
4040
Total string `json:"total"`
@@ -110,7 +110,7 @@ func (srv *fakeAPISIXConsumerSrv) ServeHTTP(w http.ResponseWriter, r *http.Reque
110110
key := fmt.Sprintf("/apisix/admin/consumers/%s", paths[len(paths)-1])
111111
data, _ := io.ReadAll(r.Body)
112112
w.WriteHeader(http.StatusCreated)
113-
consumer := make(map[string]interface{}, 0)
113+
consumer := make(map[string]any, 0)
114114
_ = json.Unmarshal(data, &consumer)
115115
srv.consumer[key] = consumer
116116
var val Value
@@ -137,7 +137,7 @@ func (srv *fakeAPISIXConsumerSrv) ServeHTTP(w http.ResponseWriter, r *http.Reque
137137
data, _ := io.ReadAll(r.Body)
138138
var val Value
139139
_ = json.Unmarshal(data, &val)
140-
consumer := make(map[string]interface{}, 0)
140+
consumer := make(map[string]any, 0)
141141
_ = json.Unmarshal(data, &consumer)
142142
srv.consumer[id] = consumer
143143
w.WriteHeader(http.StatusOK)
@@ -155,7 +155,7 @@ func (srv *fakeAPISIXConsumerSrv) ServeHTTP(w http.ResponseWriter, r *http.Reque
155155

156156
func runFakeConsumerSrv(t *testing.T) *http.Server {
157157
srv := &fakeAPISIXConsumerSrv{
158-
consumer: make(map[string]map[string]interface{}),
158+
consumer: make(map[string]map[string]any),
159159
}
160160

161161
ln, _ := nettest.NewLocalListener("tcp")
@@ -227,7 +227,7 @@ func TestConsumerClient(t *testing.T) {
227227
// Patch then List
228228
_, err = cli.Update(context.Background(), &v1.Consumer{
229229
Username: "2",
230-
Plugins: map[string]interface{}{
230+
Plugins: map[string]any{
231231
"prometheus": struct{}{},
232232
},
233233
})

pkg/dashboard/dashboard.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type Cluster interface {
7272
// list and delete for APISIX Route resource.
7373
type Route interface {
7474
Get(ctx context.Context, name string) (*v1.Route, error)
75-
List(ctx context.Context, args ...interface{}) ([]*v1.Route, error)
75+
List(ctx context.Context, args ...any) ([]*v1.Route, error)
7676
Create(ctx context.Context, route *v1.Route) (*v1.Route, error)
7777
Delete(ctx context.Context, route *v1.Route) error
7878
Update(ctx context.Context, route *v1.Route) (*v1.Route, error)
@@ -83,7 +83,7 @@ type Route interface {
8383
type SSL interface {
8484
// name is namespace_sslname
8585
Get(ctx context.Context, name string) (*v1.Ssl, error)
86-
List(ctx context.Context, args ...interface{}) ([]*v1.Ssl, error)
86+
List(ctx context.Context, args ...any) ([]*v1.Ssl, error)
8787
Create(ctx context.Context, ssl *v1.Ssl) (*v1.Ssl, error)
8888
Delete(ctx context.Context, ssl *v1.Ssl) error
8989
Update(ctx context.Context, ssl *v1.Ssl) (*v1.Ssl, error)
@@ -93,7 +93,7 @@ type SSL interface {
9393
// list and delete for APISIX Upstream resource.
9494
type Service interface {
9595
Get(ctx context.Context, name string) (*v1.Service, error)
96-
List(ctx context.Context, args ...interface{}) ([]*v1.Service, error)
96+
List(ctx context.Context, args ...any) ([]*v1.Service, error)
9797
Create(ctx context.Context, svc *v1.Service) (*v1.Service, error)
9898
Delete(ctx context.Context, svc *v1.Service) error
9999
Update(ctx context.Context, svc *v1.Service) (*v1.Service, error)

pkg/dashboard/nonexistentclient.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (f *dummyRoute) Get(_ context.Context, _ string) (*v1.Route, error) {
6363
return nil, ErrClusterNotExist
6464
}
6565

66-
func (f *dummyRoute) List(_ context.Context, _ ...interface{}) ([]*v1.Route, error) {
66+
func (f *dummyRoute) List(_ context.Context, _ ...any) ([]*v1.Route, error) {
6767
return nil, ErrClusterNotExist
6868
}
6969

@@ -85,7 +85,7 @@ func (f *dummySSL) Get(_ context.Context, _ string) (*v1.Ssl, error) {
8585
return nil, ErrClusterNotExist
8686
}
8787

88-
func (f *dummySSL) List(_ context.Context, _ ...interface{}) ([]*v1.Ssl, error) {
88+
func (f *dummySSL) List(_ context.Context, _ ...any) ([]*v1.Ssl, error) {
8989
return nil, ErrClusterNotExist
9090
}
9191

@@ -107,7 +107,7 @@ func (f *dummyService) Get(_ context.Context, _ string) (*v1.Service, error) {
107107
return nil, ErrClusterNotExist
108108
}
109109

110-
func (f *dummyService) List(_ context.Context, _ ...interface{}) ([]*v1.Service, error) {
110+
func (f *dummyService) List(_ context.Context, _ ...any) ([]*v1.Service, error) {
111111
return nil, ErrClusterNotExist
112112
}
113113

@@ -355,14 +355,14 @@ func (c *dummyCache) GetPluginConfig(_ string) (*v1.PluginConfig, error) {
355355
return nil, cache.ErrNotFound
356356
}
357357

358-
func (c *dummyCache) ListRoutes(...interface{}) ([]*v1.Route, error) { return nil, nil }
359-
func (c *dummyCache) ListSSL(_ ...interface{}) ([]*v1.Ssl, error) { return nil, nil }
360-
func (c *dummyCache) ListServices(...interface{}) ([]*v1.Service, error) { return nil, nil }
361-
func (c *dummyCache) ListStreamRoutes() ([]*v1.StreamRoute, error) { return nil, nil }
362-
func (c *dummyCache) ListGlobalRules() ([]*v1.GlobalRule, error) { return nil, nil }
363-
func (c *dummyCache) ListConsumers() ([]*v1.Consumer, error) { return nil, nil }
364-
func (c *dummyCache) ListSchema() ([]*v1.Schema, error) { return nil, nil }
365-
func (c *dummyCache) ListPluginConfigs() ([]*v1.PluginConfig, error) { return nil, nil }
358+
func (c *dummyCache) ListRoutes(...any) ([]*v1.Route, error) { return nil, nil }
359+
func (c *dummyCache) ListSSL(_ ...any) ([]*v1.Ssl, error) { return nil, nil }
360+
func (c *dummyCache) ListServices(...any) ([]*v1.Service, error) { return nil, nil }
361+
func (c *dummyCache) ListStreamRoutes() ([]*v1.StreamRoute, error) { return nil, nil }
362+
func (c *dummyCache) ListGlobalRules() ([]*v1.GlobalRule, error) { return nil, nil }
363+
func (c *dummyCache) ListConsumers() ([]*v1.Consumer, error) { return nil, nil }
364+
func (c *dummyCache) ListSchema() ([]*v1.Schema, error) { return nil, nil }
365+
func (c *dummyCache) ListPluginConfigs() ([]*v1.PluginConfig, error) { return nil, nil }
366366

367367
func (c *dummyCache) DeleteRoute(_ *v1.Route) error { return nil }
368368
func (c *dummyCache) DeleteSSL(_ *v1.Ssl) error { return nil }

0 commit comments

Comments
 (0)