Documentation
¶
Index ¶
- Constants
- func Api[Input any, Output IHttpOutput](group *ActionGroup, serializer ISerializer, ...)
- func DoAdminCall(cli *http.Client, checker IAdminChecker, req *http.Request) (*http.Response, error)
- func JSONApi[Input any, Output IHttpOutput](group *ActionGroup, ...)
- func MustPeekRequest(ctx context.Context) *http.Request
- func NewJsonRequest[T any](ctx context.Context, method string, url string, val T) (*http.Request, error)
- func NewSpeedLimitedRespWriter(ctx context.Context, writer http.ResponseWriter, kbs int) http.ResponseWriter
- func PeekRequest(ctx context.Context) (*http.Request, bool)
- func ServeGzipedFS(prefix string, fs http.FileSystem) http.HandlerFunc
- type ActionGroup
- func (group *ActionGroup) RawApi(fnc ApiAction, opts *ActionOptions)
- func (group *ActionGroup) ToHandler(actiongetter func(req *http.Request) string) http.Handler
- func (group *ActionGroup) WithConfig(cfg *Config) *ActionGroup
- func (group *ActionGroup) WithLogger(logger *slog.Logger) *ActionGroup
- func (group *ActionGroup) WithRemoteIpProvider(remoteipprovider IRemoteIPProvider) *ActionGroup
- func (group *ActionGroup) WithSessionProvider(sessionprovider ISessionProvider) *ActionGroup
- type ActionOptions
- type ApiAction
- type Config
- type GzippedOutput
- type IAdminChecker
- type IBind
- type IHttpError
- type IHttpOutput
- type IRemoteIPProvider
- type ISerializer
- type ISession
- type ISessionProvider
- type JsonBytesOutput
- type Output
- type PlainTextOutput
- type SessionPolicyKind
- type SpeedLimitedRespWriter
- type StringMap
Constants ¶
View Source
const (
MaxRequestBodySize = 1024_00
)
Variables ¶
This section is empty.
Functions ¶
func Api ¶
func Api[Input any, Output IHttpOutput]( group *ActionGroup, serializer ISerializer, fnc func(ctx context.Context, input *Input) (Output, error), opts *ActionOptions, )
func DoAdminCall ¶
func JSONApi ¶
func JSONApi[Input any, Output IHttpOutput]( group *ActionGroup, fnc func(ctx context.Context, input *Input) (Output, error), opts *ActionOptions, )
func NewJsonRequest ¶
func NewSpeedLimitedRespWriter ¶
func NewSpeedLimitedRespWriter(ctx context.Context, writer http.ResponseWriter, kbs int) http.ResponseWriter
func ServeGzipedFS ¶
func ServeGzipedFS(prefix string, fs http.FileSystem) http.HandlerFunc
ServeGzipedFS serves pre-gziped files.
Types ¶
type ActionGroup ¶
type ActionGroup struct {
// contains filtered or unexported fields
}
func NewGroup ¶
func NewGroup(module_prefix string, optsfnc func(opts *ActionOptions) *ActionOptions) *ActionGroup
func (*ActionGroup) RawApi ¶
func (group *ActionGroup) RawApi(fnc ApiAction, opts *ActionOptions)
func (*ActionGroup) WithConfig ¶
func (group *ActionGroup) WithConfig(cfg *Config) *ActionGroup
func (*ActionGroup) WithLogger ¶
func (group *ActionGroup) WithLogger(logger *slog.Logger) *ActionGroup
func (*ActionGroup) WithRemoteIpProvider ¶
func (group *ActionGroup) WithRemoteIpProvider(remoteipprovider IRemoteIPProvider) *ActionGroup
func (*ActionGroup) WithSessionProvider ¶
func (group *ActionGroup) WithSessionProvider(sessionprovider ISessionProvider) *ActionGroup
type ActionOptions ¶
type ActionOptions struct {
SessionPolicy SessionPolicyKind
RateLimitTakeN int
RequireAdmin bool
OnlyDebug bool
}
type Config ¶
type Config struct {
Debug bool
AdminAuthDir string
ErrorMap func(err error) (IHttpError, bool)
}
type GzippedOutput ¶
type GzippedOutput struct {
// contains filtered or unexported fields
}
func NewGzippedOutput ¶
func NewGzippedOutput(code int, content []byte, contentType string) *GzippedOutput
func (*GzippedOutput) BytesBody ¶
func (obj *GzippedOutput) BytesBody() ([]byte, bool)
func (*GzippedOutput) Code ¶
func (obj *GzippedOutput) Code() int
func (*GzippedOutput) Headers ¶
func (obj *GzippedOutput) Headers() http.Header
type IAdminChecker ¶
type IAdminChecker interface {
Check(ctx context.Context, ip string, req *http.Request) error
Do(ctx context.Context, cli *http.Client, req *http.Request) (*http.Response, error)
}
func NewFsAdminChecker ¶
func NewFsAdminChecker(secret string, fsdir string, header string, filesize int64) IAdminChecker
NewFsAdminChecker Help dockerized services to verify that admin requests from the host. It mandates a read-only mounted fsdir, rejecting all requests if write permission is detected.
type IHttpError ¶
func NewHttpError ¶
func NewHttpError(code int, fmt string, args ...any) IHttpError
type IHttpOutput ¶
type IRemoteIPProvider ¶
func NewHeadersRemoteIPProvider ¶
func NewHeadersRemoteIPProvider(headers ...string) IRemoteIPProvider
type ISerializer ¶
type ISerializer interface {
Deserialize(req *http.Request, dst any) error
Header() http.Header
Serialize(ctx context.Context, w io.Writer, src any) error
}
ISerializer impls not need to close req.Body in Deserialize method
var JSONSerializer ISerializer = _JsonSerializer{}
type ISessionProvider ¶
type JsonBytesOutput ¶
type JsonBytesOutput struct {
Txt []byte
}
func NewJsonBytesOutput ¶
func NewJsonBytesOutput[T any](val T) *JsonBytesOutput
func (*JsonBytesOutput) BytesBody ¶
func (j *JsonBytesOutput) BytesBody() ([]byte, bool)
func (*JsonBytesOutput) Code ¶
func (j *JsonBytesOutput) Code() int
func (*JsonBytesOutput) Headers ¶
func (j *JsonBytesOutput) Headers() http.Header
func (*JsonBytesOutput) MarshalJSON ¶
func (j *JsonBytesOutput) MarshalJSON() ([]byte, error)
type Output ¶
type Output[T any] struct { // contains filtered or unexported fields }
func (*Output[T]) MarshalJSON ¶
type PlainTextOutput ¶
type PlainTextOutput struct {
Txt string
}
func NewPlainTextOutput ¶
func NewPlainTextOutput(txt string) *PlainTextOutput
func (*PlainTextOutput) BytesBody ¶
func (p *PlainTextOutput) BytesBody() ([]byte, bool)
func (*PlainTextOutput) Code ¶
func (p *PlainTextOutput) Code() int
func (*PlainTextOutput) Headers ¶
func (p *PlainTextOutput) Headers() http.Header
func (*PlainTextOutput) MarshalJSON ¶
func (p *PlainTextOutput) MarshalJSON() ([]byte, error)
type SessionPolicyKind ¶
type SessionPolicyKind int
const ( SessionPolicyKindAuto SessionPolicyKind = iota SessionPolicyKindRequire SessionPolicyKindNone )
type SpeedLimitedRespWriter ¶
type SpeedLimitedRespWriter struct {
Writer http.ResponseWriter
*rate.Limiter
// contains filtered or unexported fields
}
func (*SpeedLimitedRespWriter) Header ¶
func (s *SpeedLimitedRespWriter) Header() http.Header
func (*SpeedLimitedRespWriter) Write ¶
func (s *SpeedLimitedRespWriter) Write(p []byte) (int, error)
func (*SpeedLimitedRespWriter) WriteHeader ¶
func (s *SpeedLimitedRespWriter) WriteHeader(statusCode int)
Click to show internal directories.
Click to hide internal directories.