Skip to content

Commit f4fbee3

Browse files
fix: lint changes
1 parent fb094fc commit f4fbee3

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

rolling-shutter/keyper/kproapi/middleware.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,32 @@ import (
77
"github.com/getkin/kin-openapi/openapi3"
88
)
99

10-
// isReadOnlyEndpoint checks if an endpoint is marked as read-only in the OpenAPI spec
10+
// isReadOnlyEndpoint checks if an endpoint is marked as read-only in the OpenAPI spec.
1111
func isReadOnlyEndpoint(operation *openapi3.Operation) bool {
12-
// Try to get the value directly from the map first
12+
// Try to get the value directly from the map first.
1313
if val, exists := operation.Extensions["x-read-only"]; exists {
14-
// Handle json.RawMessage case
14+
// Handle json.RawMessage case.
1515
if rawMsg, ok := val.(json.RawMessage); ok {
1616
return string(rawMsg) == "true"
1717
}
1818

19-
// Handle direct boolean case
19+
// Handle direct boolean case.
2020
if boolVal, ok := val.(bool); ok {
2121
return boolVal
2222
}
2323
}
2424
return false
2525
}
2626

27-
// shouldEnableEndpoint determines if an endpoint should be accessible based on its type and configuration
27+
// shouldEnableEndpoint determines if an endpoint should be accessible based on its type and configuration.
2828
func shouldEnableEndpoint(operation *openapi3.Operation, enableWriteOperations bool) bool {
2929
if isReadOnlyEndpoint(operation) {
3030
return true
3131
}
3232
return enableWriteOperations
3333
}
3434

35-
// findOperation looks up the OpenAPI operation for the given path and method
35+
// findOperation looks up the OpenAPI operation for the given path and method.
3636
func findOperation(spec *openapi3.T, path string, method string) *openapi3.Operation {
3737
pathItem := spec.Paths.Find(path)
3838
if pathItem == nil {
@@ -53,31 +53,31 @@ func findOperation(spec *openapi3.T, path string, method string) *openapi3.Opera
5353
}
5454
}
5555

56-
// ConfigMiddleware creates a middleware that controls endpoint access based on configuration
56+
// ConfigMiddleware creates a middleware that controls endpoint access based on configuration.
5757
func ConfigMiddleware(enableWriteOperations bool) MiddlewareFunc {
5858
return ConfigMiddlewareWithSpec(enableWriteOperations, GetSwagger)
5959
}
6060

61-
// ConfigMiddlewareWithSpec creates a middleware that controls endpoint access based on configuration
62-
// This accepts a function to get the spec, making it more testable
61+
// ConfigMiddlewareWithSpec creates a middleware that controls endpoint access based on configuration.
62+
// This accepts a function to get the spec, making it more testable.
6363
func ConfigMiddlewareWithSpec(enableWriteOperations bool, getSpec func() (*openapi3.T, error)) MiddlewareFunc {
6464
return func(next http.Handler) http.Handler {
6565
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
66-
// Load the OpenAPI specification
66+
// Load the OpenAPI specification.
6767
spec, err := getSpec()
6868
if err != nil {
6969
http.Error(w, "Internal server error", http.StatusInternalServerError)
7070
return
7171
}
7272

73-
// Find the operation for this request
73+
// Find the operation for this request.
7474
operation := findOperation(spec, r.URL.Path, r.Method)
7575
if operation == nil {
7676
http.Error(w, "Endpoint not found", http.StatusNotFound)
7777
return
7878
}
7979

80-
// Check if the endpoint should be accessible
80+
// Check if the endpoint should be accessible.
8181
if !shouldEnableEndpoint(operation, enableWriteOperations) {
8282
http.Error(w, "Endpoint not enabled", http.StatusForbidden)
8383
return

rolling-shutter/keyper/kproapi/middleware_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ func TestConfigMiddleware(t *testing.T) {
201201
},
202202
}
203203

204-
// Create a function that returns our test spec
204+
// Create a function that returns our test spec.
205+
//nolint:golint
205206
getTestSpec := func() (*openapi3.T, error) {
206207
return spec, nil
207208
}
@@ -245,8 +246,8 @@ func TestConfigMiddleware(t *testing.T) {
245246

246247
for _, tt := range tests {
247248
t.Run(tt.name, func(t *testing.T) {
248-
// Create a test handler that always returns 200 OK
249-
nextHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
249+
// Create a test handler that always returns 200 OK.
250+
nextHandler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
250251
w.WriteHeader(http.StatusOK)
251252
})
252253

@@ -255,7 +256,7 @@ func TestConfigMiddleware(t *testing.T) {
255256
handler := middleware(nextHandler)
256257

257258
// Create a test request
258-
req := httptest.NewRequest(tt.method, tt.path, nil)
259+
req := httptest.NewRequest(tt.method, tt.path, http.NoBody)
259260
w := httptest.NewRecorder()
260261

261262
// Serve the request

0 commit comments

Comments
 (0)