support

package
v1.30.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package support implements an enterprise support ticketing system with priority routing, SLA tracking, and webhook notifications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TenantFromContext added in v1.12.0

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

TenantFromContext returns the authenticated tenant ID from the request context.

func ValidTransition

func ValidTransition(from, to Status) bool

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

func (a *API) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes registers all ticket API endpoints on the given mux.

type AddCommentRequest

type AddCommentRequest struct {
	Author string `json:"author"`
	Body   string `json:"body"`
}

AddCommentRequest is the JSON body for adding a comment.

type AuthFunc added in v1.12.0

type AuthFunc func(token string) (tenantID string, ok bool)

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 EventType

type EventType string

EventType identifies what happened to a ticket.

const (
	EventTicketCreated  EventType = "ticket.created"
	EventTicketTriaged  EventType = "ticket.triaged"
	EventTicketResolved EventType = "ticket.resolved"
	EventTicketClosed   EventType = "ticket.closed"
	EventCommentAdded   EventType = "ticket.comment_added"
	EventSLABreach      EventType = "sla.breach"
)

type Priority

type Priority int

Priority represents ticket urgency.

const (
	P0Critical Priority = iota
	P1High
	P2Medium
	P3Low
)

func (Priority) String

func (p Priority) String() string

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router assigns tickets to teams or individuals based on priority.

func NewRouter

func NewRouter(fallback string) *Router

NewRouter creates a router with the given fallback assignee used when no priority-specific rule matches.

func (*Router) AddRule

func (r *Router) AddRule(priority Priority, assignee string)

AddRule registers a routing rule for a specific priority.

func (*Router) Assign

func (r *Router) Assign(t *Ticket) error

Assign determines the assignee for a ticket based on its priority and updates the ticket's AssignedTo field. It also transitions the ticket to triaged status.

func (*Router) Route

func (r *Router) Route(t *Ticket, store *Store) error

Route assigns and triages the ticket in one step.

type RoutingRule

type RoutingRule struct {
	Priority Priority
	Assignee string
}

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 Status

type Status string

Status represents the lifecycle state of a ticket.

const (
	StatusOpen       Status = "open"
	StatusTriaged    Status = "triaged"
	StatusInProgress Status = "in_progress"
	StatusResolved   Status = "resolved"
	StatusClosed     Status = "closed"
)

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

func (s *Store) AddComment(ticketID, author, body string) (*Comment, error)

AddComment appends a comment to the ticket.

func (*Store) All

func (s *Store) All() []*Ticket

All returns every ticket in the store.

func (*Store) Create

func (s *Store) Create(customerID, subject, body string, priority Priority) *Ticket

Create adds a new ticket and returns it.

func (*Store) Get

func (s *Store) Get(id string) (*Ticket, bool)

Get returns a ticket by ID.

func (*Store) ListByCustomer

func (s *Store) ListByCustomer(customerID string) []*Ticket

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.

func (*Ticket) Transition

func (t *Ticket) Transition(to Status, now time.Time) error

Transition moves the ticket to a new status, returning an error if the transition is invalid.

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.

Jump to

Keyboard shortcuts

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