Skip to content

Instantly share code, notes, and snippets.

@estenssoros
Last active February 27, 2019 19:47
Show Gist options
  • Save estenssoros/1d102c884738e79911dba2f03344a63c to your computer and use it in GitHub Desktop.
Save estenssoros/1d102c884738e79911dba2f03344a63c to your computer and use it in GitHub Desktop.
medium-90cb6e872528-app.go
package main
import (
"net/http"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/<your-username>/<my-app>/server/api"
)
func NewApp() *echo.Echo {
engine := echo.New()
engine.Debug = true
engine.Use(middleware.Recover())
engine.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Format: "[ECHO] - ${time_rfc3339} |${status}| ${latency_human} | ${host} | ${method} ${uri}\n",
}))
engine.Use(cors)
engine.GET("/", func(c echo.Context) error {
if data, err := Asset("index.html"); err == nil {
return c.HTMLBlob(http.StatusOK, data)
} else {
return err
}
})
apiGroup := engine.Group("/api")
apiGroup.Use(auth)
api.Routes(apiGroup)
engine.Use(sendBinaryFiles)
return engine
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment