Documentation ¶
Overview ¶
Package server provides a http service struct for a events service. All request and response structs and handlers for this service are located in this package.
Index ¶
- Constants
- func AboutHandler(about *About) func(httpRespW http.ResponseWriter, httpReq *http.Request)
- func AddNewApiKey(db *sql.DB, apiKey string, keyMsg string) error
- func CreateTemplates() *template.Template
- func EncodeAboutAsSchemaOrg(about *About, baseURL string) ([]byte, error)
- func EncodeDiscoveryAsISO19115(about *About) string
- func HealthzHandler(check func() (*Healthz, error)) http.HandlerFunc
- func InitializeJWTDB(db *sql.DB, NSC_creds_location string) error
- func ListApiKeys(db *sql.DB) error
- func MockProductEvent(httpRespW http.ResponseWriter, httpReq *http.Request)
- func NewEventsDB(filePath string) (*sql.DB, error)
- func NewJWTDB(filePath string, NSC_creds_location string) (*sql.DB, error)
- func NewServiceMetrics(opts MetricsOpts) *metrics
- func NewStateDB(filePath string) (*sql.DB, error)
- func RemoveApiKey(db *sql.DB, apiKey string) (bool, error)
- func ValidateApiKey(db *sql.DB, apiKey string) (bool, error)
- func ValidateJWTKey(db *sql.DB, JWTKey string) (bool, string, error)
- type About
- type HTTPServerError
- type Healthz
- type HealthzStatus
- type MetricsOpts
- type Product
- type Productstatus
- type Provider
- type Service
- type Version
- type WebAPISchemaOrg
Constants ¶
const ( HealthzStatusHealthy HealthzStatus = 0 HealthzStatusUnhealthy = 1 HealthzStatusCritical = 2 )
Variables ¶
This section is empty.
Functions ¶
func AboutHandler ¶
func AboutHandler(about *About) func(httpRespW http.ResponseWriter, httpReq *http.Request)
func AddNewApiKey ¶
AddNewApiKey adds a given key and message to the keys table. Invalid keys are rejected.
func CreateTemplates ¶
CreateTemplates creates templates from the template files statically built into the binary
func EncodeAboutAsSchemaOrg ¶
func HealthzHandler ¶
func HealthzHandler(check func() (*Healthz, error)) http.HandlerFunc
HealthzHandler runs the callback function check and serializes and sends the result of that check.
func InitializeJWTDB ¶ added in v0.1.1
func MockProductEvent ¶
func MockProductEvent(httpRespW http.ResponseWriter, httpReq *http.Request)
func NewEventsDB ¶
NewEventsDB returns an sql database object, initialized with necessary tables.
func NewJWTDB ¶ added in v0.1.1
NewStateDB returns an sql database object, initialised with necessary tables.
func NewServiceMetrics ¶
func NewServiceMetrics(opts MetricsOpts) *metrics
func NewStateDB ¶
NewStateDB returns an sql database object, initialised with necessary tables.
func RemoveApiKey ¶
RemoveApiKey removes a given key from the keys table. Invalid keys are rejected.
func ValidateApiKey ¶
ValidateApiKey checks a given key against the keys table. Invalid keys are rejected.
Types ¶
type About ¶
type About struct { Name string Description string Responsible string TermsOfService *url.URL Documentation *url.URL Version Version }
About contains "static" metadata information about a service. Use it to display healthz, discovery and internalstatus etc.
type HTTPServerError ¶
type HTTPServerError struct {
ErrMsg string `json:"error"`
}
HTTPServerError is used when the server fails to return a correct response to the user.
type Healthz ¶
type Healthz struct { Status HealthzStatus Description string }
type HealthzStatus ¶
type HealthzStatus int
func (HealthzStatus) String ¶
func (hltzStatus HealthzStatus) String() string
type MetricsOpts ¶
type Productstatus ¶
type Productstatus struct { Products map[string]Product GaugeVec *prometheus.GaugeVec }
func NewProductstatus ¶
func NewProductstatus(m *metrics) *Productstatus
func (*Productstatus) GetProductDelays ¶
func (p *Productstatus) GetProductDelays(t time.Time)
func (*Productstatus) Populate ¶
func (p *Productstatus) Populate(events []*mms.ProductEvent)
func (*Productstatus) PushEvent ¶
func (p *Productstatus) PushEvent(pe mms.ProductEvent) error
func (*Productstatus) UpdateMetrics ¶
func (p *Productstatus) UpdateMetrics()
type Service ¶
type Service struct { Router *mux.Router NatsURL string NatsCredentials nats.Option NatsLocal bool Metrics *metrics Productstatus *Productstatus Version Version // contains filtered or unexported fields }
Service is a struct that wires up all data that is needed for this service to run.
func NewService ¶
func NewService(templates *template.Template, eventsDB *sql.DB, stateDB *sql.DB, natsURL string, natsCredentials nats.Option, version Version, natsLocal bool) *Service
NewService creates a service struct, containing all that is needed for a mmsd server to run.
func (*Service) DeleteOldEvents ¶
DeleteOldEvents removes events older than a specified datetime.
func (*Service) GetAllEvents ¶
GetAllEvents returns all product events in the events database.