This repository has been archived on 2019-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
scoreboard/request/meta/meta.go
2019-05-27 23:46:09 +02:00

36 lines
611 B
Go
Executable file

package meta
import (
"net/http"
"strconv"
)
type Meta struct {
Pretty bool `json:"pretty"`
Envelope bool `json:"envelope"`
}
func ParseFromRequest(r *http.Request) *Meta {
meta := Meta{
Pretty: false,
Envelope: false,
}
pretty, ok := r.URL.Query()["pretty"]
if ok && len(pretty) > 0 {
prettyBool, err := strconv.ParseBool(pretty[0])
if err == nil {
meta.Pretty = prettyBool
}
}
envelope, ok := r.URL.Query()["envelope"]
if ok && len(envelope) > 0 {
envelopeBool, err := strconv.ParseBool(envelope[0])
if err == nil {
meta.Envelope = envelopeBool
}
}
return &meta
}