36 lines
611 B
Go
Executable file
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
|
|
}
|