Documentation
¶
Index ¶
- func GetHealthManager(c Container) (shared.HealthManager, error)
- func GetLogger(c Container) (logger.Logger, error)
- func GetMetrics(c Container) (metrics.Metrics, error)
- func Must[T any](c Container, name string) T
- func MustScope[T any](s Scope, name string) T
- func RegisterInterface[I, T any](c Container, name string, factory func(Container) (T, error), ...) error
- func RegisterScoped[T any](c Container, name string, factory func(Container) (T, error)) error
- func RegisterScopedInterface[I, T any](c Container, name string, factory func(Container) (T, error)) error
- func RegisterSingleton[T any](c Container, name string, factory func(Container) (T, error)) error
- func RegisterSingletonInterface[I, T any](c Container, name string, factory func(Container) (T, error)) error
- func RegisterTransient[T any](c Container, name string, factory func(Container) (T, error)) error
- func RegisterTransientInterface[I, T any](c Container, name string, factory func(Container) (T, error)) error
- func RegisterValue[T any](c Container, name string, instance T) error
- func Resolve[T any](c Container, name string) (T, error)
- func ResolveScope[T any](s Scope, name string) (T, error)
- type Container
- type Context
- type ContextWithClean
- type Ctx
- func (c *Ctx) Bind(v any) error
- func (c *Ctx) BindJSON(v any) error
- func (c *Ctx) BindRequest(v any) error
- func (c *Ctx) BindXML(v any) error
- func (c *Ctx) Bytes(code int, data []byte) error
- func (c *Ctx) Cleanup()
- func (c *Ctx) Container() Container
- func (c *Ctx) Context() context.Context
- func (c *Ctx) Cookie(name string) (string, error)
- func (c *Ctx) DeleteCookie(name string)
- func (c *Ctx) DeleteSessionValue(key string)
- func (c *Ctx) DestroySession() error
- func (c *Ctx) Flush() error
- func (c *Ctx) FormFile(name string) (multipart.File, *multipart.FileHeader, error)
- func (c *Ctx) FormFiles(name string) ([]*multipart.FileHeader, error)
- func (c *Ctx) FormValue(name string) string
- func (c *Ctx) FormValues(name string) []string
- func (c *Ctx) Get(key string) any
- func (c *Ctx) GetAllCookies() map[string]string
- func (c *Ctx) GetSessionValue(key string) (any, bool)
- func (c *Ctx) HasCookie(name string) bool
- func (c *Ctx) Header(key string) string
- func (c *Ctx) HealthManager() HealthManager
- func (c *Ctx) JSON(code int, v any) error
- func (c *Ctx) Metrics() Metrics
- func (c *Ctx) Must(name string) any
- func (c *Ctx) MustGet(key string) any
- func (c *Ctx) NoContent(code int) error
- func (c *Ctx) Param(name string) string
- func (c *Ctx) ParamBool(name string) (bool, error)
- func (c *Ctx) ParamBoolDefault(name string, defaultValue bool) bool
- func (c *Ctx) ParamFloat64(name string) (float64, error)
- func (c *Ctx) ParamFloat64Default(name string, defaultValue float64) float64
- func (c *Ctx) ParamInt(name string) (int, error)
- func (c *Ctx) ParamInt64(name string) (int64, error)
- func (c *Ctx) ParamInt64Default(name string, defaultValue int64) int64
- func (c *Ctx) ParamIntDefault(name string, defaultValue int) int
- func (c *Ctx) Params() map[string]string
- func (c *Ctx) ParseMultipartForm(maxMemory int64) error
- func (c *Ctx) Query(name string) string
- func (c *Ctx) QueryDefault(name, defaultValue string) string
- func (c *Ctx) Redirect(code int, url string) error
- func (c *Ctx) Request() *http.Request
- func (c *Ctx) Resolve(name string) (any, error)
- func (c *Ctx) Response() http.ResponseWriter
- func (c *Ctx) SaveSession() error
- func (c *Ctx) Scope() Scope
- func (c *Ctx) Session() (shared.Session, error)
- func (c *Ctx) SessionID() string
- func (c *Ctx) Set(key string, value any)
- func (c *Ctx) SetCookie(name, value string, maxAge int)
- func (c *Ctx) SetCookieWithOptions(name, value string, path, domain string, maxAge int, secure, httpOnly bool)
- func (c *Ctx) SetHeader(key, value string)
- func (c *Ctx) SetSession(session shared.Session)
- func (c *Ctx) SetSessionValue(key string, value any)
- func (c *Ctx) Status(code int) shared.ResponseBuilder
- func (c *Ctx) String(code int, s string) error
- func (c *Ctx) WithContext(ctx context.Context)
- func (c *Ctx) WriteSSE(event string, data any) error
- func (c *Ctx) XML(code int, v any) error
- type DependencyGraph
- type Factory
- type HealthManager
- type Metrics
- type RegisterOption
- type ResponseBuilder
- func (rb *ResponseBuilder) Bytes(data []byte) error
- func (rb *ResponseBuilder) Header(key, value string) shared.ResponseBuilder
- func (rb *ResponseBuilder) JSON(v any) error
- func (rb *ResponseBuilder) NoContent() error
- func (rb *ResponseBuilder) String(s string) error
- func (rb *ResponseBuilder) XML(v any) error
- type Scope
- type ServiceInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetHealthManager ¶ added in v0.5.0
func GetHealthManager(c Container) (shared.HealthManager, error)
GetHealthManager resolves the health manager from the container This is a convenience function for resolving the health manager service The health manager type is defined in the forge package, so this returns the interface.
func GetLogger ¶ added in v0.5.0
GetLogger resolves the logger from the container This is a convenience function for resolving the logger service The logger type is defined in the forge package, so this returns interface{} and should be type-asserted to the appropriate logger interface.
func GetMetrics ¶ added in v0.5.0
GetMetrics resolves the metrics from the container This is a convenience function for resolving the metrics service The metrics type is defined in the forge package, so this returns interface{} and should be type-asserted to the appropriate metrics interface.
func RegisterInterface ¶
func RegisterInterface[I, T any](c Container, name string, factory func(Container) (T, error), opts ...RegisterOption) error
RegisterInterface registers an implementation as an interface Supports all lifecycle options (Singleton, Scoped, Transient).
func RegisterScoped ¶
RegisterScoped is a convenience wrapper for request-scoped services.
func RegisterScopedInterface ¶
func RegisterScopedInterface[I, T any](c Container, name string, factory func(Container) (T, error)) error
RegisterScopedInterface is a convenience wrapper.
func RegisterSingleton ¶
RegisterSingleton is a convenience wrapper.
func RegisterSingletonInterface ¶
func RegisterSingletonInterface[I, T any](c Container, name string, factory func(Container) (T, error)) error
RegisterSingletonInterface is a convenience wrapper.
func RegisterTransient ¶
RegisterTransient is a convenience wrapper.
func RegisterTransientInterface ¶
func RegisterTransientInterface[I, T any](c Container, name string, factory func(Container) (T, error)) error
RegisterTransientInterface is a convenience wrapper.
func RegisterValue ¶
RegisterValue registers a pre-built instance (always singleton).
Types ¶
type Context ¶
Context wraps http.Request with convenience methods.
func NewContext ¶
NewContext creates a new context.
type ContextWithClean ¶
type ContextWithClean interface {
Cleanup()
}
type Ctx ¶
type Ctx struct {
// contains filtered or unexported fields
}
Ctx implements Context interface.
func (*Ctx) BindRequest ¶ added in v0.5.0
BindRequest binds and validates request data from all sources (path, query, header, body). This method provides comprehensive request binding that:
- Binds path parameters from URL path segments (path:"name")
- Binds query parameters from URL query string (query:"name")
- Binds headers from HTTP headers (header:"name")
- Binds body fields from request body (json:"name" or body:"")
- Validates all fields using validation tags (required, minLength, etc.)
Example:
type CreateUserRequest struct {
TenantID string `path:"tenantId" description:"Tenant ID"`
DryRun bool `query:"dryRun" default:"false"`
APIKey string `header:"X-API-Key" required:"true"`
Name string `json:"name" minLength:"1" maxLength:"100"`
}
func handler(ctx forge.Context) error {
var req CreateUserRequest
if err := ctx.BindRequest(&req); err != nil {
return err // Returns ValidationErrors if validation fails
}
// All fields are now bound and validated
}
func (*Ctx) Cleanup ¶
func (c *Ctx) Cleanup()
Cleanup ends the scope (should be called after request).
func (*Ctx) DeleteCookie ¶ added in v0.4.0
DeleteCookie deletes a cookie by setting MaxAge to -1.
func (*Ctx) DeleteSessionValue ¶ added in v0.4.0
DeleteSessionValue deletes a value from the current session.
func (*Ctx) DestroySession ¶ added in v0.4.0
DestroySession removes the current session from the store.
func (*Ctx) Flush ¶ added in v0.7.0
Flush flushes any buffered response data to the client. Returns an error if the response writer doesn't support flushing.
func (*Ctx) FormFiles ¶
func (c *Ctx) FormFiles(name string) ([]*multipart.FileHeader, error)
FormFiles retrieves multiple files with the same field name from a multipart form.
func (*Ctx) FormValues ¶
FormValues retrieves all values for a form field.
func (*Ctx) GetAllCookies ¶ added in v0.4.0
GetAllCookies returns all cookies as a map.
func (*Ctx) GetSessionValue ¶ added in v0.4.0
GetSessionValue gets a value from the current session.
func (*Ctx) HealthManager ¶
func (c *Ctx) HealthManager() HealthManager
HealthManager returns the health manager.
func (*Ctx) JSON ¶
JSON sends JSON response. If v is a struct with header:"..." tags, those headers are set automatically. If v has a field with body:"" tag, that field's value is serialized instead of the whole struct. If the route has sensitive field cleaning enabled, fields with sensitive:"..." tags are processed.
func (*Ctx) ParamBoolDefault ¶ added in v0.4.0
ParamBoolDefault returns a path parameter as bool with default value.
func (*Ctx) ParamFloat64 ¶ added in v0.4.0
ParamFloat64 returns a path parameter as float64.
func (*Ctx) ParamFloat64Default ¶ added in v0.4.0
ParamFloat64Default returns a path parameter as float64 with default value.
func (*Ctx) ParamInt64 ¶ added in v0.4.0
ParamInt64 returns a path parameter as int64.
func (*Ctx) ParamInt64Default ¶ added in v0.4.0
ParamInt64Default returns a path parameter as int64 with default value.
func (*Ctx) ParamIntDefault ¶ added in v0.4.0
ParamIntDefault returns a path parameter as int with default value.
func (*Ctx) ParseMultipartForm ¶
ParseMultipartForm parses a multipart form with the specified max memory maxMemory: maximum memory in bytes to use for storing files in memory (rest goes to disk) Recommended values: 10MB (10<<20), 32MB (32<<20), 64MB (64<<20).
func (*Ctx) QueryDefault ¶
QueryDefault returns a query parameter with default value.
func (*Ctx) Response ¶
func (c *Ctx) Response() http.ResponseWriter
Response returns the HTTP response writer.
func (*Ctx) SaveSession ¶ added in v0.4.0
SaveSession saves the current session to the session store.
func (*Ctx) SetCookieWithOptions ¶ added in v0.4.0
func (c *Ctx) SetCookieWithOptions(name, value string, path, domain string, maxAge int, secure, httpOnly bool)
SetCookieWithOptions sets a cookie with full control over options.
func (*Ctx) SetSession ¶ added in v0.4.0
SetSession sets the current session in the context.
func (*Ctx) SetSessionValue ¶ added in v0.4.0
SetSessionValue sets a value in the current session.
func (*Ctx) Status ¶
func (c *Ctx) Status(code int) shared.ResponseBuilder
Status sets the HTTP status code and returns a builder for chaining.
func (*Ctx) WithContext ¶
WithContext replaces the request context.
type DependencyGraph ¶
type DependencyGraph struct {
// contains filtered or unexported fields
}
DependencyGraph manages service dependencies.
func NewDependencyGraph ¶
func NewDependencyGraph() *DependencyGraph
NewDependencyGraph creates a new dependency graph.
func (*DependencyGraph) AddNode ¶
func (g *DependencyGraph) AddNode(name string, dependencies []string)
AddNode adds a node with its dependencies. Nodes are processed in the order they are added (FIFO) when no dependencies exist.
func (*DependencyGraph) TopologicalSort ¶
func (g *DependencyGraph) TopologicalSort() ([]string, error)
TopologicalSort returns nodes in dependency order. Nodes without dependencies maintain their registration order (FIFO). Returns error if circular dependency detected.
type HealthManager ¶
type HealthManager = shared.HealthManager
type RegisterOption ¶
type RegisterOption = shared.RegisterOption
RegisterOption is a configuration option for service registration.
func Scoped ¶
func Scoped() RegisterOption
Scoped makes the service live for the duration of a scope.
func Transient ¶
func Transient() RegisterOption
Transient makes the service created on each resolve.
func WithDIMetadata ¶
func WithDIMetadata(key, value string) RegisterOption
WithDIMetadata adds diagnostic metadata to DI service registration.
func WithDependencies ¶
func WithDependencies(deps ...string) RegisterOption
WithDependencies declares explicit dependencies.
func WithGroup ¶
func WithGroup(group string) RegisterOption
WithGroup adds service to a named group.
type ResponseBuilder ¶
type ResponseBuilder struct {
// contains filtered or unexported fields
}
ResponseBuilder provides fluent response building.
func (*ResponseBuilder) Bytes ¶
func (rb *ResponseBuilder) Bytes(data []byte) error
Bytes sends a byte response with the configured status.
func (*ResponseBuilder) Header ¶
func (rb *ResponseBuilder) Header(key, value string) shared.ResponseBuilder
Header sets a response header and returns the builder for chaining.
func (*ResponseBuilder) JSON ¶
func (rb *ResponseBuilder) JSON(v any) error
JSON sends a JSON response with the configured status.
func (*ResponseBuilder) NoContent ¶
func (rb *ResponseBuilder) NoContent() error
NoContent sends a no-content response with the configured status.
func (*ResponseBuilder) String ¶
func (rb *ResponseBuilder) String(s string) error
String sends a string response with the configured status.
func (*ResponseBuilder) XML ¶
func (rb *ResponseBuilder) XML(v any) error
XML sends an XML response with the configured status.
type Scope ¶
Scope represents a lifetime scope for scoped services Typically used for HTTP requests or other bounded operations.
type ServiceInfo ¶
type ServiceInfo = shared.ServiceInfo
ServiceInfo contains diagnostic information.