Last active
June 20, 2020 08:45
-
-
Save rizalgowandy/2cc0bd755a61ef1fd90f146986cac68e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net/http" | |
"github.com/labstack/echo/v4" | |
"github.com/labstack/echo/v4/middleware" | |
_ "github.com/rizalgowandy/go-swag-sample/docs/echosimple" ### replace line with your own path | |
echoSwagger "github.com/swaggo/echo-swagger" | |
) | |
// @title Echo Swagger Example API | |
// @version 1.0 | |
// @description This is a sample server server. | |
// @termsOfService http://swagger.io/terms/ | |
// @contact.name API Support | |
// @contact.url http://www.swagger.io/support | |
// @contact.email [email protected] | |
// @license.name Apache 2.0 | |
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html | |
// @host localhost:3000 | |
// @BasePath / | |
// @schemes http | |
func main() { | |
// Echo instance | |
e := echo.New() | |
// Middleware | |
e.Use(middleware.Logger()) | |
e.Use(middleware.Recover()) | |
e.Use(middleware.CORS()) | |
// Routes | |
e.GET("/", HealthCheck) | |
e.GET("/swagger/*", echoSwagger.WrapHandler) | |
// Start server | |
e.Logger.Fatal(e.Start(":3000")) | |
} | |
// HealthCheck godoc | |
// @Summary Show the status of server. | |
// @Description get the status of server. | |
// @Tags root | |
// @Accept */* | |
// @Produce json | |
// @Success 200 {object} map[string]interface{} | |
// @Router / [get] | |
func HealthCheck(c echo.Context) error { | |
return c.JSON(http.StatusOK, map[string]interface{}{ | |
"data": "Server is up and running", | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment