Never had this issue with ports
It's an issue that is obvious to me. It usually hurts nothing, except for gin-swagger.
package main import ( "fmt" "io/ioutil" "log" "os" "runtime" "strconv" "strings" "github.com/gin-gonic/gin" swaggerFiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" _ "${MY_GO_MOD}/docs" ) // @title Swagger Example API // @version 1.0 // @description This is a sample server Petstore server. // @termsOfService http://swagger.io/terms/ // @contact.name API Support // @contact.url http://www.swagger.io/support // @contact.email support@swagger.io // @license.name Apache 2.0 // @license.url http://www.apache.org/licenses/LICENSE-2.0.html // @host petstore.swagger.io // @BasePath /v2 func main() { port := os.Getenv("PORT") if port == "" { port = "8080" } r := gin.New() swaggerURL := fmt.Sprintf("http://localhost:%s/swagger/doc.json", port) if runtime.GOOS == "linux" { if data, err := ioutil.ReadFile("/proc/version"); err == nil && strings.Contains(string(data), "microsoft") { if p, err := strconv.Atoi(port); err == nil { swaggerURL = fmt.Sprintf("http://localhost:%d/swagger/doc.json", p+1) } } } url := ginSwagger.URL(swaggerURL) r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url)) log.Printf("Server running at http://localhost:%s", port) r.Run(":" + port) }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Never had this issue with ports
It's an issue that is obvious to me. It usually hurts nothing, except for gin-swagger.