From b5fe430870beadd5aaac4465a1e6389e1695882b Mon Sep 17 00:00:00 2001 From: Morlay Date: Sun, 21 Apr 2024 10:46:27 +0800 Subject: [PATCH] chore(deps): updates --- go.mod | 8 +++---- go.sum | 12 +++++++++-- pkg/http/openapi_playground.go | 39 ++++++++++++++++++++++++++++++++++ pkg/http/server.go | 32 ---------------------------- 4 files changed, 53 insertions(+), 38 deletions(-) create mode 100644 pkg/http/openapi_playground.go diff --git a/go.mod b/go.mod index fcaa1ab..fb18910 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/felixge/httpsnoop v1.0.4 github.com/go-courier/logr v0.3.0 github.com/go-json-experiment/json v0.0.0-20240418180308-af2d5061e6c2 - github.com/innoai-tech/openapi-playground v0.0.0-20240420062124-2ed72af77893 + github.com/innoai-tech/openapi-playground v0.0.0-20240420084814-73535475d149 github.com/octohelm/courier v0.0.0-20240419085324-367eabf18c5e github.com/octohelm/gengo v0.0.0-20240409082121-aeffa5400f19 github.com/octohelm/storage v0.0.0-20240311031904-722fae0a0075 @@ -30,7 +30,7 @@ require ( go.opentelemetry.io/otel/log v0.1.0-alpha go.opentelemetry.io/otel/metric v1.25.0 go.opentelemetry.io/otel/sdk v1.25.0 - go.opentelemetry.io/otel/sdk/log v0.0.0-20240419070214-1f76264a2e61 + go.opentelemetry.io/otel/sdk/log v0.0.0-20240420112451-48f028ffd36c go.opentelemetry.io/otel/sdk/metric v1.25.0 go.opentelemetry.io/otel/trace v1.25.0 golang.org/x/net v0.24.0 @@ -44,7 +44,7 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/internal v1.6.0 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect github.com/alecthomas/units v0.0.0-20231202071711-9a357b53e9c9 // indirect - github.com/aws/aws-sdk-go v1.51.24 // indirect + github.com/aws/aws-sdk-go v1.51.25 // indirect github.com/bboreham/go-loser v0.0.0-20230920113527-fcc2c21820a3 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect @@ -83,7 +83,7 @@ require ( github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/common v0.53.0 // indirect github.com/prometheus/common/sigv4 v0.1.0 // indirect - github.com/prometheus/procfs v0.13.0 // indirect + github.com/prometheus/procfs v0.14.0 // indirect github.com/stretchr/testify v1.9.0 // indirect go.opentelemetry.io/proto/otlp v1.2.0 // indirect go.uber.org/atomic v1.11.0 // indirect diff --git a/go.sum b/go.sum index 7d6fda5..6b15723 100644 --- a/go.sum +++ b/go.sum @@ -67,6 +67,8 @@ github.com/armon/go-metrics v0.4.1/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+ github.com/aws/aws-sdk-go v1.38.35/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/aws/aws-sdk-go v1.51.24 h1:nwL5MaommPkwb7Ixk24eWkdx5HY4of1gD10kFFVAl6A= github.com/aws/aws-sdk-go v1.51.24/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= +github.com/aws/aws-sdk-go v1.51.25 h1:DjTT8mtmsachhV6yrXR8+yhnG6120dazr720nopRsls= +github.com/aws/aws-sdk-go v1.51.25/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= github.com/bboreham/go-loser v0.0.0-20230920113527-fcc2c21820a3 h1:6df1vn4bBlDDo4tARvBm7l6KA9iVMnE3NWizDeWSrps= github.com/bboreham/go-loser v0.0.0-20230920113527-fcc2c21820a3/go.mod h1:CIWtjkly68+yqLPbvwwR/fjNJA/idrtULjZWh2v1ys0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= @@ -242,6 +244,7 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd h1:PpuIBO5P3e9hpqBD0O/HjhShYuM6XE0i/lbE6J94kww= github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd/go.mod h1:M5qHK+eWfAv8VR/265dIuEpL3fNfeC21tXXp9itM24A= +github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0QDGLKzqOmktBjT+Is= github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1/go.mod h1:5SN9VR2LTsRFsrEC6FHgRbTWrTHu6tqPeKxEQv15giM= github.com/hashicorp/consul/api v1.28.2 h1:mXfkRHrpHN4YY3RqL09nXU1eHKLNiuAN4kHvDQ16k/8= @@ -277,8 +280,8 @@ github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/innoai-tech/openapi-playground v0.0.0-20240420062124-2ed72af77893 h1:3gMvmcYlbyhLOVek/YWqJWk3/YDpzyrm9pKESp19Tg0= -github.com/innoai-tech/openapi-playground v0.0.0-20240420062124-2ed72af77893/go.mod h1:XF6gAVE9R8xSKHWbG0TtH/7RbWrTh16PH23eGZk69po= +github.com/innoai-tech/openapi-playground v0.0.0-20240420084814-73535475d149 h1:eAL4hNrl8jjXgNYqo6fwcKANaLNRvil5Pb12xvH6kns= +github.com/innoai-tech/openapi-playground v0.0.0-20240420084814-73535475d149/go.mod h1:XF6gAVE9R8xSKHWbG0TtH/7RbWrTh16PH23eGZk69po= github.com/ionos-cloud/sdk-go/v6 v6.1.11 h1:J/uRN4UWO3wCyGOeDdMKv8LWRzKu6UIkLEaes38Kzh8= github.com/ionos-cloud/sdk-go/v6 v6.1.11/go.mod h1:EzEgRIDxBELvfoa/uBN0kOQaqovLjUWEB7iW4/Q+t4k= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= @@ -412,6 +415,8 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/procfs v0.13.0 h1:GqzLlQyfsPbaEHaQkO7tbDlriv/4o5Hudv6OXHGKX7o= github.com/prometheus/procfs v0.13.0/go.mod h1:cd4PFCR54QLnGKPaKGA6l+cfuNXtht43ZKY6tow0Y1g= +github.com/prometheus/procfs v0.14.0 h1:Lw4VdGGoKEZilJsayHf0B+9YgLGREba2C6xr+Fdfq6s= +github.com/prometheus/procfs v0.14.0/go.mod h1:XL+Iwz8k8ZabyZfMFHPiilCniixqQarAy5Mu67pHlNQ= github.com/prometheus/prometheus v0.51.2 h1:U0faf1nT4CB9DkBW87XLJCBi2s8nwWXdTbyzRUAkX0w= github.com/prometheus/prometheus v0.51.2/go.mod h1:yv4MwOn3yHMQ6MZGHPg/U7Fcyqf+rxqiZfSur6myVtc= github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0 h1:sadMIsgmHpEOGbUs6VtHBXRR1OHevnj7hLx9ZcdNGW4= @@ -472,6 +477,8 @@ go.opentelemetry.io/otel/sdk v1.25.0 h1:PDryEJPC8YJZQSyLY5eqLeafHtG+X7FWnf3aXMtx go.opentelemetry.io/otel/sdk v1.25.0/go.mod h1:oFgzCM2zdsxKzz6zwpTZYLLQsFwc+K0daArPdIhuxkw= go.opentelemetry.io/otel/sdk/log v0.0.0-20240419070214-1f76264a2e61 h1:rFEHbmSIzjGIWy8xJcNbptLugnQoNomQ8Xuq6WQVUi0= go.opentelemetry.io/otel/sdk/log v0.0.0-20240419070214-1f76264a2e61/go.mod h1:hhtugoOtNL5LhgMYdSshVsCw6VqcKLlQGnhlq5YroMc= +go.opentelemetry.io/otel/sdk/log v0.0.0-20240420112451-48f028ffd36c h1:D0rfTtsFm0AeK1NTWU+rDbW1KhrexkYkbWJSrB2+YiQ= +go.opentelemetry.io/otel/sdk/log v0.0.0-20240420112451-48f028ffd36c/go.mod h1:hhtugoOtNL5LhgMYdSshVsCw6VqcKLlQGnhlq5YroMc= go.opentelemetry.io/otel/sdk/metric v1.25.0 h1:7CiHOy08LbrxMAp4vWpbiPcklunUshVpAvGBrdDRlGw= go.opentelemetry.io/otel/sdk/metric v1.25.0/go.mod h1:LzwoKptdbBBdYfvtGCzGwk6GWMA3aUzBOwtQpR6Nz7o= go.opentelemetry.io/otel/trace v1.25.0 h1:tqukZGLwQYRIFtSQM2u2+yfMVTgGVeqRLPUYx1Dq6RM= @@ -801,6 +808,7 @@ k8s.io/apimachinery v0.30.0 h1:qxVPsyDM5XS96NIh9Oj6LavoVFYff/Pon9cZeDIkHHA= k8s.io/apimachinery v0.30.0/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= k8s.io/client-go v0.30.0 h1:sB1AGGlhY/o7KCyCEQ0bPWzYDL0pwOZO4vAtTSh/gJQ= k8s.io/client-go v0.30.0/go.mod h1:g7li5O5256qe6TYdAMyX/otJqMhIiGgTapdLchhmOaY= +k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8= k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw= k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag= diff --git a/pkg/http/openapi_playground.go b/pkg/http/openapi_playground.go new file mode 100644 index 0000000..939b42a --- /dev/null +++ b/pkg/http/openapi_playground.go @@ -0,0 +1,39 @@ +package http + +import ( + "encoding/base64" + "net/http" + "strings" + "sync" + + "github.com/innoai-tech/infra/pkg/http/webapp" + openapiview "github.com/innoai-tech/openapi-playground" + "github.com/octohelm/courier/pkg/courierhttp/handler/httprouter" +) + +func init() { + httprouter.SetOpenAPIViewContents(&openapiView{}) +} + +type openapiView struct { + once sync.Once + handler http.Handler +} + +func (v *openapiView) Upgrade(w http.ResponseWriter, r *http.Request) error { + v.once.Do(func() { + basePath := strings.Split(r.URL.Path, "/_view/")[0] + + v.handler = webapp.ServeFS( + openapiview.Contents, + webapp.WithBaseHref(basePath+"/_view/"), + webapp.WithAppConfig(map[string]string{ + "OPENAPI": base64.StdEncoding.EncodeToString([]byte(basePath)), + }), + ) + }) + + v.handler.ServeHTTP(w, r) + + return nil +} diff --git a/pkg/http/server.go b/pkg/http/server.go index 5bf6949..090a138 100644 --- a/pkg/http/server.go +++ b/pkg/http/server.go @@ -3,15 +3,11 @@ package http import ( "compress/gzip" "context" - "encoding/base64" "fmt" "net/http" "runtime" - "strings" - "sync" "github.com/go-courier/logr" - openapiview "github.com/innoai-tech/openapi-playground" "github.com/octohelm/courier/pkg/courier" "github.com/octohelm/courier/pkg/courierhttp/handler" "github.com/octohelm/courier/pkg/courierhttp/handler/httprouter" @@ -22,36 +18,8 @@ import ( "github.com/innoai-tech/infra/pkg/cli" "github.com/innoai-tech/infra/pkg/configuration" "github.com/innoai-tech/infra/pkg/http/middleware" - "github.com/innoai-tech/infra/pkg/http/webapp" ) -func init() { - httprouter.SetOpenAPIViewContents(&openapiView{}) -} - -type openapiView struct { - once sync.Once - handler http.Handler -} - -func (v *openapiView) Upgrade(w http.ResponseWriter, r *http.Request) error { - v.once.Do(func() { - basePath := strings.Split(r.URL.Path, "/_view/")[0] - - v.handler = webapp.ServeFS( - openapiview.Contents, - webapp.WithBaseHref(basePath+"/_view/"), - webapp.WithAppConfig(map[string]string{ - "OPENAPI": base64.StdEncoding.EncodeToString([]byte(basePath + "/")), - }), - ) - }) - - v.handler.ServeHTTP(w, r) - - return nil -} - type Server struct { // Listen addr Addr string `flag:",omitempty,expose=http"`