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

Migrate gin to echo with echox and echojwtx #73

Merged
merged 1 commit into from
Apr 20, 2023
Merged
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
3 changes: 1 addition & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# [Choice] Go version (use -bullseye variants on local arm64/Apple Silicon): 1, 1.18, 1.17, 1-bullseye, 1.18-bullseye, 1.17-bullseye, 1-buster, 1.18-buster, 1.17-buster
ARG VARIANT=1-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT}
FROM mcr.microsoft.com/vscode/devcontainers/go:0-1.20-bullseye

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
Expand Down
4 changes: 2 additions & 2 deletions chart/permissions-api/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ spec:
protocol: TCP
livenessProbe:
httpGet:
path: /healthz
path: /livez
port: http
readinessProbe:
httpGet:
path: /healthz
path: /readyz
JAORMX marked this conversation as resolved.
Show resolved Hide resolved
port: http
{{- with .Values.deployment.resources }}
resources:
Expand Down
26 changes: 18 additions & 8 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.hollow.sh/toolbox/ginjwt"
"go.infratographer.com/x/ginx"
"go.infratographer.com/x/echojwtx"
"go.infratographer.com/x/echox"
"go.infratographer.com/x/otelx"
"go.infratographer.com/x/versionx"
"go.uber.org/zap"

"go.infratographer.com/permissions-api/internal/api"
"go.infratographer.com/permissions-api/internal/config"
Expand All @@ -33,9 +34,9 @@ func init() {

v := viper.GetViper()

ginx.MustViperFlags(v, serverCmd.Flags(), apiDefaultListen)
echox.MustViperFlags(v, serverCmd.Flags(), apiDefaultListen)
otelx.MustViperFlags(v, serverCmd.Flags())
ginjwt.RegisterViperOIDCFlags(v, serverCmd)
echojwtx.MustViperFlags(v, serverCmd.Flags())
}

func serve(ctx context.Context, cfg *config.AppConfig) {
Expand All @@ -51,15 +52,24 @@ func serve(ctx context.Context, cfg *config.AppConfig) {

engine := query.NewEngine("infratographer", spiceClient)

s := ginx.NewServer(logger.Desugar(), cfg.Server, versionx.BuildDetails())
srv := echox.NewServer(
logger.Desugar(),
echox.Config{
Listen: viper.GetString("server.listen"),
ShutdownGracePeriod: viper.GetDuration("server.shutdown-grace-period"),
},
versionx.BuildDetails(),
)

r, err := api.NewRouter(cfg.OIDC, engine, logger)
if err != nil {
logger.Fatalw("unable to initialize router", "error", err)
}

s = s.AddHandler(r).
AddReadinessCheck("spicedb", spicedbx.Healthcheck(spiceClient))
srv.AddHandler(r)
srv.AddReadinessCheck("spicedb", spicedbx.Healthcheck(spiceClient))

s.Run()
if err := srv.Run(); err != nil {
logger.Fatal("failed to run server", zap.Error(err))
}
}
45 changes: 19 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
module go.infratographer.com/permissions-api

go 1.19
go 1.20

require (
github.com/authzed/authzed-go v0.7.0
github.com/authzed/grpcutil v0.0.0-20230109193425-40ce0530e048
github.com/gin-gonic/gin v1.9.0
github.com/google/uuid v1.3.0
github.com/labstack/echo/v4 v4.10.2
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.2
go.hollow.sh/toolbox v0.5.1
go.infratographer.com/x v0.0.3
go.infratographer.com/x v0.0.4
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.40.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.40.0
go.opentelemetry.io/otel v1.14.0
Expand All @@ -22,39 +21,33 @@ require (

require (
cloud.google.com/go/compute v1.18.0 // indirect
github.com/MicahParks/keyfunc v1.9.0 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.8.0 // indirect
github.com/brpaz/echozap v1.1.3 // indirect
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/envoyproxy/protoc-gen-validate v0.9.1 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gin-contrib/requestid v0.0.6 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-contrib/zap v0.1.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.14.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmoiron/sqlx v1.3.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/jzelinskie/stringz v0.0.0-20210414224931-d6a8ce844a70 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/labstack/echo-contrib v0.14.1 // indirect
github.com/labstack/echo-jwt/v4 v4.1.0 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand All @@ -64,18 +57,17 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/prometheus/common v0.40.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
github.com/zsais/go-gin-prometheus v0.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.37.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho v0.40.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.11.2 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.11.2 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.11.2 // indirect
Expand All @@ -87,12 +79,13 @@ require (
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230209215440-0dfe4f8abfcc // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
Loading