go-tsviewer/request/meta/meta.go

37 lines
609 B
Go
Raw Permalink Normal View History

2019-01-14 20:07:11 +00:00
package meta
import (
"net/http"
"strconv"
)
type Meta struct {
Pretty bool `json:"pretty"`
Envelope bool `json:"envelope"`
}
func NewFromRequest(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
}