Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Recoverer middleware #195

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ name: Build
on:
push:
branches:
- 'main'
- "main"
pull_request:
paths-ignore:
- 'LICENSE*'
- 'DOCKERFILE*'
- '**.gitignore'
- '**.md'
- '**.txt'
- '.github/ISSUE_TEMPLATE/**'
- '.github/dependabot.yml'
- 'docs/**'
- 'scripts/**'
- "LICENSE*"
- "DOCKERFILE*"
- "**.gitignore"
- "**.md"
- "**.txt"
- ".github/ISSUE_TEMPLATE/**"
- ".github/dependabot.yml"
- "docs/**"
- "scripts/**"
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -22,7 +22,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: "1.21"
- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
Expand All @@ -37,7 +37,7 @@ jobs:
- name: Clean
run: make clean
- name: Build
run: make build
run: FORCE_SERVER_GENERATION=1 make build
- name: Check if there are uncommitted file changes
run: |
clean=$(git status --porcelain)
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ openapi/validate: bin/openapi-generator-cli
.PHONY: gen/openapi-server
gen/openapi-server: bin/openapi-generator-cli openapi/validate
@if git diff --exit-code --name-only | grep -q "api/openapi/model-registry.yaml" || \
git diff --exit-code --name-only | grep -q "api/openapi/model-registry.yaml" || \
Comment on lines 80 to -81
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the pipeline builds the server upon a committed version, the server is never checked.
It seems we have also forgotten to update it some time ago, I wonder if there's a better way to test this?

[ -n "${FORCE_SERVER_GENERATION}" ]; then \
ROOT_FOLDER="." ./scripts/gen_openapi_server.sh; \
else \
Expand Down
11 changes: 6 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"errors"
"flag"
"fmt"
"github.com/golang/glog"
"github.com/spf13/pflag"
"os"
"strings"

"github.com/golang/glog"
"github.com/spf13/pflag"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -46,7 +47,7 @@ func Execute() {
}

func init() {
//cobra.OnInitialize(initConfig)
// cobra.OnInitialize(initConfig)

// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
Expand All @@ -61,7 +62,7 @@ func init() {

// Cobra also supports local flags, which will only run
// when this action is called directly.
//rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

}

Expand Down Expand Up @@ -94,7 +95,7 @@ func initConfig(cmd *cobra.Command) error {
var configFileNotFoundError viper.ConfigFileNotFoundError
ok := errors.As(err, &configFileNotFoundError)
// ignore if it's a file not found error for default config file
if !(cfgFile == "" && ok) {
if cfgFile != "" || !ok {
return fmt.Errorf("reading config %s: %v", viper.ConfigFileUsed(), err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/converter/openapi_mlmd_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
type OpenAPIModelWrapper[
M OpenAPIModel,
] struct {
TypeId int64
Model *M
ParentResourceId *string // optional parent id
ModelName *string // optional registered model name
ParentResourceId *string
ModelName *string
TypeId int64
}

// goverter:converter
Expand Down
9 changes: 6 additions & 3 deletions internal/server/openapi/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ type Router interface {
Routes() Routes
}

const errMsgRequiredMissing = "required parameter is missing"
const errMsgMinValueConstraint = "provided parameter is not respecting minimum value constraint"
const errMsgMaxValueConstraint = "provided parameter is not respecting maximum value constraint"
const (
errMsgRequiredMissing = "required parameter is missing"
errMsgMinValueConstraint = "provided parameter is not respecting minimum value constraint"
errMsgMaxValueConstraint = "provided parameter is not respecting maximum value constraint"
)

// NewRouter creates a new router for any number of api routers
func NewRouter(routers ...Router) chi.Router {
router := chi.NewRouter()
router.Use(middleware.Logger)
router.Use(middleware.Recoverer)
router.Use(cors.Handler(cors.Options{
AllowedOrigins: []string{"https://*", "http://*"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
Expand Down
Loading
Loading