Use swagger specification in GoLang for Azure functions

Viewed 123

Curently i'm building an Azure serverless Function in GoLang. I must have a swagger specification inside the function. I'm using gin as http framework and swaggo as the swagger specification generator.

Main function:

func main() {
    port, exists := os.LookupEnv("FUNCTIONS_CUSTOMHANDLER_PORT")
    if !exists {
        port = "8080"
    }
    r := gin.Default()

    v1 := r.Group("/api")
    v1.GET("/ping", function.Ping)
    v1.GET("/docs", function.Swagger)
    url := ginSwagger.URL("http://localhost:7071/api/docs")
    v1.GET("/swagger", ginSwagger.WrapHandler(swaggerFiles.Handler, url))
    r.Run(":" + port)
}

The function that will return the swagger.json:

func Swagger(c *gin.Context) {
    c.File("docs/swagger.json")
}

When we build the application and run it local the response is 404.

0 Answers
Related