Created
January 22, 2021 18:49
-
-
Save hahwul/9575158544a3754c66eec1948d229b21 to your computer and use it in GitHub Desktop.
Go simple web server using echo
This file contains 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/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