rest

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

README

REST api server

Deployment

LOG_LEVEL

LOG_LEVEL defines the level of logging. Valid levels are debug, warn, info, and error.

LOG_LEVEL="info"
SERVER_ADDR

SERVER_ADDR defines the address the Alexandria API service will listen to. This is required.

SERVER_ADDR=:443
TLS_CERT / TLS_KEY / TLS_CACERT / MTLS_ENABLED

TLS_CERT and TLS_KEY define the file path where the certificates used to serve https traffic are stored. These are optional.

When MTLS_ENABLED is set to true, TLS_CACERT defines the path to the CA certifcate of the client used to enable mutual TLS.

For the local dev environment, these are set to

TLS_CERT="/etc/certs/arcade.pem"
TLS_KEY="/etc/certs/arcade_key.pem"
TLS_CACERT="/etc/certs/rootCA.pem"
MTS_ENABLED="true"
ALLOWED_ORIGINS

ALLOWED_ORIGINS sets the allowed origins for CORS requests, as used in the 'Allow-Access-Control-Origin' HTTP header. Note: Passing in a string "*" will allow any domain.

ALLOWED_METHODS

ALLOWED_METHODS can be used to explicitly allow methods in the Access-Control-Allow-Methods header. This is a replacement operation so you must also pass GET, HEAD, and POST if you wish to support those methods.

ALLOWED_HEADERS

ALLOWED_HEADERS adds the provided headers to the list of allowed headers in a CORS request. This is an append operation so the headers Accept, Accept-Language, and Content-Language are always allowed. Content-Type must be explicitly declared if accepting Content-Types other than application/x-www-form-urlencoded, multipart/form-data, or text/plain.

CLIENT_ID

CLIENT_ID is the okta client id used to verify authentication bearer tokens.

CLIENT_ID="0oa...1d8"
PPROF_ENABLED

PPROF_ENABLED adds the pprof endpoints to the server. See: https://pkg.go.dev/net/http/pprof and https://go.dev/blog/pprof

PPROF_ENABLED="true"

Documentation

Overview

Package rest provides the basis of a restful http service.

Index

Constants

View Source
const (
	DefaultLogLevel = "info"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

Config holds the configuration information for the restful api server.

func NewConfig

func NewConfig(prefix ...string) (Config, error)

NewConfig returns the configuration of restful api server.

func (Config) AllowedHeaders

func (c Config) AllowedHeaders() []string

AllowedHeaders returns a string of Allowed Headers passed to the CORS middleware.

func (Config) AllowedMethods

func (c Config) AllowedMethods() []string

AllowedMethods returns a string of Allowed Methods passed to the CORS middleware.

func (Config) AllowedOrigins

func (c Config) AllowedOrigins() []string

AllowedOrigins returns a string of Allowed Origins passed to the CORS middleware.

func (Config) LogLevel

func (c Config) LogLevel() string

LogLevel returns the logging level. The default level is "error".

func (Config) MTLSEnabled

func (c Config) MTLSEnabled() bool

MTLSEnabled returns true if MTLS is enabled.

func (Config) PProfEnabled

func (c Config) PProfEnabled() bool

PProfEnabled adds the pprof endpoints to the server.

func (Config) ServerAddr

func (c Config) ServerAddr() string

ServerAddr returns the network address the server will listen on.

func (Config) TLSCACert

func (c Config) TLSCACert() string

TLSCACert returns the path of the CA certificate file.

func (Config) TLSCert

func (c Config) TLSCert() string

TLSCert returns the path of the certificate file.

func (Config) TLSKey

func (c Config) TLSKey() string

TLSKey returns the path of the certificate key file.

type Constructors

type Constructors struct {
	NewConfig     func(...string) (Config, error)
	NewLogger     func(Config) (*zerolog.Logger, error)
	NewHTTPServer func(context.Context, Config) (*server.Server, error)
}

Constructors provide a way to inject different functions to create server components.

type Server

type Server struct {
	Stdout, Stderr io.Writer    // Provides a way for unit tests to capture output to standard file descriptors.
	C              Constructors // Provides a way for unit tests to inject different object constructors.
	// contains filtered or unexported fields
}

Server represents the restful api server.

func NewServer

func NewServer(version, branch, commit, date string, mw ...mux.MiddlewareFunc) *Server

NewServer returns a new restful api server.

func (Server) Ctx added in v0.0.9

func (s Server) Ctx() context.Context

func (*Server) Init

func (s *Server) Init(prefix ...string) error

Init initializes the server object.

func (Server) Start

func (s Server) Start(extServices ...server.Service) error

func (Server) Stop

func (s Server) Stop()

Stop halts the server.

Jump to

Keyboard shortcuts

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