types

package
v0.0.0-...-4c5efe1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2021 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAPIRoute = newError("invalid api route", http.StatusNotFound)
	ErrBadreq          = newError("bad request", http.StatusBadRequest)
	ErrInvalid         = newError("invalid data", http.StatusBadRequest)
	ErrUnauthorized    = newError("unauthorized", http.StatusUnauthorized)
	ErrForbidden       = newError("forbidden", http.StatusForbidden)
	ErrNotFound        = newError("not found", http.StatusNotFound)
	ErrLBNotFound      = newError("loadbalancer not found", http.StatusNotFound)
	ErrMNA             = newError("method not allowed", http.StatusMethodNotAllowed)
	ErrExists          = newError("resource already exists", http.StatusConflict)
	ErrISE             = newError("internal server error", http.StatusInternalServerError)
	ErrFollower        = newError("follower write forbidden", http.StatusForbidden)
	ErrClusterNotFound = newError("cluster not found", http.StatusNotFound)
	ErrLBsNotFound     = newError("loadbalancers not found", http.StatusNotFound)
)

Functions

This section is empty.

Types

type Auth

type Auth struct {
	// contains filtered or unexported fields
}

func NewAuth

func NewAuth(conf []config.BasicAuth) (a *Auth)

func (*Auth) Login

func (a *Auth) Login(user, pass, path string) bool

type Context

type Context struct {
	Status int

	Request  *http.Request
	Response http.ResponseWriter

	Data *ContextData
	Log  logr.Logger
}

Context is the context object shared between http handlers

func NewContext

func NewContext(w http.ResponseWriter, r *http.Request, data *ContextData, log logr.Logger) *Context

func (*Context) Body

func (c *Context) Body(b []byte)

func (*Context) Err

func (c *Context) Err(err Error)

Err is a HTTPErr wrapper for the custom Error type

func (*Context) Form

func (c *Context) Form(name string) string

Form returns the given form value

func (*Context) GetHeader

func (c *Context) GetHeader(name string) string

GetHeader returns the given http header

func (*Context) HTTPErr

func (c *Context) HTTPErr(err string, status int)

HTTPErr is a http.Error wrapper

func (*Context) JSON

func (c *Context) JSON(v interface{})

JSON is a json response

func (*Context) Leader

func (c *Context) Leader() bool

func (*Context) Method

func (c *Context) Method() string

Method returns the request method

func (*Context) NotFound

func (c *Context) NotFound()

func (*Context) OK

func (c *Context) OK()

OK is a empty HTTP 200 JSON response

func (*Context) Path

func (c *Context) Path() string

Path returns the request URL path

func (*Context) ReadBody

func (c *Context) ReadBody() (b []byte, err error)

func (*Context) SetHeader

func (c *Context) SetHeader(name, value string)

SetHeader sets the given http header

func (*Context) Var

func (c *Context) Var(name string) (ret string)

Var returns the given url variable

type ContextData

type ContextData struct {
	Net netalloc.Allocator
	DB  *db.DB

	Auth         *Auth
	AuthDisabled bool

	Leader bool
}

type CtxHandler

type CtxHandler func(*Context)

type Err

type Err struct {
	// contains filtered or unexported fields
}

Err implements the Error interface

func (Err) Error

func (a Err) Error() string

Error returns the error string

func (Err) JSON

func (a Err) JSON() string

Error returns the error string as JSON format

func (Err) Status

func (a Err) Status() int

Status returns the HTTP status code

type Error

type Error interface {
	Error() string
	JSON() string
	Status() int
}

Error interface is a custom api error

type Route

type Route struct {
	Path    string
	Handler CtxHandler
	Methods []string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL