server

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package server provides the HTTP server for the TODO

Index

Constants

This section is empty.

Variables

View Source
var ErrNoNATSConnection = errors.New("no NATS connection")

ErrNoNATSConnection is returned when there is no NATS connection

Functions

This section is empty.

Types

type EventClient

type EventClient interface {
	Subscribe(ctx context.Context, subject string) error
	Messages() <-chan *EventMessage
	Shutdown() error
}

EventClient is an interface for the event client

type EventMessage

type EventMessage struct {
	Subject string
	Event   *govevents.Event
}

EventMessage is a wrapper for a governor event message

type NATSClient

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

NATSClient is a NATS client with some configuration

func NewNATSClient

func NewNATSClient(opts ...NATSOption) (*NATSClient, error)

NewNATSClient configures and establishes a new NATS client connection

func (*NATSClient) Messages

func (c *NATSClient) Messages() <-chan *EventMessage

Messages returns a channel of messages

func (*NATSClient) Shutdown

func (c *NATSClient) Shutdown() error

Shutdown drains and closes the NATS connection

func (*NATSClient) Subscribe

func (c *NATSClient) Subscribe(ctx context.Context, subject string) error

Subscribe creates a subscription to the NATS subject

type NATSOption

type NATSOption func(c *NATSClient)

NATSOption is a functional configuration option for NATS

func WithNATSConn

func WithNATSConn(nc *nats.Conn) NATSOption

WithNATSConn sets the nats connection

func WithNATSLogger

func WithNATSLogger(l *zap.Logger) NATSOption

WithNATSLogger sets the NATS client logger

func WithNATSPrefix

func WithNATSPrefix(p string) NATSOption

WithNATSPrefix sets the nats subscription prefix

func WithNATSQueueGroup

func WithNATSQueueGroup(q string, s int) NATSOption

WithNATSQueueGroup sets the nats subscription queue group

func WithNATSTracer

func WithNATSTracer(t trace.Tracer) NATSOption

WithNATSTracer sets the NATS client tracer

type Option

type Option func(*Server)

Option is a function that configures a Server

func WithAuditFileWriter

func WithAuditFileWriter(w io.Writer) Option

WithAuditFileWriter sets the audit file writer for the server

func WithDebug

func WithDebug(dbg bool) Option

WithDebug sets the debug flag for the server

func WithEventProcessor

func WithEventProcessor(p eventprocessor.EventProcessor) Option

WithEventProcessor adds an event processor to the server

func WithEventRouter

func WithEventRouter(er eventrouter.EventRouter) Option

WithEventRouter sets the event router for the server

func WithGovernorClient

func WithGovernorClient(c *governor.Client) Option

WithGovernorClient sets the governor client for the server

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger sets the logger for the server

func WithNATSClient

func WithNATSClient(c *NATSClient) Option

WithNATSClient sets the nats client for the server

func WithTracer

func WithTracer(t trace.Tracer) Option

WithTracer sets the tracer for the server

type Server

type Server struct {
	Listen          string
	Debug           bool
	AuditFileWriter io.Writer
	// contains filtered or unexported fields
}

Server implements the HTTP Server

func NewServer

func NewServer(
	listen, extensionID, erdDir string,
	opts ...Option,
) *Server

NewServer creates a new HTTP server

func (*Server) Bootstrap

func (s *Server) Bootstrap(ctx context.Context) error

Bootstrap is a function that bootstraps the extension it is called by the server after it has started

  1. extension check if it is registered
  2. extension check if it is enabled
  3. compare local ERDs with ERDs from governor, only create new ERDs if they don't exist in governor. Since ERDs are immutable, the extension will not attempt to update the ERDs if it was changed by the developer.

func (*Server) ListenEvents

func (s *Server) ListenEvents(ctx context.Context)

ListenEvents listens for events from the governor api

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run will start the server listening on the specified address

func (*Server) Subscribe

func (s *Server) Subscribe(ctx context.Context) error

Subscribe subscribes to all subjects related to the extension

type Status

type Status string

Status is an enum type for the server status

const (
	// StatusUp is the status when the server is up
	StatusUp Status = "UP"
	// StatusDisabled is the status when the extension is disabled
	StatusDisabled Status = "DISABLED"
	// StatusBootstrapping is the status when the server is bootstrapping
	StatusBootstrapping Status = "BOOTSTRAPPING"
)

Jump to

Keyboard shortcuts

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