From 4c8a4c4184afc54e2b9c84171e2c522d8ee701fd Mon Sep 17 00:00:00 2001 From: bubbajoe Date: Sun, 14 Apr 2024 22:15:19 +0900 Subject: [PATCH] nobug: fix gofmt formatting --- internal/config/config.go | 6 +++--- internal/config/configtest/config.go | 1 - internal/config/store_config.go | 2 +- internal/pattern/pattern.go | 2 +- internal/proxy/proxy_transport/proxy_transport.go | 10 +++++----- pkg/cache/cache_test.go | 1 - pkg/modules/extractors/extractors_test.go | 4 ++-- pkg/modules/testutil/testutil.go | 2 +- pkg/modules/types/response_writer.go | 1 - pkg/resources/resource_manager_test.go | 2 +- pkg/spec/response_writer_tracker.go | 4 ++-- pkg/typescript/typescript.go | 1 + pkg/typescript/typescript_test.go | 2 +- pkg/util/hash.go | 2 +- pkg/util/http_response.go | 4 ++-- pkg/util/linker/linker_test.go | 1 - pkg/util/tree/avl/avl.go | 4 ++-- 17 files changed, 23 insertions(+), 26 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index ce6b320..df5a4ac 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -108,9 +108,9 @@ type ( DGateJWTAuthConfig struct { // HeaderName is the name of the header to extract the JWT token from - HeaderName string `koanf:"header_name"` - Algorithm string `koanf:"algorithm"` - SignatureConfig map[string]any `koanf:",remain"` + HeaderName string `koanf:"header_name"` + Algorithm string `koanf:"algorithm"` + SignatureConfig map[string]any `koanf:",remain"` } AsymmetricSignatureConfig struct { diff --git a/internal/config/configtest/config.go b/internal/config/configtest/config.go index 4c1210d..dff33e0 100644 --- a/internal/config/configtest/config.go +++ b/internal/config/configtest/config.go @@ -99,4 +99,3 @@ func NewTest2DGateConfig() *config.DGateConfig { }, } } - diff --git a/internal/config/store_config.go b/internal/config/store_config.go index d4e74a8..4e9a4b2 100644 --- a/internal/config/store_config.go +++ b/internal/config/store_config.go @@ -24,4 +24,4 @@ func StoreConfig[T any, C any](config C) (T, error) { } err = decoder.Decode(config) return output, err -} \ No newline at end of file +} diff --git a/internal/pattern/pattern.go b/internal/pattern/pattern.go index 8f88235..b43ba62 100644 --- a/internal/pattern/pattern.go +++ b/internal/pattern/pattern.go @@ -24,7 +24,7 @@ func PatternMatch(value, pattern string) (bool, error) { return strings.Contains(value, pattern[1:len(pattern)-1]), nil } else if asteriskPrefix { return strings.HasSuffix(value, pattern[1:]), nil - } else if asteriskSuffix{ + } else if asteriskSuffix { return strings.HasPrefix(value, pattern[:len(pattern)-1]), nil } else if strings.HasPrefix(pattern, "/") && strings.HasSuffix(pattern, "/") { re := pattern[1 : len(pattern)-1] diff --git a/internal/proxy/proxy_transport/proxy_transport.go b/internal/proxy/proxy_transport/proxy_transport.go index 56a7da6..3f1932c 100644 --- a/internal/proxy/proxy_transport/proxy_transport.go +++ b/internal/proxy/proxy_transport/proxy_transport.go @@ -52,10 +52,10 @@ func (b *proxyTransportBuilder) RetryTimeout(retryTimeout time.Duration) Builder func (b *proxyTransportBuilder) Clone() Builder { return &proxyTransportBuilder{ - transport: b.transport, + transport: b.transport, requestTimeout: b.requestTimeout, - retries: b.retries, - retryTimeout: b.requestTimeout, + retries: b.retries, + retryTimeout: b.requestTimeout, } } @@ -101,8 +101,8 @@ func (m *retryRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) return m.transport.RoundTrip(req) } var ( - resp *http.Response - err error + resp *http.Response + err error // retryTimeoutChan <-chan time.Time ) // if m.retryTimeout != 0 { diff --git a/pkg/cache/cache_test.go b/pkg/cache/cache_test.go index 196b62d..13fbb14 100644 --- a/pkg/cache/cache_test.go +++ b/pkg/cache/cache_test.go @@ -103,7 +103,6 @@ func TestCache_MaxItems_Overwrite(t *testing.T) { assert.True(t, ok, "expected key to be found") assert.Equal(t, 1, n, "expected value to be 1, got %d", n) - c.Bucket("test").SetWithTTL("key", 2, time.Millisecond*100) n, ok = c.Bucket("test").Get("key") assert.True(t, ok, "expected key to be found") diff --git a/pkg/modules/extractors/extractors_test.go b/pkg/modules/extractors/extractors_test.go index 69fe0d3..1a73eac 100644 --- a/pkg/modules/extractors/extractors_test.go +++ b/pkg/modules/extractors/extractors_test.go @@ -185,7 +185,7 @@ func TestExportedPromiseErrors(t *testing.T) { if err != nil { t.Fatal(err) } - + rt := loop.Start() defer loop.Stop() @@ -208,7 +208,7 @@ func TestExportedPromiseErrors(t *testing.T) { if err != nil { t.Fatal(err) } - + callable, ok = goja.AssertFunction(v) if !assert.True(t, ok) { return diff --git a/pkg/modules/testutil/testutil.go b/pkg/modules/testutil/testutil.go index a0addf3..97a97cf 100644 --- a/pkg/modules/testutil/testutil.go +++ b/pkg/modules/testutil/testutil.go @@ -21,7 +21,7 @@ type mockRuntimeContext struct { mock.Mock smap *sync.Map ctx context.Context - req *require.Registry + req *require.Registry loop *eventloop.EventLoop data any state modules.StateManager diff --git a/pkg/modules/types/response_writer.go b/pkg/modules/types/response_writer.go index 8e8c5ba..bfe197c 100644 --- a/pkg/modules/types/response_writer.go +++ b/pkg/modules/types/response_writer.go @@ -137,4 +137,3 @@ func (g *ResponseWriterWrapper) Cookie() []*http.Cookie { func (g *ResponseWriterWrapper) Header() http.Header { return g.rw.Header() } - diff --git a/pkg/resources/resource_manager_test.go b/pkg/resources/resource_manager_test.go index 125d929..380b04c 100644 --- a/pkg/resources/resource_manager_test.go +++ b/pkg/resources/resource_manager_test.go @@ -582,7 +582,7 @@ func BenchmarkRM_ReadingWriting(b *testing.B) { Paths: []string{"/"}, Methods: []string{"GET"}, Modules: []string{""}, - Tags: []string{"test"}, + Tags: []string{"test"}, } for i := 0; pb.Next(); i++ { rt.Name = "test" + strconv.Itoa(i%routeSize) diff --git a/pkg/spec/response_writer_tracker.go b/pkg/spec/response_writer_tracker.go index 2cb622a..b33857d 100644 --- a/pkg/spec/response_writer_tracker.go +++ b/pkg/spec/response_writer_tracker.go @@ -12,8 +12,8 @@ type ResponseWriterTracker interface { } type rwTracker struct { - rw http.ResponseWriter - status int + rw http.ResponseWriter + status int bytesWritten int64 } diff --git a/pkg/typescript/typescript.go b/pkg/typescript/typescript.go index f549ae1..e24c28e 100644 --- a/pkg/typescript/typescript.go +++ b/pkg/typescript/typescript.go @@ -8,6 +8,7 @@ import ( ) // typescript v5.3.3 +// //go:embed typescript.min.js var tscSource string diff --git a/pkg/typescript/typescript_test.go b/pkg/typescript/typescript_test.go index 7769477..88f1c27 100644 --- a/pkg/typescript/typescript_test.go +++ b/pkg/typescript/typescript_test.go @@ -8,7 +8,7 @@ import ( "github.com/dop251/goja" ) -// TOOD: add more test cases for errors to ensure the line numbers are correct +// TODO: add more test cases for errors to ensure the line numbers are correct // and the error messages are correct; also wrap code in a function and test. func TestTranspile(t *testing.T) { diff --git a/pkg/util/hash.go b/pkg/util/hash.go index 8237179..d7f1b62 100644 --- a/pkg/util/hash.go +++ b/pkg/util/hash.go @@ -8,6 +8,7 @@ import ( "hash" "hash/crc32" ) + func jsonHash(objs ...any) (hash.Hash32, error) { hash, err := crc32Hash(func(a any) []byte { b, err := json.Marshal(a) @@ -29,7 +30,6 @@ func JsonHash(objs ...any) (uint32, error) { return hash.Sum32(), nil } - func JsonHashBytes(objs ...any) ([]byte, error) { hash, err := jsonHash(objs...) if err != nil { diff --git a/pkg/util/http_response.go b/pkg/util/http_response.go index a96532b..1f6896f 100644 --- a/pkg/util/http_response.go +++ b/pkg/util/http_response.go @@ -23,7 +23,7 @@ func JsonResponse(w http.ResponseWriter, statusCode int, data any) { } responseData := map[string]any{ "status_code": statusCode, - "data": data, + "data": data, } if isSlice(data) { responseData["count"] = sliceLen(data) @@ -40,7 +40,7 @@ func JsonError[T any](w http.ResponseWriter, statusCode int, message T) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(statusCode) json.NewEncoder(w).Encode(map[string]any{ - "error": message, + "error": message, "status": statusCode, }) } diff --git a/pkg/util/linker/linker_test.go b/pkg/util/linker/linker_test.go index 8df45ad..f875ae3 100644 --- a/pkg/util/linker/linker_test.go +++ b/pkg/util/linker/linker_test.go @@ -27,7 +27,6 @@ func TestLinkerTests(t *testing.T) { linker3.LinkOneMany("bottom", "l3bottom", linker2) linker2.LinkOneMany("bottom", "l2bottom", linker1) - assert.True(t, linker1.Len("top") == 1) assert.True(t, linker2.Len("top") == 1) assert.True(t, linker3.Len("top") == 1) diff --git a/pkg/util/tree/avl/avl.go b/pkg/util/tree/avl/avl.go index c75291b..9705666 100644 --- a/pkg/util/tree/avl/avl.go +++ b/pkg/util/tree/avl/avl.go @@ -165,8 +165,8 @@ func replace[K cmp.Ordered, V any](root *node[K, V], key K, value V) (*node[K, V var oldValue V if root == nil { return &node[K, V]{ - key: key, - val: value, + key: key, + val: value, height: 1, }, oldValue }