error-pages/internal/http/handlers/version/handler.go

27 lines
469 B
Go
Raw Normal View History

2021-09-29 15:38:50 +00:00
package version
import (
"encoding/json"
"github.com/valyala/fasthttp"
)
// NewHandler creates version handler.
func NewHandler(ver string) fasthttp.RequestHandler {
var cache []byte
return func(ctx *fasthttp.RequestCtx) {
if cache == nil {
cache, _ = json.Marshal(struct {
Version string `json:"version"`
}{
Version: ver,
})
}
ctx.SetContentType("application/json")
ctx.SetStatusCode(fasthttp.StatusOK)
_, _ = ctx.Write(cache)
}
}