Documentation
¶
Overview ¶
Package support implements an enterprise support ticketing system with priority routing, SLA tracking, and webhook notifications.
Index ¶
- func TenantFromContext(ctx context.Context) (string, bool)
- func ValidTransition(from, to Status) bool
- type API
- func (a *API) AddComment(w http.ResponseWriter, r *http.Request)
- func (a *API) CloseTicket(w http.ResponseWriter, r *http.Request)
- func (a *API) CreateTicket(w http.ResponseWriter, r *http.Request)
- func (a *API) GetTicket(w http.ResponseWriter, r *http.Request)
- func (a *API) ListTickets(w http.ResponseWriter, r *http.Request)
- func (a *API) RegisterRoutes(mux *http.ServeMux)
- type AddCommentRequest
- type AuthFunc
- type BboltStoreBackend
- func (b *BboltStoreBackend) All() []*Ticket
- func (b *BboltStoreBackend) Close() error
- func (b *BboltStoreBackend) Delete(id string) error
- func (b *BboltStoreBackend) Get(id string) (*Ticket, bool)
- func (b *BboltStoreBackend) ListByCustomer(customerID string) []*Ticket
- func (b *BboltStoreBackend) Save(ticket *Ticket) error
- type Breach
- type BreachHandler
- type BreachType
- type Comment
- type CreateTicketRequest
- type EventType
- type Priority
- type Router
- type RoutingRule
- type SLAPolicy
- type SLATracker
- type Status
- type Store
- type StoreOption
- type Ticket
- type TicketStoreBackend
- type WebhookDispatcher
- type WebhookEvent
- type WebhookTarget
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TenantFromContext ¶ added in v1.12.0
TenantFromContext returns the authenticated tenant ID from the request context.
func ValidTransition ¶
ValidTransition reports whether transitioning from one status to another is allowed.
Types ¶
type API ¶
type API struct {
Store *Store
Router *Router
SLA *SLATracker
Webhooks *WebhookDispatcher
Auth AuthFunc
}
API provides HTTP handlers for the customer support portal.
func (*API) AddComment ¶
func (a *API) AddComment(w http.ResponseWriter, r *http.Request)
AddComment handles POST /support/tickets/{id}/comments.
func (*API) CloseTicket ¶
func (a *API) CloseTicket(w http.ResponseWriter, r *http.Request)
CloseTicket handles POST /support/tickets/{id}/close.
func (*API) CreateTicket ¶
func (a *API) CreateTicket(w http.ResponseWriter, r *http.Request)
CreateTicket handles POST /support/tickets.
func (*API) GetTicket ¶
func (a *API) GetTicket(w http.ResponseWriter, r *http.Request)
GetTicket handles GET /support/tickets/{id}.
func (*API) ListTickets ¶
func (a *API) ListTickets(w http.ResponseWriter, r *http.Request)
ListTickets handles GET /support/tickets?customer_id=...
func (*API) RegisterRoutes ¶
RegisterRoutes registers all ticket API endpoints on the given mux.
type AddCommentRequest ¶
AddCommentRequest is the JSON body for adding a comment.
type AuthFunc ¶ added in v1.12.0
AuthFunc validates a Bearer token and returns the associated tenant ID. If the token is invalid, it returns an empty string and false.
type BboltStoreBackend ¶ added in v1.17.0
type BboltStoreBackend struct {
// contains filtered or unexported fields
}
BboltStoreBackend persists tickets in a bbolt database.
func NewBboltStoreBackend ¶ added in v1.17.0
func NewBboltStoreBackend(path string) (*BboltStoreBackend, error)
NewBboltStoreBackend opens or creates a bbolt database at path and returns a backend ready for use with NewStore(WithStoreBackend(...)).
func (*BboltStoreBackend) All ¶ added in v1.17.0
func (b *BboltStoreBackend) All() []*Ticket
All returns every ticket in the database.
func (*BboltStoreBackend) Close ¶ added in v1.17.0
func (b *BboltStoreBackend) Close() error
Close closes the underlying bbolt database.
func (*BboltStoreBackend) Delete ¶ added in v1.17.0
func (b *BboltStoreBackend) Delete(id string) error
Delete removes a ticket by ID.
func (*BboltStoreBackend) Get ¶ added in v1.17.0
func (b *BboltStoreBackend) Get(id string) (*Ticket, bool)
Get retrieves a ticket by ID.
func (*BboltStoreBackend) ListByCustomer ¶ added in v1.17.0
func (b *BboltStoreBackend) ListByCustomer(customerID string) []*Ticket
ListByCustomer returns all tickets belonging to the given customer.
func (*BboltStoreBackend) Save ¶ added in v1.17.0
func (b *BboltStoreBackend) Save(ticket *Ticket) error
Save persists a ticket as JSON keyed by its ID.
type Breach ¶
type Breach struct {
TicketID string
Type BreachType
Priority Priority
Deadline time.Time
BreachedAt time.Time
}
Breach records an SLA violation.
type BreachHandler ¶
type BreachHandler func(Breach)
BreachHandler is called when an SLA breach is detected.
type BreachType ¶
type BreachType string
BreachType indicates which SLA target was breached.
const ( BreachResponse BreachType = "response" BreachResolution BreachType = "resolution" )
type Comment ¶
type Comment struct {
ID string `json:"id"`
Author string `json:"author"`
Body string `json:"body"`
CreatedAt time.Time `json:"created_at"`
}
Comment is a message attached to a ticket.
type CreateTicketRequest ¶
type CreateTicketRequest struct {
CustomerID string `json:"customer_id"`
Subject string `json:"subject"`
Body string `json:"body"`
Priority Priority `json:"priority"`
}
CreateTicketRequest is the JSON body for creating a ticket.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router assigns tickets to teams or individuals based on priority.
func NewRouter ¶
NewRouter creates a router with the given fallback assignee used when no priority-specific rule matches.
type RoutingRule ¶
RoutingRule maps a priority to an assignee (team or individual).
type SLAPolicy ¶
type SLAPolicy struct {
Priority Priority
ResponseTime time.Duration // max time to first response (triage)
ResolutionTime time.Duration // max time to resolution
}
SLAPolicy defines response and resolution time targets for a priority level.
func DefaultSLAPolicies ¶
func DefaultSLAPolicies() []SLAPolicy
DefaultSLAPolicies returns standard enterprise SLA targets.
type SLATracker ¶
type SLATracker struct {
// contains filtered or unexported fields
}
SLATracker monitors tickets against SLA policies and fires breach alerts.
func NewSLATracker ¶
func NewSLATracker(policies []SLAPolicy) *SLATracker
NewSLATracker creates a tracker with the given policies.
func (*SLATracker) Check ¶
func (s *SLATracker) Check(t *Ticket, now time.Time) []Breach
Check evaluates whether a ticket has breached its SLA at the given time. It returns any breaches found.
func (*SLATracker) CheckAll ¶
func (s *SLATracker) CheckAll(store *Store, now time.Time) []Breach
CheckAll evaluates all tickets in a store for SLA breaches.
func (*SLATracker) OnBreach ¶
func (s *SLATracker) OnBreach(h BreachHandler)
OnBreach registers a handler that is called when a breach is detected.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a thread-safe ticket store backed by a pluggable storage backend.
func NewStore ¶
func NewStore(opts ...StoreOption) *Store
NewStore creates a ticket store. By default it uses an in-memory backend. Use WithStoreBackend to supply a persistent backend.
func (*Store) AddComment ¶
AddComment appends a comment to the ticket.
func (*Store) ListByCustomer ¶
ListByCustomer returns all tickets for a customer, ordered by creation time (newest first).
type StoreOption ¶ added in v1.17.0
type StoreOption func(*Store)
StoreOption configures a Store.
func WithStoreBackend ¶ added in v1.17.0
func WithStoreBackend(b TicketStoreBackend) StoreOption
WithStoreBackend sets the persistence backend for the Store.
type Ticket ¶
type Ticket struct {
ID string `json:"id"`
CustomerID string `json:"customer_id"`
Subject string `json:"subject"`
Body string `json:"body"`
Priority Priority `json:"priority"`
Status Status `json:"status"`
AssignedTo string `json:"assigned_to,omitempty"`
Comments []Comment `json:"comments,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ResolvedAt time.Time `json:"resolved_at,omitempty"`
ClosedAt time.Time `json:"closed_at,omitempty"`
}
Ticket is the core data model for a support ticket.
type TicketStoreBackend ¶ added in v1.17.0
type TicketStoreBackend interface {
Save(ticket *Ticket) error
Get(id string) (*Ticket, bool)
ListByCustomer(customerID string) []*Ticket
Delete(id string) error
}
TicketStoreBackend defines the persistence interface for ticket storage.
type WebhookDispatcher ¶
type WebhookDispatcher struct {
// contains filtered or unexported fields
}
WebhookDispatcher sends events to registered webhook targets.
func NewWebhookDispatcher ¶
func NewWebhookDispatcher() *WebhookDispatcher
NewWebhookDispatcher creates a dispatcher with an SSRF-safe HTTP client that blocks connections to loopback, private, link-local, and cloud metadata IP addresses.
func (*WebhookDispatcher) Dispatch ¶
func (d *WebhookDispatcher) Dispatch(ctx context.Context, event WebhookEvent) []error
Dispatch sends an event to all matching targets. It returns errors for any failed deliveries but does not stop on first failure.
func (*WebhookDispatcher) Register ¶
func (d *WebhookDispatcher) Register(target WebhookTarget)
Register adds a webhook target.
func (*WebhookDispatcher) Targets ¶
func (d *WebhookDispatcher) Targets() []WebhookTarget
Targets returns the list of registered webhook targets.
type WebhookEvent ¶
type WebhookEvent struct {
Type EventType `json:"type"`
Timestamp time.Time `json:"timestamp"`
Payload interface{} `json:"payload"`
}
WebhookEvent is the payload sent to registered webhook endpoints.
type WebhookTarget ¶
type WebhookTarget struct {
Name string // e.g. "slack", "pagerduty"
URL string
Events []EventType // empty means all events
}
WebhookTarget is a registered endpoint for receiving notifications.