api

package
v0.0.0-...-20fbe64 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2024 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	RedocTemplate = `` /* 622-byte string literal not displayed */

	SwaggerTemplate = `` /* 1427-byte string literal not displayed */

)

Variables

This section is empty.

Functions

func AddSwaggerOperation

func AddSwaggerOperation(swagger *spec.Swagger, route *Route, builder *openapi.Builder)

func NewRedocUI

func NewRedocUI(specPath string) []byte

func NewSwaggerUI

func NewSwaggerUI(specPath string) []byte

func NewUsernameContext

func NewUsernameContext(ctx context.Context, username string) context.Context

func UsernameFromContext

func UsernameFromContext(ctx context.Context) string

Types

type API

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

func NewAPI

func NewAPI() *API

func (*API) APIDoc

func (m *API) APIDoc(completer func(swagger *spec.Swagger)) *API

func (*API) BuildHandler

func (m *API) BuildHandler() http.Handler

func (*API) Filter

func (m *API) Filter(pattern string, filters ...Filter) *API

func (*API) HealthCheck

func (m *API) HealthCheck(checkfun func() error) *API

func (*API) Register

func (m *API) Register(prefix string, modules ...Module) *API

func (*API) Route

func (m *API) Route(route *Route) *API

func (*API) Serve

func (m *API) Serve(ctx context.Context, listenaddr string) error

func (*API) TLS

func (m *API) TLS(cert, key string) *API

func (*API) Version

func (m *API) Version(data any) *API

type Filter

type Filter func(w http.ResponseWriter, r *http.Request, next http.Handler)

func CORSFilter

func CORSFilter() Filter

func LoggingFilter

func LoggingFilter(log logr.Logger) Filter

func OIDCAuthFilter

func OIDCAuthFilter(ctx context.Context, opts *OIDCClientOptions) Filter

type Filters

type Filters []Filter

func (Filters) Process

func (fs Filters) Process(w http.ResponseWriter, r *http.Request, next http.Handler)

type Function

type Function = http.HandlerFunc

type Group

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

func NewGroup

func NewGroup(path string) *Group

func (*Group) AddRoutes

func (g *Group) AddRoutes(rs ...*Route) *Group

func (*Group) AddSubGroup

func (g *Group) AddSubGroup(groups ...*Group) *Group

func (*Group) BuildRoutes

func (t *Group) BuildRoutes() map[string]map[string]*Route

func (*Group) Parameters

func (g *Group) Parameters(params ...Param) *Group

func (*Group) Tag

func (g *Group) Tag(name string) *Group

type Module

type Module interface {
	RegisterRoute(r *Group)
}

type OIDCClientOptions

type OIDCClientOptions struct {
	Issuer         string
	Audience       string
	NoAuthPatterns []string                   // white list pathes, match by path.Match
	CustomRules    func(r *http.Request) bool // 用户自定义规则
}

type Param

type Param struct {
	Name        string
	Kind        ParamKind
	Type        string
	Enum        []any
	Default     any
	IsOptional  bool
	Description string
	Example     any
}

func BodyParameter

func BodyParameter(name string, value any) Param

func FormParameter

func FormParameter(name string, description string) Param

func PathParameter

func PathParameter(name string, description string) Param

func QueryParameter

func QueryParameter(name string, description string) Param

func (Param) DataType

func (p Param) DataType(t string) Param

func (Param) Desc

func (p Param) Desc(desc string) Param

func (Param) In

func (p Param) In(t ...any) Param

func (Param) Optional

func (p Param) Optional() Param

type ParamKind

type ParamKind string
const (
	ParamKindPath   ParamKind = "path"
	ParamKindQuery  ParamKind = "query"
	ParamKindHeader ParamKind = "header"
	ParamKindForm   ParamKind = "formData"
	ParamKindBody   ParamKind = "body"
)

type PatternFilter

type PatternFilter struct {
	Pattern matcher.Section
	Filters Filters
}

type PatternFilters

type PatternFilters []PatternFilter

func (PatternFilters) Process

func (p PatternFilters) Process(w http.ResponseWriter, r *http.Request, next http.Handler)

type ResponseMeta

type ResponseMeta struct {
	Code        int
	Headers     map[string]string
	Body        interface{}
	Description string
}

type Route

type Route struct {
	Summary    string
	Path       string
	Method     string
	Deprecated bool
	Func       Function
	Tags       []string
	Consumes   []string
	Produces   []string
	Params     []Param
	Responses  []ResponseMeta
	Properties map[string]interface{}
}

func Any

func Any(path string) *Route

func DELETE

func DELETE(path string) *Route

func Do

func Do(method string, path string) *Route

func GET

func GET(path string) *Route
func HEAD(path string) *Route

func OPTIONS

func OPTIONS(path string) *Route

func PATCH

func PATCH(path string) *Route

func POST

func POST(path string) *Route

func PUT

func PUT(path string) *Route

func (*Route) Accept

func (n *Route) Accept(mime ...string) *Route

Accept types of all the responses

func (*Route) ContentType

func (n *Route) ContentType(mime ...string) *Route

ContentType of all available responses type

func (*Route) Doc

func (n *Route) Doc(summary string) *Route

func (*Route) Parameters

func (n *Route) Parameters(params ...Param) *Route

func (*Route) Response

func (n *Route) Response(body interface{}, desc ...string) *Route

func (*Route) SetProperty

func (n *Route) SetProperty(k string, v interface{}) *Route

func (*Route) Tag

func (n *Route) Tag(tags ...string) *Route

func (*Route) To

func (n *Route) To(fun Function) *Route

type StatusResponseWriter

type StatusResponseWriter struct {
	http.ResponseWriter
	StatusCode int
}

func (*StatusResponseWriter) WriteHeader

func (w *StatusResponseWriter) WriteHeader(code int)

Jump to

Keyboard shortcuts

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