Skip to content

Commit

Permalink
Set up staticcheck linter for BFF
Browse files Browse the repository at this point in the history
Signed-off-by: Griffin-Sullivan <[email protected]>
  • Loading branch information
Griffin-Sullivan committed Sep 11, 2024
1 parent 533d260 commit 13595a3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ui-bff-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions clients/ui/bff/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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} .
13 changes: 7 additions & 6 deletions clients/ui/bff/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions clients/ui/bff/api/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions clients/ui/bff/api/registered_models_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions clients/ui/bff/staticcheck.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
checks = ["all", "-U1000", "-ST1000"]

0 comments on commit 13595a3

Please sign in to comment.