uapi

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompileValidationErrors

func CompileValidationErrors(payload any) map[string]string

func SetupState

func SetupState(s UAPIState)

Types

type APIRouter

type APIRouter interface {
	Routes(r *chi.Mux)
	Tag() (string, string)
}

type AuthData

type AuthData struct {
	TargetType string         `json:"target_type"`
	ID         string         `json:"id"`
	Authorized bool           `json:"authorized"`
	Banned     bool           `json:"banned"`
	Data       map[string]any `json:"data"`
}

type AuthType

type AuthType struct {
	URLVar       string
	Type         string
	AllowedScope string
}

type HttpResponse

type HttpResponse struct {
	Data     string
	Bytes    []byte
	Json     any
	Headers  map[string]string
	Status   int
	Redirect string
}

func DefaultResponse

func DefaultResponse(statusCode int) HttpResponse

func MarshalReq

func MarshalReq(r *http.Request, dst any) (resp HttpResponse, ok bool)

func MarshalReqWithHeaders

func MarshalReqWithHeaders(r *http.Request, dst any, headers map[string]string) (resp HttpResponse, ok bool)

func ValidatorErrorResponse

func ValidatorErrorResponse(compiled map[string]string, v validator.ValidationErrors) HttpResponse

type Method

type Method int
const (
	GET Method = iota
	POST
	PATCH
	PUT
	DELETE
	HEAD
)

func (Method) String

func (m Method) String() string

type Route

type Route struct {
	Method                Method
	Pattern               string
	Aliases               map[string]string
	OpId                  string
	Handler               func(d RouteData, r *http.Request) HttpResponse
	Setup                 func()
	Docs                  func() *docs.Doc
	Auth                  []AuthType
	ExtData               map[string]any
	AuthOptional          bool
	SanityCheck           func() error
	DisablePathSlashCheck bool
}

func (Route) Route

func (r Route) Route(ro Router)

func (Route) String

func (r Route) String() string

type RouteData

type RouteData struct {
	Context context.Context
	Auth    AuthData
	Props   map[string]string
}

type Router

type Router interface {
	Get(pattern string, h http.HandlerFunc)
	Post(pattern string, h http.HandlerFunc)
	Patch(pattern string, h http.HandlerFunc)
	Put(pattern string, h http.HandlerFunc)
	Delete(pattern string, h http.HandlerFunc)
	Head(pattern string, h http.HandlerFunc)
}

type UAPIConstants

type UAPIConstants struct {
	ResourceNotFound    string
	BadRequest          string
	Forbidden           string
	Unauthorized        string
	InternalServerError string
	MethodNotAllowed    string
	BodyRequired        string
}

type UAPIDefaultResponder

type UAPIDefaultResponder interface {
	New(msg string, ctx map[string]string) any
}

type UAPIInitData

type UAPIInitData struct {
	Tag string
}

type UAPIState

type UAPIState struct {
	Logger              *zap.Logger
	Authorize           func(r Route, req *http.Request) (AuthData, HttpResponse, bool)
	AuthTypeMap         map[string]string
	RouteDataMiddleware func(rd *RouteData, req *http.Request) (*RouteData, error)
	BaseSanityCheck     func(r Route) error
	PatchDocs           func(d *docs.Doc) *docs.Doc
	Context             context.Context
	Constants           *UAPIConstants
	DefaultResponder    UAPIDefaultResponder
	InitData            UAPIInitData
}
var (
	State *UAPIState
)

func (*UAPIState) SetCurrentTag

func (s *UAPIState) SetCurrentTag(tag string)

Jump to

Keyboard shortcuts

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