Documentation
¶
Index ¶
- func ClaimsFromContext(c echo.Context) *auth.JWTClaims
- func JWTFromCookieMiddleware(cookieName string) echo.MiddlewareFunc
- func JWTFromHeaderMiddleware() echo.MiddlewareFunc
- func JWTParserMiddleware(a *auth.Auth, companyRepo data.CompanyRepoer, userRepo data.UserRepoer) echo.MiddlewareFunc
- func RateLimit(cfg *config.Config, denyHandler echo.HandlerFunc) echo.MiddlewareFunc
- func UseCustomErrorHandler(e *echo.Echo)
- func UseGlobalMiddlewares(e *echo.Echo, cfg *config.Config)
- type AuthHandler
- type BranchHandler
- type CompanyHandler
- type CustomerHandler
- type ExpenseHandler
- type Handlers
- type OrderHandler
- type POSStationHandler
- type ProductHandler
- type Repos
- type SessionHandler
- type StockMovementHandler
- type SupplierHandler
- type SupplierPaymentHandler
- type UserHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClaimsFromContext ¶
ClaimsFromContext returns the JWT claims stored by JWTParserMiddleware, or nil.
func JWTFromCookieMiddleware ¶
func JWTFromCookieMiddleware(cookieName string) echo.MiddlewareFunc
JWTFromCookieMiddleware extracts a token from the named cookie and stores the raw token string in the context. Use on HTML route groups.
func JWTFromHeaderMiddleware ¶
func JWTFromHeaderMiddleware() echo.MiddlewareFunc
JWTFromHeaderMiddleware extracts a Bearer token from the Authorization header and stores the raw token string in the context. Use on JSON API route groups.
func JWTParserMiddleware ¶
func JWTParserMiddleware( a *auth.Auth, companyRepo data.CompanyRepoer, userRepo data.UserRepoer, ) echo.MiddlewareFunc
JWTParserMiddleware validates the JWT stored in the context. On success it wraps the context with withAuthUser so route handlers can access claims.
It also enforces per-user session invalidation: if userRepo reports a token_valid_after cutoff for the token's subject that is later than the token's own iat (issued-at) claim, the token is treated as invalid — the same as a signature/expiry failure — so a call to UserRepoer.InvalidateTokens takes effect immediately on the next request, not just on the next token refresh. A userRepo lookup error (e.g. the user was deleted) fails open: the request proceeds as if unrestricted, since downstream company/role checks already reject a nonexistent user.
func RateLimit ¶
func RateLimit(cfg *config.Config, denyHandler echo.HandlerFunc) echo.MiddlewareFunc
RateLimit returns a per-IP rate-limiting middleware — 5 requests/minute with a burst of 2, no-op in testing mode — deferring the "too many requests" response to denyHandler so callers can respond in their own format (JSON for the API, an HTML page for the web app). Each call builds its own store, so two routes each wrapped with their own RateLimit(...) call get independent per-IP buckets rather than sharing one.
func UseCustomErrorHandler ¶
UseCustomErrorHandler registers the error handler that maps *model.APIError to JSON.
Types ¶
type AuthHandler ¶
type AuthHandler struct {
// contains filtered or unexported fields
}
AuthHandler handles JSON API authentication endpoints.
func NewAuthHandler ¶
func NewAuthHandler(svc *service.AuthService) *AuthHandler
NewAuthHandler creates a new AuthHandler.
type BranchHandler ¶
type BranchHandler struct {
// contains filtered or unexported fields
}
BranchHandler handles HTTP requests for the /api/v1/branches routes.
func NewBranchHandler ¶
func NewBranchHandler(svc *service.BranchService) *BranchHandler
type CompanyHandler ¶
type CompanyHandler struct {
// contains filtered or unexported fields
}
CompanyHandler handles HTTP requests for the /api/v1/companies routes.
func NewCompanyHandler ¶
func NewCompanyHandler(svc *service.CompanyService) *CompanyHandler
type CustomerHandler ¶
type CustomerHandler struct {
// contains filtered or unexported fields
}
CustomerHandler handles HTTP requests for the /api/v1/customers routes.
func NewCustomerHandler ¶
func NewCustomerHandler(svc *service.CustomerService) *CustomerHandler
type ExpenseHandler ¶
type ExpenseHandler struct {
// contains filtered or unexported fields
}
ExpenseHandler handles HTTP requests for /api/v1/expenses.
func NewExpenseHandler ¶
func NewExpenseHandler(svc *service.ExpenseService) *ExpenseHandler
type Handlers ¶
type Handlers struct {
// contains filtered or unexported fields
}
Handlers wires services to their HTTP handlers.
func NewHandlers ¶
func NewHandlers( repos *Repos, authSvc *service.AuthService, a *auth.Auth, cfg *config.Config, ) *Handlers
NewHandlers builds all handlers from the given repos, auth service, and config.
func (*Handlers) FileHandler ¶
func (h *Handlers) FileHandler() *fileHandler
FileHandler exposes the file-download handler so core.NewApp can mount its public /files/:id route directly on the root Echo instance, outside the normal /api session-authenticated group (see fileHandler.ServeFile).
func (*Handlers) RegisterRoutes ¶
RegisterRoutes mounts all JSON API routes onto the /api group.
type OrderHandler ¶
type OrderHandler struct {
// contains filtered or unexported fields
}
OrderHandler handles HTTP requests for /api/v1/orders.
func NewOrderHandler ¶
func NewOrderHandler(svc *service.OrderService) *OrderHandler
NewOrderHandler constructs an OrderHandler.
type POSStationHandler ¶
type POSStationHandler struct {
// contains filtered or unexported fields
}
POSStationHandler handles HTTP requests for the /api/v1/stations routes.
func NewPOSStationHandler ¶
func NewPOSStationHandler(svc *service.POSStationService) *POSStationHandler
type ProductHandler ¶
type ProductHandler struct {
// contains filtered or unexported fields
}
ProductHandler handles HTTP requests for the /api/v1/products routes.
func NewProductHandler ¶
func NewProductHandler(svc *service.ProductService) *ProductHandler
type Repos ¶
type Repos struct {
UserRepo data.UserRepoer
CompanyRepo data.CompanyRepoer
BranchRepo data.BranchRepoer
StationRepo data.POSStationRepoer
CustomerRepo data.CustomerRepoer
SupplierRepo data.SupplierRepoer
ProductRepo data.ProductRepoer
InventoryRepo data.InventoryRepoer
ExpenseRepo data.ExpenseRepoer
SupplierPaymentRepo data.SupplierPaymentRepoer
SessionRepo data.SessionRepoer
OrderRepo data.OrderRepoer
AccountingRepo data.AccountingRepoer
ReportsRepo data.ReportsQuerier
DiscountRepo data.DiscountRepoer
FileRepo data.FileRepoer
FileStorage data.FileStorage
// FileAccessTTL is how long a local-storage presigned download URL (and
// the file-access JWT backing it) remains valid.
FileAccessTTL time.Duration
PaymentMethods []model.PaymentMethod
CashDrawerMethods []model.PaymentMethod
// Emitter receives domain events after each write operation.
// nil disables event dispatch (tests and installations without a job queue).
Emitter data.EventEmitter
}
Repos holds all repository implementations passed to the handler layer. The pro version injects its own implementations here.
type SessionHandler ¶
type SessionHandler struct {
// contains filtered or unexported fields
}
SessionHandler handles HTTP requests for /api/v1/sessions.
func NewSessionHandler ¶
func NewSessionHandler(svc *service.SessionService) *SessionHandler
NewSessionHandler constructs a SessionHandler.
type StockMovementHandler ¶
type StockMovementHandler struct {
// contains filtered or unexported fields
}
StockMovementHandler handles HTTP requests for /api/v1/stock-movements.
func NewStockMovementHandler ¶
func NewStockMovementHandler(svc *service.InventoryService) *StockMovementHandler
type SupplierHandler ¶
type SupplierHandler struct {
// contains filtered or unexported fields
}
SupplierHandler handles HTTP requests for the /api/v1/suppliers routes.
func NewSupplierHandler ¶
func NewSupplierHandler(svc *service.SupplierService) *SupplierHandler
type SupplierPaymentHandler ¶
type SupplierPaymentHandler struct {
// contains filtered or unexported fields
}
SupplierPaymentHandler handles HTTP requests for /api/v1/suppliers/:id/payments.
func NewSupplierPaymentHandler ¶
func NewSupplierPaymentHandler(svc *service.SupplierPaymentService) *SupplierPaymentHandler
type UserHandler ¶
type UserHandler struct {
// contains filtered or unexported fields
}
UserHandler handles HTTP requests for the /api/v1/users routes.
func NewUserHandler ¶
func NewUserHandler(svc *service.UserService) *UserHandler
NewUserHandler creates a new UserHandler.
Source Files
¶
- accounting_handler.go
- auth_handler.go
- branch_handler.go
- company_handler.go
- context_names.go
- customer_handler.go
- discount_handler.go
- entry.go
- errors.go
- expense_handler.go
- file_handler.go
- middleware.go
- order_handler.go
- product_handler.go
- reports_handler.go
- response.go
- route_middlewares.go
- session_handler.go
- station_handler.go
- stock_movement_handler.go
- supplier_handler.go
- supplier_payment_handler.go
- user_handler.go