Documentation
¶
Index ¶
- type Config
- type DirectoryEntry
- type DirectoryIndexingType
- type DirectoryListing
- type FileUploadHandlerConfig
- type FileUploadHandlerOption
- type FileUploadPostprocessor
- type FilenamePrependType
- type Group
- func (g *Group) DELETE(pattern string, handler http.HandlerFunc, middlewares ...middleware.Middleware)
- func (g *Group) GET(pattern string, handler http.HandlerFunc, middlewares ...middleware.Middleware)
- func (g *Group) Group(subPrefix string, middlewares ...middleware.Middleware) *Group
- func (g *Group) Handle(method, pattern string, handler http.Handler, ...)
- func (g *Group) HandleFunc(method, pattern string, handler http.HandlerFunc, ...)
- func (g *Group) OPTIONS(pattern string, handler http.HandlerFunc, middlewares ...middleware.Middleware)
- func (g *Group) PATCH(pattern string, handler http.HandlerFunc, middlewares ...middleware.Middleware)
- func (g *Group) POST(pattern string, handler http.HandlerFunc, middlewares ...middleware.Middleware)
- func (g *Group) PUT(pattern string, handler http.HandlerFunc, middlewares ...middleware.Middleware)
- func (g *Group) Use(middlewares ...middleware.Middleware)
- type GroupConfig
- type RouteConfig
- type Router
- type Server
- func (s *Server) EchoHandler(w http.ResponseWriter, r *http.Request)
- func (s *Server) FileUploadHandler(uploadsDir string, opts ...FileUploadHandlerOption) http.HandlerFunc
- func (s *Server) GetHTTPListenerAddr() net.Addr
- func (s *Server) GetHTTPSListenerAddr() net.Addr
- func (s *Server) GetListenerAddr() net.Addr
- func (s *Server) GetLogger() *slog.Logger
- func (s *Server) GetMux() *http.ServeMux
- func (s *Server) GetRootGroup() *Group
- func (s *Server) HealthHandler(w http.ResponseWriter, _ *http.Request)
- func (s *Server) Start(ctx context.Context, router *Router) error
- func (s *Server) Stop(ctx context.Context) error
- type StaticRouteConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
ListenAddress string `env:"HTTP_SERVER_LISTENADDRESS"`
ReadTimeout time.Duration `env:"HTTP_SERVER_READTIMEOUT"`
ReadHeaderTimeout time.Duration `env:"HTTP_SERVER_READHEADERTIMEOUT"`
WriteTimeout time.Duration `env:"HTTP_SERVER_WRITETIMEOUT"`
IdleTimeout time.Duration `env:"HTTP_SERVER_IDLETIMEOUT"`
MaxHeaderBytes int `env:"HTTP_SERVER_MAXHEADERBYTES"`
ShutdownTimeout time.Duration `env:"HTTP_SERVER_SHUTDOWNTIMEOUT"`
ServiceName string `env:"HTTP_SERVER_SERVICENAME"`
FileUploadMaxMemory int64 `env:"HTTP_SERVER_FILEUPLOADMAXMEMORY"`
TLSEnabled bool `env:"HTTP_SERVER_TLSENABLED"`
TLSListenAddress string `env:"HTTP_SERVER_TLSLISTENADDRESS"`
TLSCertFile string `env:"HTTP_SERVER_TLSCERTFILE"`
TLSKeyFile string `env:"HTTP_SERVER_TLSKEYFILE"`
}
type DirectoryEntry ¶
type DirectoryIndexingType ¶
type DirectoryIndexingType uint
const ( DirectoryIndexingTypeNone DirectoryIndexingType = iota // No indexing (0) DirectoryIndexingTypeHTML // HTML listing DirectoryIndexingTypeJSON // JSON listing )
type DirectoryListing ¶
type DirectoryListing struct {
Path string `json:"path"`
Parent string `json:"parent,omitempty"`
Entries []DirectoryEntry `json:"entries"`
}
type FileUploadHandlerConfig ¶
type FileUploadHandlerConfig struct {
// contains filtered or unexported fields
}
FileUploadHandlerConfig holds the configuration for the file upload handler.
type FileUploadHandlerOption ¶
type FileUploadHandlerOption func(*FileUploadHandlerConfig)
func WithFileUploadHandlerPostprocessor ¶
func WithFileUploadHandlerPostprocessor( processor FileUploadPostprocessor, ) FileUploadHandlerOption
WithFileUploadHandlerPostprocessor sets a postprocessor that modifies the response.
func WithFilenamePrependType ¶
func WithFilenamePrependType( prependType FilenamePrependType, ) FileUploadHandlerOption
WithFilenamePrependType sets the type of prefix to add to uploaded filenames.
type FileUploadPostprocessor ¶
type FileUploadPostprocessor func( response map[string]any, request *http.Request, ) (map[string]any, error)
FileUploadPostprocessor defines the function signature for processing file upload responses.
type FilenamePrependType ¶
type FilenamePrependType uint8
const ( // FilenamePrependTypeNone does not add any prefix to the filename. FilenamePrependTypeNone FilenamePrependType = iota // FilenamePrependTypeDateTime prepends date and time in Y_M_D_H_I_S format. FilenamePrependTypeDateTime // FilenamePrependTypeUUID prepends a UUID4 to the filename (default). FilenamePrependTypeUUID )
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
func NewGroup ¶
func NewGroup( mux *http.ServeMux, prefix string, logger *slog.Logger, middlewares ...middleware.Middleware, ) *Group
func (*Group) DELETE ¶
func (g *Group) DELETE( pattern string, handler http.HandlerFunc, middlewares ...middleware.Middleware, )
func (*Group) GET ¶
func (g *Group) GET( pattern string, handler http.HandlerFunc, middlewares ...middleware.Middleware, )
func (*Group) Group ¶
func (g *Group) Group( subPrefix string, middlewares ...middleware.Middleware, ) *Group
func (*Group) Handle ¶
func (g *Group) Handle( method, pattern string, handler http.Handler, middlewares ...middleware.Middleware, )
Handle registers a handler for the given method and pattern.
func (*Group) HandleFunc ¶
func (g *Group) HandleFunc( method, pattern string, handler http.HandlerFunc, middlewares ...middleware.Middleware, )
HandleFunc is a convenience method for registering http.HandlerFunc.
func (*Group) OPTIONS ¶
func (g *Group) OPTIONS( pattern string, handler http.HandlerFunc, middlewares ...middleware.Middleware, )
func (*Group) PATCH ¶
func (g *Group) PATCH( pattern string, handler http.HandlerFunc, middlewares ...middleware.Middleware, )
func (*Group) POST ¶
func (g *Group) POST( pattern string, handler http.HandlerFunc, middlewares ...middleware.Middleware, )
func (*Group) PUT ¶
func (g *Group) PUT( pattern string, handler http.HandlerFunc, middlewares ...middleware.Middleware, )
func (*Group) Use ¶
func (g *Group) Use(middlewares ...middleware.Middleware)
type GroupConfig ¶
type GroupConfig struct {
Path string
Middlewares []middleware.Middleware
Routes []RouteConfig
Groups []GroupConfig // Nested groups
}
type RouteConfig ¶
type RouteConfig struct {
Method string // http.MethodGet, http.MethodPost, etc.
Path string // "/users/{id}", etc.
Handler http.HandlerFunc // Handler function
}
type Router ¶
type Router struct {
// Global middleware settings
GlobalMiddlewares []middleware.Middleware
// Multiple static file routes
Static []StaticRouteConfig
// Route groups
Groups []GroupConfig
// contains filtered or unexported fields
}
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewWithConfig ¶
func NewWithConfigAndLogger ¶
func (*Server) EchoHandler ¶
func (s *Server) EchoHandler( w http.ResponseWriter, r *http.Request, )
EchoHandler echoes back request information (useful for testing).
func (*Server) FileUploadHandler ¶
func (s *Server) FileUploadHandler( uploadsDir string, opts ...FileUploadHandlerOption, ) http.HandlerFunc
FileUploadHandler returns a handler for file uploads to the specified directory.
func (*Server) GetHTTPListenerAddr ¶
GetHTTPListenerAddr returns the HTTP listener address if the server is running.
func (*Server) GetHTTPSListenerAddr ¶
GetHTTPSListenerAddr returns the HTTPS listener address if the server is running with TLS.
func (*Server) GetListenerAddr ¶
GetListenerAddr returns the HTTP listener address if the server is running Deprecated: Use GetHTTPListenerAddr() instead.
func (*Server) GetRootGroup ¶
func (*Server) HealthHandler ¶
func (s *Server) HealthHandler( w http.ResponseWriter, _ *http.Request, )
HealthHandler provides a basic health check endpoint.
type StaticRouteConfig ¶
type StaticRouteConfig struct {
Dir string // Directory to serve files from
Path string // URL path prefix to serve on
DirectoryIndexingType DirectoryIndexingType // Directory indexing type
}