Documentation
¶
Index ¶
- Variables
- func ByPassLogger() func(next http.Handler) http.Handler
- func Cors() *cors.Cors
- func GetLogEntry(r *http.Request) zerolog.Context
- func IgnoreError(v ...interface{})
- func LogEntrySetField(r *http.Request, key string, value interface{})
- func LogEntrySetFields(r *http.Request, fields map[string]interface{})
- func Render(w http.ResponseWriter, r *http.Request, v render.Renderer)
- type ApiError
- func ErrDatabase(err error) *ApiError
- func ErrInternalServerError(err error) *ApiError
- func ErrInvalidEmailSignup(cause error) *ApiError
- func ErrInvalidRequest(err error, data ...interface{}) *ApiError
- func ErrPermission(err error) *ApiError
- func ErrRequestEntityTooLarge(err error) *ApiError
- func ErrServiceUnavailable(err error) *ApiError
- func ErrUnauthorized(err error) *ApiError
- type ContextKey
- type SeverityHook
- type Status
- type StructuredLogger
- type StructuredLoggerEntry
Constants ¶
This section is empty.
Variables ¶
var ( // SessionCtxKey is the context.Context key to store the request context. SessionUserCtxKey = &ContextKey{Name: "Session.User"} SessionRoleCtxKey = &ContextKey{Name: "Session.Role"} )
var ( // ErrBadID error message for bad or invalid id ErrBadID = &ApiError{StatusCode: http.StatusBadRequest, ErrorText: "bad or invalid id"} // ErrPermissionDenied error message for permission denied ErrPermissionDenied = &ApiError{StatusCode: http.StatusUnauthorized, ErrorText: "permission denied"} // ErrInvalidSession error message for invalid session ErrInvalidSession = &ApiError{StatusCode: http.StatusUnauthorized, ErrorText: "invalid session"} // ErrEncryptionError error message for bcrypt password encryption error ErrEncryptionError = &ApiError{StatusCode: http.StatusInternalServerError, ErrorText: "issue with email signup"} // ErrUserExists throws error if user already exists ErrUserExists = &ApiError{StatusCode: http.StatusConflict, ErrorText: "user already exists"} )
Functions ¶
func LogEntrySetField ¶
func LogEntrySetFields ¶
Types ¶
type ApiError ¶
type ApiError struct {
Err error `json:"-"`
StatusCode int `json:"-"`
StatusText string `json:"status"`
Location string `json:"location,omitempty"`
AppCode int64 `json:"code,omitempty"`
ErrorText string `json:"error,omitempty"`
Cause string `json:"cause,omitempty"`
Data interface{} `json:"data,omitempty"`
}
ApiError holds possible http api error fields
func ErrDatabase ¶
ErrDatabase is error message for inability to perform database operation
func ErrInternalServerError ¶
ErrInternalServerError is error message for Internal Server.
func ErrInvalidEmailSignup ¶
ErrInvalidEmailSignup shapes error message if the users email address is invalid
func ErrInvalidRequest ¶
ErrInvalidRequest is error message for bad request
func ErrPermission ¶
ErrPermission is error message for Unauthorized
func ErrRequestEntityTooLarge ¶
ErrRequestEntityTooLarge is error message for Request Entity Too Large
func ErrServiceUnavailable ¶
ErrServiceUnavailable is error message for Service Unavailable
func ErrUnauthorized ¶
ErrUnauthorized is error message for Unauthorized
type ContextKey ¶
type ContextKey struct {
Name string
}
contextKey is a value for use with context.WithValue. It's used as a pointer so it fits in an interface{} without allocation. This technique for defining context keys was copied from Go 1.7's new use of context in net/http.
func (*ContextKey) String ¶
func (k *ContextKey) String() string
type SeverityHook ¶
Run secondary functions based on severity.
type StructuredLogger ¶
func (*StructuredLogger) NewLogEntry ¶
func (z *StructuredLogger) NewLogEntry(r *http.Request) middleware.LogEntry
type StructuredLoggerEntry ¶
func (*StructuredLoggerEntry) Panic ¶
func (entry *StructuredLoggerEntry) Panic(v interface{}, stack []byte)