Skip to content

Instantly share code, notes, and snippets.

@hahwul
Created January 22, 2021 18:49
Show Gist options
  • Save hahwul/9575158544a3754c66eec1948d229b21 to your computer and use it in GitHub Desktop.
Save hahwul/9575158544a3754c66eec1948d229b21 to your computer and use it in GitHub Desktop.
Go simple web server using echo
package main
import (
"net/http"
"github.com/labstack/echo/v4/middleware"
"github.com/labstack/echo/v4"
"github.com/tylerb/graceful"
)
func main() {
e := echo.New()
e.Use(middleware.SecureWithConfig(middleware.SecureConfig{
XSSProtection: "",
ContentTypeNosniff: "",
XFrameOptions: "",
HSTSMaxAge: 3600,
ContentSecurityPolicy: "default-src 'self'",
}))
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Format: "method=${method}, uri=${uri}, status=${status}\n",
}))
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hi wanda :D")
})
e.Server.Addr = ":1323"
// Serve it like a boss
graceful.ListenAndServe(e.Server, 5*time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment