error-pages/internal/http/handlers/version/handler.go
2021-09-29 20:38:50 +05:00

27 lines
469 B
Go

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)
}
}