mirror of
https://github.com/tarampampam/error-pages.git
synced 2024-08-30 18:22:40 +00:00
27 lines
469 B
Go
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)
|
||
|
}
|
||
|
}
|