codies/helpers.go

25 lines
470 B
Go
Raw Normal View History

2020-05-25 05:18:35 +00:00
package main
import (
"net/http"
"reflect"
"github.com/gofrs/uuid"
"github.com/tomwright/queryparam/v4"
)
func httpErr(w http.ResponseWriter, code int) {
http.Error(w, http.StatusText(code), code)
}
func stringPtr(s string) *string {
return &s
}
func init() {
queryparam.DefaultParser.ValueParsers[reflect.TypeOf(uuid.UUID{})] = func(value string, _ string) (reflect.Value, error) {
id, err := uuid.FromString(value)
return reflect.ValueOf(id), err
}
}