diff --git a/.github/workflows/ui-bff-build.yml b/.github/workflows/ui-bff-build.yml index 3957f5b3..56cbe0d1 100644 --- a/.github/workflows/ui-bff-build.yml +++ b/.github/workflows/ui-bff-build.yml @@ -24,6 +24,12 @@ jobs: working-directory: clients/ui/bff run: make clean + - name: Run linter + working-directory: clients/ui/bff + uses: dominikh/staticcheck-action@v1 + with: + version: "latest" + - name: Build working-directory: clients/ui/bff run: make build diff --git a/clients/ui/bff/Makefile b/clients/ui/bff/Makefile index 36da91c5..f30b8f1a 100644 --- a/clients/ui/bff/Makefile +++ b/clients/ui/bff/Makefile @@ -34,6 +34,10 @@ build: fmt vet test run: fmt vet go run ./cmd/main.go --port=$(PORT) --mock-k8s-client=$(MOCK_K8S_CLIENT) +.PHONY: lint +lint: + staticcheck ./... + .PHONY: docker-build docker-build: $(CONTAINER_TOOL) build -t ${IMG} . diff --git a/clients/ui/bff/api/app.go b/clients/ui/bff/api/app.go index 603d7439..890913a9 100644 --- a/clients/ui/bff/api/app.go +++ b/clients/ui/bff/api/app.go @@ -2,24 +2,25 @@ package api import ( "fmt" + "log/slog" + "net/http" + "github.com/julienschmidt/httprouter" "github.com/kubeflow/model-registry/ui/bff/config" "github.com/kubeflow/model-registry/ui/bff/data" "github.com/kubeflow/model-registry/ui/bff/integrations" "github.com/kubeflow/model-registry/ui/bff/internals/mocks" - "log/slog" - "net/http" ) const ( Version = "1.0.0" PathPrefix = "/api/v1" - ModelRegistryId = "model_registry_id" - RegisteredModelId = "registered_model_id" + ModelRegistryID = "model_registry_id" + RegisteredModelID = "registered_model_id" HealthCheckPath = PathPrefix + "/healthcheck" ModelRegistry = PathPrefix + "/model-registry" - RegisteredModelsPath = ModelRegistry + "/:" + ModelRegistryId + "/registered_models" - RegisteredModelPath = RegisteredModelsPath + "/:" + RegisteredModelId + RegisteredModelsPath = ModelRegistry + "/:" + ModelRegistryID + "/registered_models" + RegisteredModelPath = RegisteredModelsPath + "/:" + RegisteredModelID ) type App struct { diff --git a/clients/ui/bff/api/middleware.go b/clients/ui/bff/api/middleware.go index b7d0385b..ca12b2e2 100644 --- a/clients/ui/bff/api/middleware.go +++ b/clients/ui/bff/api/middleware.go @@ -3,10 +3,11 @@ package api import ( "context" "fmt" + "net/http" + "github.com/julienschmidt/httprouter" "github.com/kubeflow/model-registry/ui/bff/integrations" "k8s.io/client-go/rest" - "net/http" ) type contextKey string @@ -39,7 +40,7 @@ func (app *App) enableCORS(next http.Handler) http.Handler { func (app *App) AttachRESTClient(handler func(http.ResponseWriter, *http.Request, httprouter.Params)) httprouter.Handle { return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { - modelRegistryID := ps.ByName(ModelRegistryId) + modelRegistryID := ps.ByName(ModelRegistryID) modelRegistryBaseURL, err := resolveModelRegistryURL(modelRegistryID, app.kubernetesClient) if err != nil { diff --git a/clients/ui/bff/api/registered_models_handler.go b/clients/ui/bff/api/registered_models_handler.go index 9e5f768b..42e93047 100644 --- a/clients/ui/bff/api/registered_models_handler.go +++ b/clients/ui/bff/api/registered_models_handler.go @@ -4,12 +4,13 @@ import ( "encoding/json" "errors" "fmt" + "net/http" + "github.com/julienschmidt/httprouter" "github.com/kubeflow/model-registry/pkg/openapi" "github.com/kubeflow/model-registry/ui/bff/data" "github.com/kubeflow/model-registry/ui/bff/integrations" "github.com/kubeflow/model-registry/ui/bff/validation" - "net/http" ) func (app *App) GetRegisteredModelsHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { @@ -91,7 +92,7 @@ func (app *App) GetRegisteredModelHandler(w http.ResponseWriter, r *http.Request return } - model, err := data.GetRegisteredModel(client, ps.ByName(RegisteredModelId)) + model, err := data.GetRegisteredModel(client, ps.ByName(RegisteredModelID)) if err != nil { app.serverErrorResponse(w, r, err) return diff --git a/clients/ui/bff/staticcheck.conf b/clients/ui/bff/staticcheck.conf new file mode 100644 index 00000000..4462f30c --- /dev/null +++ b/clients/ui/bff/staticcheck.conf @@ -0,0 +1 @@ +checks = ["all", "-U1000", "-ST1000"] \ No newline at end of file