-
Hi. I'm migrating an Apache webservice to run using go and echo framework only. I now had a look at the security settings and found the Apache doing the following: The following apache stuff should be converted for echo framework at set on a generic level:
How do I set these values in echo? Or is this not needed? |
Beta Was this translation helpful? Give feedback.
Answered by
aldas
Jun 8, 2021
Replies: 1 comment 1 reply
-
If you need custom configuration for TLS when you would need to create something like that func main() {
e := echo.New()
// create for Echo routes
s := http.Server{
Addr: ":8443",
Handler: e, // set Echo as handler
TLSConfig: &tls.Config{
//Certificates: nil, // <-- s.ListenAndServeTLS will populate this field for you
//CipherSuites: nil,
//PreferServerCipherSuites: false,
//MinVersion: 0,
//MaxVersion: 0,
//CurvePreferences: nil,
},
}
if err := s.ListenAndServeTLS("server.crt", "server.key"); err != http.ErrServerClosed {
log.Fatal(err)
}
} If you need to add headers to responses. do: func main() {
e := echo.New()
// this middleware will add these headers to every handler
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
c.Response().Header().Add("Pragma", "no-cache")
// ..
// ..
return next(c)
}
})
e.GET("/", func(c echo.Context) error {
// or in handler function
c.Response().Header().Add("Pragma", "no-cache")
return c.JSON(http.StatusOK, "{}")
})
// ... start server
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Kukulkano
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you need custom configuration for TLS when you would need to create something like that
If you need to add headers to responses. do:
func