patchy

package module
v0.0.0-...-54b281d Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2023 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBuildInfoFailed          = errors.New("failed to read build info")
	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 ErrEndOfStream = fmt.Errorf("end of stream")
View Source
var ErrMissingAuthCheck = errors.New("missing auth check")
View Source
var ErrStreamingNotSupported = errors.New("streaming not supported")

Functions

func AddAuthBasic

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

func AddAuthBasicName

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

func AddAuthBearer

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

func AddAuthBearerName

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

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[T any](ctx context.Context, api *API, obj *T) (*T, error)

func CreateName

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

func Delete

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

func DeleteName

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

func EventHookAuthBasic

func EventHookAuthBasic(ctx context.Context, ev *event.Event)

func EventHookAuthBearer

func EventHookAuthBearer(ctx context.Context, ev *event.Event)

func EventHookSpanID

func EventHookSpanID(ctx context.Context, ev *event.Event)

func FieldChanged

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

func Find

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

func FindName

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

func Get

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

func GetName

func GetName[T any](ctx context.Context, api *API, name, id string, opts *GetOpts) (*T, 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[T any](ctx context.Context, api *API, opts *ListOpts) ([]*T, error)

func ListName

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

func OpenAPIHookAuthBasic

func OpenAPIHookAuthBasic(_ context.Context, t *OpenAPI)

func OpenAPIHookAuthBearer

func OpenAPIHookAuthBearer(_ context.Context, t *OpenAPI)

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, apiName, camelName string)

func Replace

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

func ReplaceName

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

func ReplicateIn

func ReplicateIn[TIn, TOut any](ctx context.Context, api *API, in <-chan []*TIn, transform func(in *TIn) (*TOut, error), opts *ListOpts) error

func ReplicateInName

func ReplicateInName[TIn, TOut any](ctx context.Context, api *API, name string, in <-chan []*TIn, transform func(in *TIn) (*TOut, error), opts *ListOpts) error

func ReplicateInNameOnce

func ReplicateInNameOnce[TIn, TOut any](ctx context.Context, api *API, name string, in <-chan []*TIn, transform func(in *TIn) (*TOut, error), opts *ListOpts) error

func ReplicateInOnce

func ReplicateInOnce[TIn, TOut any](ctx context.Context, api *API, in <-chan []*TIn, transform func(in *TIn) (*TOut, error), opts *ListOpts) error

func SetListHook

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

func SetListHookName

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

func SyncList

func SyncList[T any](ctx context.Context, api *API, list []*T, opts *ListOpts) error

func SyncListName

func SyncListName[T any](ctx context.Context, api *API, name string, list []*T, opts *ListOpts) error

func Update

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

func UpdateMap

func UpdateMap[T any](ctx context.Context, api *API, id string, patch map[string]any, opts *UpdateOpts) (*T, error)

func UpdateName

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

func UpdateNameMap

func UpdateNameMap[T any](ctx context.Context, api *API, name, id string, patch map[string]any, opts *UpdateOpts) (*T, error)

Types

type API

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

func NewAPI

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

func (*API) AddOpenAPIHook

func (api *API) AddOpenAPIHook(hook OpenAPIHook)

func (*API) AddRequestHook

func (api *API) AddRequestHook(hook RequestHook)

func (*API) Addr

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

func (*API) CheckSafe

func (api *API) CheckSafe()

func (*API) EventClient

func (api *API) EventClient() *event.Client

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

func (api *API) Log(ctx context.Context, vals ...any)

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

func (api *API) SetEventData(ctx context.Context, vals ...any)

func (*API) SetOpenAPIInfo

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

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 (
	ContextStub ContextKey = iota

	ContextAuthBasicLookup
	ContextAuthBearerLookup
	ContextReplicate

	ContextAuthBearer
	ContextAuthBasic

	ContextWriteID
	ContextWriteGeneration

	ContextSpanID

	ContextEvent
)

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[T any](ctx context.Context, api *API, id string) (*GetStream[T], 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[T any](ctx context.Context, api *API, opts *ListOpts) (*ListStream[T], error)

func StreamListName

func StreamListName[T any](ctx context.Context, api *API, name string, opts *ListOpts) (*ListStream[T], 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 OpenAPIHook

type OpenAPIHook func(context.Context, *OpenAPI)

type OpenAPIInfo

type OpenAPIInfo = openapi3.Info

type RequestHook

type RequestHook func(http.ResponseWriter, *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