You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
963 B
Go

package internal
import (
"log/slog"
"net/http"
)
// handleSomething handles one of those web requests
// that you hear so much about.
func handleSomething(logger *slog.Logger, config *Config) http.Handler {
// provides a closure environment for the function
// thing := prepareThing()
msg := config.GetMessage()
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
// use thing to handle request
logger.Info("Handle something called", "msg", msg)
w.Write([]byte("handledSomething..."))
},
)
}
// handleHealthzPlease returns a healthyu en
func handleHealthzPlease(logger *slog.Logger) http.Handler {
response := map[string]string{"status": "healthy"}
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
logger.Debug("Health endpoint called", "method", r.Method, "url", r.URL.Path)
if err := encode(w, r, http.StatusOK, response); err != nil {
serverError(logger, w, r, err)
}
})
}