api

package
v0.0.0-...-e2941dc Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrHeaderValueMissingQuotes = errors.New("header missing quotes")
	ErrUnknownAcceptType        = errors.New("unknown Accept type")
)
View Source
var (
	ErrInvalidIfNoneMatch           = errors.New("invalid If-None-Match")
	ErrIfNoneMatchUnknownType       = fmt.Errorf("unknown type (%w)", ErrInvalidIfNoneMatch)
	ErrIfNoneMatchInvalidGeneration = fmt.Errorf("invalid generation (%w)", ErrInvalidIfNoneMatch)
)
View Source
var (
	ErrInvalidFilterOp     = errors.New("invalid filter operator")
	ErrInvalidSort         = errors.New("invalid _sort")
	ErrInvalidStreamFormat = errors.New("invalid _stream")
)
View Source
var ErrMissingAuthCheck = errors.New("missing auth check")
View Source
var ErrStreamingNotSupported = errors.New("streaming not supported")

Functions

func ApplyFilters

func ApplyFilters[T any](list []T, opts *ListOpts) ([]T, error)

func ApplySorts

func ApplySorts[T any](list []T, opts *ListOpts) ([]T, error)

func ApplyWindow

func ApplyWindow[T any](list []T, opts *ListOpts) ([]T, error)

func Create

func Create[TOut, TIn any](ctx context.Context, api *API, obj *TIn) (*TOut, error)

func CreateName

func CreateName[TOut, TIn any](ctx context.Context, api *API, name string, obj *TIn) (*TOut, error)

func Delete

func Delete[TOut any](ctx context.Context, api *API, id string, opts *UpdateOpts) error

func DeleteName

func DeleteName[TOut any](ctx context.Context, api *API, name, id string, opts *UpdateOpts) error

func FieldChanged

func FieldChanged[T any](obj *T, prev *T, p string) bool

func Find

func Find[TOut any](ctx context.Context, api *API, shortID string) (*TOut, error)

func FindName

func FindName[TOut any](ctx context.Context, api *API, name, shortID string) (*TOut, error)

func Get

func Get[TOut any](ctx context.Context, api *API, id string, opts *GetOpts) (*TOut, error)

func GetName

func GetName[TOut any](ctx context.Context, api *API, name, id string, opts *GetOpts) (*TOut, error)

func IsCreate

func IsCreate[T any](obj *T, prev *T) bool

func IsDelete

func IsDelete[T any](obj *T, prev *T) bool

func IsUpdate

func IsUpdate[T any](obj *T, prev *T) bool

func List

func List[TOut any](ctx context.Context, api *API, opts *ListOpts) ([]*TOut, error)

func ListName

func ListName[TOut any](ctx context.Context, api *API, name string, opts *ListOpts) ([]*TOut, error)

func P

func P[T any](v T) *T

func Register

func Register[T any](api *API)

func RegisterName

func RegisterName[T any](api *API, typeName string)

func Replace

func Replace[TOut, TIn any](ctx context.Context, api *API, id string, obj *TIn, opts *UpdateOpts) (*TOut, error)

func ReplaceName

func ReplaceName[TOut, TIn any](ctx context.Context, api *API, name, id string, obj *TIn, opts *UpdateOpts) (*TOut, error)

func SetAuthBasic

func SetAuthBasic[T any](api *API, pathUser, pathPass string)

func SetAuthBasicName

func SetAuthBasicName[T any](api *API, name, pathUser, pathPass string)

func SetAuthBearer

func SetAuthBearer[T any](api *API, pathToken string)

func SetAuthBearerName

func SetAuthBearerName[T any](api *API, name, pathToken string)

func SetListHook

func SetListHook[T any](api *API, hook ListHook)

func SetListHookName

func SetListHookName[T any](api *API, name string, hook ListHook)

func Update

func Update[TOut, TIn any](ctx context.Context, api *API, id string, obj *TIn, opts *UpdateOpts) (*TOut, error)

func UpdateName

func UpdateName[TOut, TIn any](ctx context.Context, api *API, name, id string, obj *TIn, opts *UpdateOpts) (*TOut, error)

Types

type API

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

func NewAPI

func NewAPI(dbname string) (*API, error)

func (*API) Addr

func (api *API) Addr() *net.TCPAddr

func (*API) CheckSafe

func (api *API) CheckSafe()

func (*API) Close

func (api *API) Close()

func (*API) Handle

func (api *API) Handle(method, path string, handler httprouter.Handle)

func (*API) Handler

func (api *API) Handler(method, path string, handler http.Handler)

func (*API) HandlerFunc

func (api *API) HandlerFunc(method, path string, handler http.HandlerFunc)

func (*API) IsSafe

func (api *API) IsSafe() error

func (*API) ListenInsecure

func (api *API) ListenInsecure(bind string) error

func (*API) ListenSelfCert

func (api *API) ListenSelfCert(bind string) error

func (*API) ListenTLS

func (api *API) ListenTLS(bind, certFile, keyFile string) error

func (*API) Serve

func (api *API) Serve() error

func (*API) ServeFiles

func (api *API) ServeFiles(path string, fs http.FileSystem)

func (*API) ServeHTTP

func (api *API) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*API) SetOpenAPIInfo

func (api *API) SetOpenAPIInfo(info *OpenAPIInfo)

func (*API) SetRequestHook

func (api *API) SetRequestHook(hook RequestHook)

func (*API) SetStripPrefix

func (api *API) SetStripPrefix(prefix string)

func (*API) Shutdown

func (api *API) Shutdown(ctx context.Context) error

type ContextKey

type ContextKey int
const (
	ContextInternal ContextKey = iota

	ContextAuthBearer
	ContextAuthBasic
)

type DebugInfo

type DebugInfo struct {
	Server *ServerInfo `json:"server"`
	IP     *IPInfo     `json:"ip"`
	HTTP   *HTTPInfo   `json:"http"`
	TLS    *TLSInfo    `json:"tls"`
}

type Filter

type Filter struct {
	Path  string
	Op    string
	Value string
}

type GetOpts

type GetOpts struct {
	IfNoneMatch []httpheader.EntityTag

	// This is "any" because making GetOpts generic complicates too many things
	Prev any
}

type GetStream

type GetStream[T any] struct {
	// contains filtered or unexported fields
}

func StreamGet

func StreamGet[TOut any](ctx context.Context, api *API, id string) (*GetStream[TOut], error)

func StreamGetName

func StreamGetName[T any](ctx context.Context, api *API, name, id string) (*GetStream[T], error)

func (*GetStream[T]) Chan

func (gs *GetStream[T]) Chan() <-chan *T

func (*GetStream[T]) Close

func (gs *GetStream[T]) Close()

func (*GetStream[T]) Error

func (gs *GetStream[T]) Error() error

func (*GetStream[T]) Read

func (gs *GetStream[T]) Read() *T

type HTTPInfo

type HTTPInfo struct {
	Protocol string      `json:"protocol"`
	Method   string      `json:"method"`
	Header   http.Header `json:"header"`
	URL      string      `json:"url"`
}

type IPInfo

type IPInfo struct {
	RemoteAddr string `json:"remoteAddr"`
}

type ListHook

type ListHook func(context.Context, *ListOpts, *API) error

type ListOpts

type ListOpts struct {
	Stream  string
	Limit   int64
	Offset  int64
	After   string
	Sorts   []string
	Filters []*Filter

	IfNoneMatch []httpheader.EntityTag

	// This is "any" because making ListOpts generic complicates too many things
	Prev any
}

type ListStream

type ListStream[T any] struct {
	// contains filtered or unexported fields
}

func StreamList

func StreamList[TOut any](ctx context.Context, api *API, opts *ListOpts) (*ListStream[TOut], error)

func StreamListName

func StreamListName[TOut any](ctx context.Context, api *API, name string, opts *ListOpts) (*ListStream[TOut], error)

func (*ListStream[T]) Chan

func (ls *ListStream[T]) Chan() <-chan []*T

func (*ListStream[T]) Close

func (ls *ListStream[T]) Close()

func (*ListStream[T]) Error

func (ls *ListStream[T]) Error() error

func (*ListStream[T]) Read

func (ls *ListStream[T]) Read() []*T

type Metadata

type Metadata = metadata.Metadata

type OpenAPI

type OpenAPI = openapi3.T

type OpenAPIInfo

type OpenAPIInfo = openapi3.Info

type RequestHook

type RequestHook func(*http.Request, *API) (*http.Request, error)

type ServerInfo

type ServerInfo struct {
	Hostname string `json:"hostname"`
}

type TLSInfo

type TLSInfo struct {
	Version            uint16 `json:"version"`
	DidResume          bool   `json:"didResume"`
	CipherSuite        uint16 `json:"cipherSuite"`
	NegotiatedProtocol string `json:"negotiatedProtocol"`
	ServerName         string `json:"serverName"`
}

type UpdateOpts

type UpdateOpts struct {
	IfMatch []httpheader.EntityTag

	// This is "any" because making UpdateOpts generic complicates too many things
	Prev any
}

Jump to

Keyboard shortcuts

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