types

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAPIRoute    = newError("invalid api route", http.StatusNotFound)
	ErrInvalid            = newError("invalid data", http.StatusBadRequest)
	ErrBadreq             = newError("bad request", http.StatusBadRequest)
	ErrForbidden          = newError("forbidden", http.StatusForbidden)
	ErrNotFound           = newError("not found", http.StatusNotFound)
	ErrKeyNotFound        = newError("key not found", http.StatusNotFound)
	ErrReqNotFound        = newError("key request not found", http.StatusNotFound)
	ErrTooManyApprovals   = newError("too many approvals pending", http.StatusConflict)
	ErrKeyRequestRejected = newError("key request rejected", http.StatusForbidden)
	ErrMNA                = newError("method not allowed", http.StatusMethodNotAllowed)
	ErrISE                = newError("internal server error", http.StatusInternalServerError)
)

Functions

This section is empty.

Types

type Approval

type Approval struct {
	ID     string
	Name   string
	IP     string
	Status Status
}

type ApprovalMap

type ApprovalMap map[string]Approval

type Approver

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

func NewApprover

func NewApprover() *Approver

func (*Approver) List

func (a *Approver) List() (m ApprovalMap)

func (*Approver) New

func (a *Approver) New(id, name, ip string) (aid string, err error)

func (*Approver) Status

func (a *Approver) Status(id, aid, ip string) (s Status)

func (*Approver) Update

func (a *Approver) Update(aid string, s Status) (err error)

type Context

type Context struct {
	Code int

	Request  *http.Request
	Response http.ResponseWriter

	Data *ContextData
	Log  logr.Logger
	// contains filtered or unexported fields
}

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) ClientIP

func (c *Context) ClientIP() string

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) HTTPErr

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

HTTPErr is a http.Error wrapper

func (*Context) Header

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

Header returns the given http header

func (*Context) JSON

func (c *Context) JSON(v any)

JSON is a json response

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) Redirect

func (c *Context) Redirect(url string, code int)

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) string

Var returns the given url variable

type ContextData

type ContextData struct {
	Approver *Approver
	DB       *db.DB
}

type CtxHandler

type CtxHandler func(*Context)

type Err

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

Err implements the Error interface

func (Err) Code

func (a Err) Code() int

Code returns the HTTP status code

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

type Error

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

Error interface is a custom api error

type Route

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

type Status

type Status int
const (
	Pending Status = iota
	Approved
	Rejected
	NotFound
)

func (Status) String

func (s Status) String() string

Jump to

Keyboard shortcuts

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