Documentation
¶
Index ¶
- Variables
- func CancelOnInterrupt(cancel context.CancelFunc, log zerolog.Logger)
- func Decrypt(secret []byte, encrypted string) ([]byte, error)
- func Encrypt(secret []byte, value []byte) (string, error)
- func FromISO(date string) (time.Time, error)
- func IDParam(r *http.Request, name string) uint
- func LoadEnv(env interface{}) error
- func NewLogger(service string) zerolog.Logger
- func ParseQuery(query map[string]string, v interface{}) error
- func RandomBytes(n int) ([]byte, error)
- func RandomString(s int) (string, error)
- func ReadBody(r *http.Request) []byte
- func ReadJSON(r *http.Request, v interface{})
- func ReadQuery(r *http.Request, v interface{})
- func RunServer(ctx context.Context, log zerolog.Logger, server *http.Server)
- func Send(w http.ResponseWriter, code int, data []byte)
- func SendError(r *http.Request, w http.ResponseWriter, err APIError)
- func SendSuccess(r *http.Request, w http.ResponseWriter, v interface{})
- func StringParam(r *http.Request, name string) string
- func UUID() string
- type APIError
- type SessionStore
Constants ¶
This section is empty.
Variables ¶
var ( ErrAuthorisationFormat = errors.New("Your authorization header format is invalid") ErrUnsupportedScheme = errors.New("Your scheme is not supported") ErrEmptyToken = errors.New("There was no token supplied to the authorization header") ErrHeaderNotSet = errors.New("Authorization header is not set") )
var DumpLog = regexp.MustCompile("(?i)kube-probe|prometheus")
var ISO_FORMATS = [3]string{"2006-01-02T15:04:05.000Z", "2006-01-02", "2006-01-02T15:04:05"}
Functions ¶
func CancelOnInterrupt ¶ added in v0.8.0
func CancelOnInterrupt(cancel context.CancelFunc, log zerolog.Logger)
CancelOnInterrupt cancels a context when it receives an interrupt signal
func LoadEnv ¶ added in v0.5.0
func LoadEnv(env interface{}) error
LoadEnv loads environment variables into Env
func ParseQuery ¶ added in v0.9.0
ParseQuery converts a map of strings to strings to a struct. It uses the key and default struct tag to help it determine how to get keys and set defaults. Mind that it only supports the types - int(all bit sizes) - uint(all bit sizes) - float(all bit sizes) - string - ISO8601 time
func RandomBytes ¶ added in v0.8.0
RandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.
func RandomString ¶ added in v0.8.0
RandomString returns a securely generated random hex string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue. Keep in mind that s is the length of the returned string, not the number of bytes to be produced
func ReadBody ¶
ReadBody extracts the bytes in a request body without destroying the contents of the body
func ReadJSON ¶ added in v0.8.0
ReadJSON decodes the JSON body of the request and destroys to prevent possible issues with writing a response. If the content type is not JSON it fails with a 415. Otherwise it fails with a 400 on validation errors.
func SendError ¶
func SendError(r *http.Request, w http.ResponseWriter, err APIError)
SendError sends a JSON error message
func SendSuccess ¶
func SendSuccess(r *http.Request, w http.ResponseWriter, v interface{})
SendSuccess sends a JSON success message with status code 200
func StringParam ¶ added in v0.2.0
StringParam basically just ensures the param name is correct. You might not need this method unless you're too lazy to do real tests.
Types ¶
type APIError ¶
type APIError struct {
Code int `json:"-"`
Message string `json:"message"`
Meta interface{} `json:"meta"`
Err error `json:"-"`
}
APIError is a struct describing an error
type SessionStore ¶ added in v0.8.0
type SessionStore struct {
// contains filtered or unexported fields
}
func NewSessionStore ¶ added in v0.8.0
func (*SessionStore) Headless ¶ added in v0.8.0
func (s *SessionStore) Headless() func(http.Handler) http.Handler
Secure loads a user session into the request context
func (*SessionStore) Load ¶ added in v0.8.0
func (s *SessionStore) Load(r *http.Request, session interface{})
Load retrieves a user's session object based on the session key from the Authorization header or the session cookie and fails with an error if it faces any issue parsing any of them.