server

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

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

View Source
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

func AddNewApiKey(db *sql.DB, apiKey string, keyMsg string) error

AddNewApiKey adds a given key and message to the keys table. Invalid keys are rejected.

func CreateTemplates

func CreateTemplates() *template.Template

CreateTemplates creates templates from the template files statically built into the binary

func EncodeAboutAsSchemaOrg

func EncodeAboutAsSchemaOrg(about *About, baseURL string) ([]byte, error)

func EncodeDiscoveryAsISO19115

func EncodeDiscoveryAsISO19115(about *About) string

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 InitializeJWTDB(db *sql.DB, NSC_creds_location string) error

func ListApiKeys

func ListApiKeys(db *sql.DB) error

ListApiKeys lists all keys in the keys table

func MockProductEvent

func MockProductEvent(httpRespW http.ResponseWriter, httpReq *http.Request)

func NewEventsDB

func NewEventsDB(filePath string) (*sql.DB, error)

NewEventsDB returns an sql database object, initialized with necessary tables.

func NewJWTDB added in v0.1.1

func NewJWTDB(filePath string, NSC_creds_location string) (*sql.DB, error)

NewStateDB returns an sql database object, initialised with necessary tables.

func NewServiceMetrics

func NewServiceMetrics(opts MetricsOpts) *metrics

func NewStateDB

func NewStateDB(filePath string) (*sql.DB, error)

NewStateDB returns an sql database object, initialised with necessary tables.

func RemoveApiKey

func RemoveApiKey(db *sql.DB, apiKey string) (bool, error)

RemoveApiKey removes a given key from the keys table. Invalid keys are rejected.

func ValidateApiKey

func ValidateApiKey(db *sql.DB, apiKey string) (bool, error)

ValidateApiKey checks a given key against the keys table. Invalid keys are rejected.

func ValidateJWTKey added in v0.1.1

func ValidateJWTKey(db *sql.DB, JWTKey string) (bool, string, error)

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 MetricsOpts struct {
	Name            string
	Description     string
	ResponseBuckets []float64
}

type Product

type Product struct {
	Name                 string
	NextInstanceExpected time.Time
}

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 Provider

type Provider struct {
	Ldtype string `json:"@type"`
	Name   string `json:"name"`
}

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

func (service *Service) DeleteOldEvents(maxAge time.Time) error

DeleteOldEvents removes events older than a specified datetime.

func (*Service) GetAllEvents

func (service *Service) GetAllEvents(ctx context.Context) ([]*mms.ProductEvent, error)

GetAllEvents returns all product events in the events database.

type Version added in v0.0.2

type Version struct {
	Version string
	Commit  string
	Date    string
}

Version and build information

type WebAPISchemaOrg

type WebAPISchemaOrg struct {
	Name          string   `json:"name"`
	Description   string   `json:"description"`
	ToS           string   `json:"termsOfService"`
	Documentation string   `json:"documentation"`
	Provider      Provider `json:"provider"`
}

Jump to

Keyboard shortcuts

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