Documentation
¶
Index ¶
- Variables
- func ErrorCode(err error, def int) int
- func HandleRequest[Req any](c ctx.C, s *Server, path string, f func(ctx.C, Req, http.ResponseWriter) error) *openapi.PathItem
- func NewRequest(c ctx.C, method string, url string, body io.Reader) (*http.Request, error)
- func TestAPI[T Doable, UID any](c ctx.C, uid UID, obj T) error
- type Call
- type CallHandler
- type Client
- type Doable
- type Error
- type Request
- type ResponseWriter
- type Server
- func (this *Server) Handle(path string, h http.Handler) *openapi.Path
- func (this *Server) HandleFunc(path string, h http.HandlerFunc) *openapi.Path
- func (this *Server) HandleRequest(path string, f func(r *Request) (any, error)) *openapi.PathItem
- func (this *Server) HandleStream(path string, f StreamFunc) *openapi.PathItem
- func (this *Server) Listen(c ctx.C, addr string) (*net.TCPAddr, error)
- func (s *Server) MustRegisterAPI(c ctx.C, path string, obj Doable) *openapi.PathItem
- func (s *Server) MustRegisterStreamingAPI(c ctx.C, path string, obj Streamable) *openapi.PathItem
- func (this Server) Mux() *http.ServeMux
- func (s *Server) RegisterAPI(c ctx.C, path string, obj Doable) (*openapi.PathItem, error)
- func (s *Server) RegisterStreamingAPI(c ctx.C, path string, obj Streamable) (*openapi.PathItem, error)
- func (this *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (this *Server) SetReady(code int)
- func (this *Server) SetupMonitoring(c ctx.C, prefix string)
- func (this *Server) SetupPrometheus(c ctx.C, path string)
- func (this *Server) Use(mw func(http.Handler) http.Handler)
- type StreamFunc
- type Streamable
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultClient = Client{}
View Source
var Metrics = struct { Request *prom.Histogram }{ Request: prom.Register("http_request", &prom.Histogram{ Buckets: prom.DefaultBuckets, Labels: []string{"method", "path", "code"}, }), }
Functions ¶
func HandleRequest ¶
func NewRequest ¶
Types ¶
type CallHandler ¶
type CallHandler struct {
Path string
MaxLength int // default is 1Mb
ReadTimeout time.Duration // how long to wait for the request to be completed default is 30s
Handler func(c ctx.C, call *Call) error
}
func (CallHandler) Register ¶
func (this CallHandler) Register(s *Server)
type ResponseWriter ¶
type ResponseWriter = http.ResponseWriter
type Server ¶
type Server struct {
OpenAPI *openapi.Service
// ReadTimeout is the maximum duration for reading the entire
// request, including the body. A zero or negative value means
// there will be no timeout.
//
// Because ReadTimeout does not let Handlers make per-request
// decisions on each request body's acceptable deadline or
// upload rate, most users will prefer to use
// ReadHeaderTimeout. It is valid to use them both.
ReadTimeout time.Duration
// ReadHeaderTimeout is the amount of time allowed to read
// request headers. The connection's read deadline is reset
// after reading the headers and the Handler can decide what
// is considered too slow for the body. If zero, the value of
// ReadTimeout is used. If negative, or if zero and ReadTimeout
// is zero or negative, there is no timeout.
ReadHeaderTimeout time.Duration
// WriteTimeout is the maximum duration before timing out
// writes of the response. It is reset whenever a new
// request's header is read. Like ReadTimeout, it does not
// let Handlers make decisions on a per-request basis.
// A zero or negative value means there will be no timeout.
WriteTimeout time.Duration
// contains filtered or unexported fields
}
func (*Server) HandleFunc ¶
func (*Server) HandleRequest ¶
Setup the given request as JSON, and add it to `s.OpenAPI` for the given path as POST, returns the openapi.PathItem
func (*Server) HandleStream ¶
func (this *Server) HandleStream(path string, f StreamFunc) *openapi.PathItem
Setup the given streaming function, ignore the method, request body can be nil
func (*Server) MustRegisterAPI ¶
func (*Server) MustRegisterStreamingAPI ¶
func (*Server) RegisterAPI ¶
func (*Server) RegisterStreamingAPI ¶
func (*Server) SetupMonitoring ¶
register /pprof/ and /goroutines under the given prefix
type StreamFunc ¶
a streaming function with an option request body `in` and a function which sends chunks to the client
type Streamable ¶
type Streamable interface {
api.StreamingOp
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.