Skip to content

Commit

Permalink
Merge pull request #46
Browse files Browse the repository at this point in the history
Make port in swagger docs configurable

Reviewed-by: [email protected]
Tested-by: [email protected]
  • Loading branch information
GMishx authored Feb 28, 2024
2 parents 3090c7d + e7c8d90 commit c1e95ae
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/laas/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2028,7 +2028,7 @@ const docTemplate = `{
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "0.0.9",
Host: "localhost:8080",
Host: "",
BasePath: "/api/v1",
Schemes: []string{},
Title: "laas (License as a Service) API",
Expand Down
1 change: 0 additions & 1 deletion cmd/laas/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
},
"version": "0.0.9"
},
"host": "localhost:8080",
"basePath": "/api/v1",
"paths": {
"/audits": {
Expand Down
1 change: 0 additions & 1 deletion cmd/laas/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,6 @@ definitions:
example: 200
type: integer
type: object
host: localhost:8080
info:
contact:
email: [email protected]
Expand Down
14 changes: 13 additions & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
package api

import (
"fmt"
"net/http"
"os"
"time"

"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"

"github.com/fossology/LicenseDb/cmd/laas/docs"
"github.com/fossology/LicenseDb/pkg/auth"
"github.com/fossology/LicenseDb/pkg/db"
"github.com/fossology/LicenseDb/pkg/middleware"
Expand All @@ -33,14 +36,23 @@ import (
// @license.name GPL-2.0-only
// @license.url https://github.com/fossology/LicenseDb/blob/main/LICENSE
//
// @host localhost:8080
// @BasePath /api/v1
//
// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name Authorization
// @description Token from /login endpoint

const DEFAULT_PORT = "8080"

func Router() *gin.Engine {

port := os.Getenv("PORT")
if len(port) == 0 {
port = DEFAULT_PORT
}
docs.SwaggerInfo.Host = fmt.Sprintf("localhost:%s", port)

// r is a default instance of gin engine
r := gin.Default()

Expand Down

0 comments on commit c1e95ae

Please sign in to comment.