backend

package
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2026 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestIDFromCtx

func RequestIDFromCtx(ctx context.Context) (string, bool)

func RequestLogger

func RequestLogger(l *logrus.Logger, debugPaths ...string) func(http.Handler) http.Handler

RequestLogger logs basic request info.

func SecurityHeaders

func SecurityHeaders() func(http.Handler) http.Handler

SecurityHeaders adds common security-related headers to all responses.

func UserIDFromCtx

func UserIDFromCtx(ctx context.Context) (string, bool)

func WithUserID

func WithUserID(ctx context.Context, uid string) context.Context

Types

type Config

type Config struct {
	Store           *storage.Store
	Logger          *logrus.Logger
	Version         string
	CORSAllowOrigin []string
	Monitoring      MonitoringConfig

	JWTSecret  string
	AccessTTL  time.Duration
	RefreshTTL time.Duration

	AuditLogTTL time.Duration

	OAuth        oauth.Config
	BotAPIKey    string
	SessionStore sessions.SessionStore

	DevLoginEnabled bool
	SkipWorkers     bool
}

type MonitoringConfig

type MonitoringConfig struct {
	MetricsEndpoint string
	HealthzEndpoint string
}

type OAuthAuthorizationServerMetadata added in v0.0.3

type OAuthAuthorizationServerMetadata struct {
	Issuer                 string   `json:"issuer"`
	AuthorizationEndpoint  string   `json:"authorization_endpoint,omitempty"`
	TokenEndpoint          string   `json:"token_endpoint,omitempty"`
	RegistrationEndpoint   string   `json:"registration_endpoint,omitempty"`
	UserinfoEndpoint       string   `json:"userinfo_endpoint,omitempty"`
	ScopesSupported        []string `json:"scopes_supported,omitempty"`
	ResponseTypesSupported []string `json:"response_types_supported,omitempty"`
	GrantTypesSupported    []string `json:"grant_types_supported,omitempty"`

	// Custom CatWatch metadata to replace /api/config
	Config struct {
		GoogleEnabled bool `json:"google_enabled"`
		OIDCEnabled   bool `json:"oidc_enabled"`
		DevLogin      bool `json:"dev_login"`
	} `json:"x_catwatch_config"`
}

OAuthAuthorizationServerMetadata represents OAuth 2.0 Authorization Server Metadata (RFC 8414).

type PublicCat

type PublicCat struct {
	ID            string                `json:"id"`
	Name          string                `json:"name"`
	Description   string                `json:"description,omitempty"`
	Color         string                `json:"color,omitempty"`
	BirthDate     *time.Time            `json:"birth_date,omitempty"`
	Gender        string                `json:"gender"`
	IsSterilized  bool                  `json:"is_sterilized"`
	Condition     int                   `json:"condition"`
	NeedAttention bool                  `json:"need_attention"`
	Tags          []storage.Tag         `json:"tags,omitempty"`
	LastSeen      *time.Time            `json:"last_seen,omitempty"`
	Locations     []storage.CatLocation `json:"locations,omitempty"`
	Images        []storage.Image       `json:"images,omitempty"`
	Likes         int64                 `json:"likes"`
	Liked         bool                  `json:"liked"`
	CreatedAt     time.Time             `json:"created_at"`
	Records       any                   `json:"records,omitempty"`
}

func ToPublicCat

func ToPublicCat(c storage.Cat) PublicCat

type PublicRecord

type PublicRecord struct {
	ID        string     `json:"id"`
	Type      string     `json:"type"`
	Timestamp time.Time  `json:"timestamp"`
	DoneAt    *time.Time `json:"done_at,omitempty"`
}

func ToPublicRecord

func ToPublicRecord(r storage.Record) PublicRecord

type Server

type Server struct {
	Router chi.Router
	// contains filtered or unexported fields
}

func NewServer

func NewServer(cfg Config) (*Server, error)

func (*Server) AuditMiddleware

func (s *Server) AuditMiddleware(next http.Handler) http.Handler

AuditMiddleware logs mutations to the AuditLog table.

func (*Server) BotKeyAuth added in v0.0.8

func (s *Server) BotKeyAuth(next http.Handler) http.Handler

BotKeyAuth requires a valid X-Bot-Key header on every request. If BotAPIKey is not configured the endpoint is closed to all callers.

func (*Server) CSRFProtection added in v0.0.3

func (s *Server) CSRFProtection(next http.Handler) http.Handler

CSRFProtection implements a simple CSRF check for state-changing requests.

func (*Server) DevEnabled added in v0.0.6

func (s *Server) DevEnabled() bool

func (*Server) GoogleEnabled added in v0.0.6

func (s *Server) GoogleEnabled() bool

func (*Server) JWTAuth

func (s *Server) JWTAuth(next http.Handler) http.Handler

func (*Server) LogAudit

func (s *Server) LogAudit(r *http.Request, targetType, targetID, status, delta string)

func (*Server) OIDCEnabled added in v0.0.6

func (s *Server) OIDCEnabled() bool

func (*Server) RequireAuth

func (s *Server) RequireAuth(next http.Handler) http.Handler

RequireAuth middleware ensures user is authenticated.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL