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

37 lines
611 B
Go
Raw Permalink Normal View History

2019-05-26 19:32:16 +00:00
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
}