Documentation ¶
Index ¶
- Constants
- Variables
- func BasicAuthFunc(username string, password string) func(*http.Request) bool
- func CheckBewit(r *http.Request) error
- func Error(w http.ResponseWriter, err error)
- func ExpvarsMiddleware(m *expvar.Map) func(next http.Handler) http.Handler
- func GetIpAddress(r *http.Request) string
- func GetSessionID(r *http.Request) string
- func HeaderLog(w http.ResponseWriter, msg string)
- func LoggerMiddleware(logger log.Logger) func(next http.Handler) http.Handler
- func MarshalAndWrite(r *http.Request, w http.ResponseWriter, data interface{}, ...) bool
- func NewBewit(url *url.URL, ttl time.Duration) error
- func NewSnappyResponseWriter(rw http.ResponseWriter, r *http.Request) *snappyResponseWriter
- func Read(r *http.Request) ([]byte, error)
- func RecoverHandler(h http.Handler) http.Handler
- func SetAttachment(fname string, r *http.Request, w http.ResponseWriter)
- func SetHawkKey(bkey []byte)
- func SetNoCache(w http.ResponseWriter)
- func Unmarshal(req *http.Request, out interface{}) error
- func WithStatusCode(status int) func(http.ResponseWriter)
- func Write(r *http.Request, w http.ResponseWriter, data []byte, ...)
- func WriteEncoded(r *http.Request, w http.ResponseWriter, data []byte, ...)
- func WriteJSON(w http.ResponseWriter, data interface{})
- func WriteJSONError(w http.ResponseWriter, status int, msg string)
- type PublicError
- type PublicErrorer
- type Query
- func (q *Query) Get(key string) string
- func (q *Query) GetBoolDefault(key string, defaultval bool) (bool, error)
- func (q *Query) GetDefault(key, defaultval string) string
- func (q *Query) GetInt(key string, defaultval, maxval int) (int, error)
- func (q *Query) GetInt64Default(key string, defaultval int64) (int64, error)
- func (q *Query) GetIntDefault(key string, defaultval int) (int, error)
Constants ¶
const ResponseFormatHeader = "BlobStash-API-Response-Format"
Variables ¶
var BasicRealm = "Authorization Required"
BasicRealm is used when setting the WWW-Authenticate response header.
Functions ¶
func BasicAuthFunc ¶
BasicAuthFunc implements a checker for HTTP Basic Authentication scheme
func CheckBewit ¶
Check will try to authenticate the `bewit` parameter for the given request
func Error ¶
func Error(w http.ResponseWriter, err error)
Error is an shortcut for `WriteJSONError(w, http.StatusInternalServerError, err.Error())`
func GetIpAddress ¶
Return the IP Address from the `*http.Request`. Try the `X-Real-Ip`, `X-Forwarded-For` headers first.
func GetSessionID ¶
GetSessionID returns the client "session ID" (set via the `BlobStash-Session-ID` header). Returns an empty string if it's missing.
func HeaderLog ¶
func HeaderLog(w http.ResponseWriter, msg string)
HeaderLog append a debug message that will be outputted in the `BlobStash-Debug` header
func LoggerMiddleware ¶
LoggerMiddleware logs HTTP requests and adds some debug headers
func MarshalAndWrite ¶
func MarshalAndWrite(r *http.Request, w http.ResponseWriter, data interface{}, writeOptions ...func(http.ResponseWriter)) bool
func NewSnappyResponseWriter ¶
func NewSnappyResponseWriter(rw http.ResponseWriter, r *http.Request) *snappyResponseWriter
NewSnappyResponseWriter returns a `http.ResponseWriter` wrapper which can encode the output with Snappy if requested by the client. If snappy isn't enabled, it will act like a regular `http.ResponseWriter` `Close` must be call so the `*snappy.Writer` instance can be put back in the `sync.Pool`
func RecoverHandler ¶
RecoverHandler catches all the "paniced" errors and display a JSON error
func SetAttachment ¶
func SetAttachment(fname string, r *http.Request, w http.ResponseWriter)
SetAttachment will set the "Content-Disposition" header if the "dl" query parameter is set
func SetHawkKey ¶
func SetHawkKey(bkey []byte)
func SetNoCache ¶
func SetNoCache(w http.ResponseWriter)
Set the `Cache-control` header to `no-cache` in order to prevent the browser to cache the response
func WithStatusCode ¶
func WithStatusCode(status int) func(http.ResponseWriter)
func Write ¶
func Write(r *http.Request, w http.ResponseWriter, data []byte, writeOptions ...func(http.ResponseWriter))
func WriteEncoded ¶
func WriteEncoded(r *http.Request, w http.ResponseWriter, data []byte, writeOptions ...func(http.ResponseWriter))
Same as Write, but assume data is already snappy encoded
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, data interface{})
WriteJSON marshal and output the data as JSON with the right content-type
func WriteJSONError ¶
func WriteJSONError(w http.ResponseWriter, status int, msg string)
WriteJSONError is an helper to output a {"error": <msg>} JSON payload with the given status code
Types ¶
type PublicError ¶
type PublicError struct {
Err error
}
Wrapping an error in PublicError will make the RecoverHandler display the error message instead of the default status text.
func (*PublicError) Error ¶
func (pe *PublicError) Error() string
Error implements the Error interface
func (*PublicError) Status ¶
func (pe *PublicError) Status() int
Status implements the PublicErrorer interface with a 500 status code
type PublicErrorer ¶
PublicErrorer is the interface for "displayable" error by the RecoverHandler
func NewPublicErrorFmt ¶
func NewPublicErrorFmt(msg string, args ...interface{}) PublicErrorer
NewPublicError is a shortcut for initializing a `PublicError` with `fmt.Errorf`
type Query ¶
type Query struct {
// contains filtered or unexported fields
}