diff --git a/Makefile b/Makefile index 606b4cc..e4378fc 100644 --- a/Makefile +++ b/Makefile @@ -87,7 +87,9 @@ release: git push origin $(VERSION) swagger: - go install github.com/swaggo/swag/cmd/swag + go install github.com/swaggo/swag/cmd/swag@latest + go get github.com/swaggo/swag/gen@latest + go get github.com/swaggo/swag/cmd/swag@latest cd pkg/api && $$(go env GOPATH)/bin/swag init -g server.go .PHONY: cue-mod diff --git a/go.mod b/go.mod index e76adcf..80c7da3 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.12.0 github.com/swaggo/http-swagger v1.2.8 - github.com/swaggo/swag v1.8.2 + github.com/swaggo/swag v1.8.3 go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.32.0 go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.32.0 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.32.0 @@ -42,7 +42,9 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cenkalti/backoff/v4 v4.1.3 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect github.com/felixge/httpsnoop v1.0.2 // indirect + github.com/ghodss/yaml v1.0.0 // indirect github.com/go-logr/logr v1.2.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect @@ -65,11 +67,13 @@ require ( github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.32.1 // indirect github.com/prometheus/procfs v0.7.3 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/spf13/afero v1.8.2 // indirect github.com/spf13/cast v1.5.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/subosito/gotenv v1.3.0 // indirect github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2 // indirect + github.com/urfave/cli/v2 v2.3.0 // indirect go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.7.0 // indirect go.opentelemetry.io/otel/metric v0.30.0 // indirect go.opentelemetry.io/proto/otlp v0.16.0 // indirect diff --git a/go.sum b/go.sum index bca4731..1193c68 100644 --- a/go.sum +++ b/go.sum @@ -82,6 +82,8 @@ github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWH github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU= github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -105,6 +107,7 @@ github.com/felixge/httpsnoop v1.0.2/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSw github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -296,7 +299,10 @@ github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1 github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= @@ -331,6 +337,10 @@ github.com/swaggo/http-swagger v1.2.8 h1:TVjxLU7qoqofJ9qynJazmpTGs/p4Kx9FTp7YYwO github.com/swaggo/http-swagger v1.2.8/go.mod h1:FrQwV7rx+A5t11PIX8d+tFJa2GKx11RdAXQptllPQHg= github.com/swaggo/swag v1.8.2 h1:D4aBiVS2a65zhyk3WFqOUz7Rz0sOaUcgeErcid5uGL4= github.com/swaggo/swag v1.8.2/go.mod h1:jMLeXOOmYyjk8PvHTsXBdrubsNd9gUJTTCzL5iBnseg= +github.com/swaggo/swag v1.8.3 h1:3pZSSCQ//gAH88lfmxM3Cd1+JCsxV8Md6f36b9hrZ5s= +github.com/swaggo/swag v1.8.3/go.mod h1:jMLeXOOmYyjk8PvHTsXBdrubsNd9gUJTTCzL5iBnseg= +github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= +github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/pkg/api/docs/docs.go b/pkg/api/docs/docs.go index 00074c6..1b2b661 100644 --- a/pkg/api/docs/docs.go +++ b/pkg/api/docs/docs.go @@ -1,22 +1,14 @@ -// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT +// Package docs GENERATED BY SWAG; DO NOT EDIT // This file was generated by swaggo/swag - package docs -import ( - "bytes" - "encoding/json" - "strings" +import "github.com/swaggo/swag" - "github.com/alecthomas/template" - "github.com/swaggo/swag" -) - -var doc = `{ +const docTemplate = `{ "schemes": {{ marshal .Schemes }}, "swagger": "2.0", "info": { - "description": "{{.Description}}", + "description": "{{escape .Description}}", "title": "{{.Title}}", "contact": { "name": "Source Code", @@ -110,6 +102,15 @@ var doc = `{ "HTTP API" ], "summary": "Get payload from cache", + "parameters": [ + { + "type": "string", + "description": "Key to load from cache", + "name": "key", + "in": "path", + "required": true + } + ], "responses": { "200": { "description": "OK", @@ -131,6 +132,15 @@ var doc = `{ "HTTP API" ], "summary": "Save payload in cache", + "parameters": [ + { + "type": "string", + "description": "Key to save to", + "name": "key", + "in": "path", + "required": true + } + ], "responses": { "202": { "description": "" @@ -149,6 +159,15 @@ var doc = `{ "HTTP API" ], "summary": "Delete payload from cache", + "parameters": [ + { + "type": "string", + "description": "Key to delete", + "name": "key", + "in": "path", + "required": true + } + ], "responses": { "202": { "description": "" @@ -303,7 +322,8 @@ var doc = `{ "tags": [ "HTTP API" ], - "summary": "Panic" + "summary": "Panic", + "responses": {} } }, "/readyz": { @@ -610,49 +630,18 @@ var doc = `{ } }` -type swaggerInfo struct { - Version string - Host string - BasePath string - Schemes []string - Title string - Description string -} - // SwaggerInfo holds exported Swagger Info so clients can modify it -var SwaggerInfo = swaggerInfo{ - Version: "2.0", - Host: "localhost:9898", - BasePath: "/", - Schemes: []string{"http", "https"}, - Title: "Podinfo API", - Description: "Go microservice template for Kubernetes.", -} - -type s struct{} - -func (s *s) ReadDoc() string { - sInfo := SwaggerInfo - sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1) - - t, err := template.New("swagger_info").Funcs(template.FuncMap{ - "marshal": func(v interface{}) string { - a, _ := json.Marshal(v) - return string(a) - }, - }).Parse(doc) - if err != nil { - return doc - } - - var tpl bytes.Buffer - if err := t.Execute(&tpl, sInfo); err != nil { - return doc - } - - return tpl.String() +var SwaggerInfo = &swag.Spec{ + Version: "2.0", + Host: "localhost:9898", + BasePath: "/", + Schemes: []string{"http", "https"}, + Title: "Podinfo API", + Description: "Go microservice template for Kubernetes.", + InfoInstanceName: "swagger", + SwaggerTemplate: docTemplate, } func init() { - swag.Register(swag.Name, &s{}) + swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) } diff --git a/pkg/api/docs/swagger.json b/pkg/api/docs/swagger.json index bbb873b..9720822 100644 --- a/pkg/api/docs/swagger.json +++ b/pkg/api/docs/swagger.json @@ -99,6 +99,15 @@ "HTTP API" ], "summary": "Get payload from cache", + "parameters": [ + { + "type": "string", + "description": "Key to load from cache", + "name": "key", + "in": "path", + "required": true + } + ], "responses": { "200": { "description": "OK", @@ -120,6 +129,15 @@ "HTTP API" ], "summary": "Save payload in cache", + "parameters": [ + { + "type": "string", + "description": "Key to save to", + "name": "key", + "in": "path", + "required": true + } + ], "responses": { "202": { "description": "" @@ -138,6 +156,15 @@ "HTTP API" ], "summary": "Delete payload from cache", + "parameters": [ + { + "type": "string", + "description": "Key to delete", + "name": "key", + "in": "path", + "required": true + } + ], "responses": { "202": { "description": "" @@ -292,7 +319,8 @@ "tags": [ "HTTP API" ], - "summary": "Panic" + "summary": "Panic", + "responses": {} } }, "/readyz": { diff --git a/pkg/api/docs/swagger.yaml b/pkg/api/docs/swagger.yaml index 10fd702..4308297 100644 --- a/pkg/api/docs/swagger.yaml +++ b/pkg/api/docs/swagger.yaml @@ -103,6 +103,12 @@ paths: consumes: - application/json description: deletes the key and its value from cache + parameters: + - description: Key to delete + in: path + name: key + required: true + type: string produces: - application/json responses: @@ -115,6 +121,12 @@ paths: consumes: - application/json description: returns the content from cache if key exists + parameters: + - description: Key to load from cache + in: path + name: key + required: true + type: string produces: - application/json responses: @@ -129,6 +141,12 @@ paths: consumes: - application/json description: writes the posted content in cache + parameters: + - description: Key to save to + in: path + name: key + required: true + type: string produces: - application/json responses: @@ -233,6 +251,7 @@ paths: /panic: get: description: crashes the process with exit code 255 + responses: {} summary: Panic tags: - HTTP API