Skip to content

Commit

Permalink
Update Swagger info
Browse files Browse the repository at this point in the history
  • Loading branch information
paulyhedral committed Nov 2, 2024
1 parent abbd025 commit 879586c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
38 changes: 28 additions & 10 deletions cmd/catalog-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
apiconstants "github.com/sweetrpg/api-core/constants"
"github.com/sweetrpg/api-core/tracing"
"github.com/sweetrpg/catalog-api/constants"
_ "github.com/sweetrpg/catalog-api/docs"
"github.com/sweetrpg/catalog-api/docs"
"github.com/sweetrpg/catalog-api/server"
"github.com/sweetrpg/common/logging"
"github.com/sweetrpg/common/util"
Expand All @@ -29,16 +29,13 @@ import (

// @title Catalog API service
// @version 1.0
// @description Testing Swagger APIs.
// @termsOfService http://swagger.io/terms/
// @description Swagger APIs
// @termsOfService https://pilgrimagesoftware.com/terms/
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email [email protected]
// @contact.url https://sweetrpg.com
// @contact.email [email protected]
// @license.name MIT
// @license.url https://mit-license.org/
// @host localhost:8000
// @BasePath /
// @schemes http https
func main() {
_ = godotenv.Load(".env")

Expand All @@ -62,15 +59,28 @@ func main() {
// Actuator
setupAcuator(r)

// swagger middleware to serve the API docs
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
// Swagger
setupSwagger(r)

server.SetupHandlers(r, cache)

_ = r.Run(util.GetEnv(apiconstants.BIND_ADDRESS, ":8000"))
}

func setupSwagger(r *gin.Engine) {
logging.Logger.Info("Setting up Swagger...")

docs.SwaggerInfo.Version = os.Getenv(apiconstants.VERSION)
docs.SwaggerInfo.Host = util.GetEnv(apiconstants.INGRESS_HOST, "localhost")

Check failure on line 74 in cmd/catalog-api/main.go

View workflow job for this annotation

GitHub Actions / Linux

undefined: apiconstants.INGRESS_HOST

Check failure on line 74 in cmd/catalog-api/main.go

View workflow job for this annotation

GitHub Actions / Linux

undefined: apiconstants.INGRESS_HOST
docs.SwaggerInfo.BasePath = util.GetEnv(apiconstants.INGRESS_BASE_PATH, "/")

Check failure on line 75 in cmd/catalog-api/main.go

View workflow job for this annotation

GitHub Actions / Linux

undefined: apiconstants.INGRESS_BASE_PATH

Check failure on line 75 in cmd/catalog-api/main.go

View workflow job for this annotation

GitHub Actions / Linux

undefined: apiconstants.INGRESS_BASE_PATH
docs.SwaggerInfo.Schemes = strings.Split(util.GetEnv(apiconstants.INGRESS_SCHEMES, "http"), ",")

Check failure on line 76 in cmd/catalog-api/main.go

View workflow job for this annotation

GitHub Actions / Linux

undefined: apiconstants.INGRESS_SCHEMES

Check failure on line 76 in cmd/catalog-api/main.go

View workflow job for this annotation

GitHub Actions / Linux

undefined: apiconstants.INGRESS_SCHEMES
// swagger middleware to serve the API docs
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
}

func setupSentry() {
logging.Logger.Info("Setting up Sentry...")

sentryDsn, found := os.LookupEnv(apiconstants.SENTRY_DSN)
if found {
sentryDebug, _ := strconv.ParseBool(util.GetEnv(apiconstants.SENTRY_DEBUG, "false"))
Expand Down Expand Up @@ -100,6 +110,8 @@ func setupSentry() {
}

func setupAcuator(r *gin.Engine) {
logging.Logger.Info("Setting up actuator...")

actuatorHandler := actuator.GetActuatorHandler(&actuator.Config{
Endpoints: []int{
actuator.Env,
Expand All @@ -121,6 +133,8 @@ func setupAcuator(r *gin.Engine) {
}

func setupCache() persistence.CacheStore {
logging.Logger.Info("Setting up query cache...")

var cache persistence.CacheStore
redisHost, found := os.LookupEnv(apiconstants.REDIS_HOST)
if found {
Expand All @@ -136,12 +150,16 @@ func setupCache() persistence.CacheStore {
}

func setupTracing(r *gin.Engine) {
logging.Logger.Info("Setting up tracing...")

tracing.SetupTracing(constants.ServiceName)
defer tracing.TeardownTracing()
r.Use(otelgin.Middleware(constants.ServiceName))
}

func setupMetrics(r *gin.Engine) {
logging.Logger.Info("Setting up metrics endpoint...")

m := ginmetrics.GetMonitor()
m.SetMetricPath("/metrics")
m.SetSlowTime(10)
Expand Down
3 changes: 3 additions & 0 deletions kubernetes/overlays/dev/configmaps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ data:
OTEL_EXPORTER_OTLP_ENDPOINT: http://jaeger-collector.observability.svc.cluster.local:4318/
SENTRY_RELEASE: "1"
REDIS_HOST: redis-master.sweetrpg-catalog.svc.cluster.local
INGRESS_BASE_PATH: /0
INGRESS_HOST: api.catalog.dev.sweetrpg.com
INGRESS_SCHEMES: http,https
6 changes: 3 additions & 3 deletions server/contributions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"net/http"
"time"

"github.com/sweetrpg/api-core/tracing"

"github.com/getsentry/sentry-go"
"github.com/gin-contrib/cache"
"github.com/gin-contrib/cache/persistence"
"github.com/gin-gonic/gin"
"github.com/google/jsonapi"
"github.com/sweetrpg/api-core/tracing"
_ "github.com/sweetrpg/api-core/vo"
"github.com/sweetrpg/catalog-data/data"
"github.com/sweetrpg/common/logging"
options "go.jtlabs.io/query"
Expand All @@ -35,7 +35,7 @@ func setupContributionHandlers(g *gin.Engine, store persistence.CacheStore) {
// @Tags contributions
// @Produce json
// @Success 200 {object} interface{}
// @Failure 500 {object} interface{}
// @Failure 500 {object} vo.ErrorVO
// @Router /contributions [get]
func listContributions(c *gin.Context) {
opt, _ := options.FromQuerystring(c.Request.URL.RawQuery)
Expand Down

0 comments on commit 879586c

Please sign in to comment.