rest

package
v2.0.0-alpha.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultAllowedOrigins contains a nil slice, as per default, no origins are allowed.
	DefaultAllowedOrigins []string = nil

	// DefaultAllowedHeaders contains sensible defaults for the Access-Control-Allow-Headers header.
	// Please adjust accordingly in production using WithAllowedHeaders.
	DefaultAllowedHeaders = []string{"Content-Type", "Accept", "Authorization"}

	// DefaultAllowedMethods contains sensible defaults for the Access-Control-Allow-Methods header.
	// Please adjust accordingly in production using WithAllowedMethods.
	DefaultAllowedMethods = []string{"GET", "POST", "PUT", "DELETE"}

	// DefaultAPIHTTPPort specifies the default port for the REST API.
	DefaultAPIHTTPPort uint16 = 8080
)

Functions

func GetReadyChannel

func GetReadyChannel() chan bool

GetReadyChannel returns a channel which will notify when the server is ready

func GetServerPort

func GetServerPort() (uint16, error)

GetServerPort returns the actual port used by the REST API

func RunServer

func RunServer(ctx context.Context, grpcPort uint16, port uint16, serverOpts ...ServerConfigOption) (err error)

RunServer starts our REST API. The REST API is a reverse proxy using grpc-gateway that exposes certain gRPC calls as RESTful HTTP methods.

func StopServer

func StopServer(ctx context.Context)

StopServer is in charge of stopping the REST API.

Types

type ServerConfigOption

type ServerConfigOption func(*config, *runtime.ServeMux)

ServerConfigOption represents functional-style options to modify the server configuration in RunServer.

func WithAdditionalGRPCOpts

func WithAdditionalGRPCOpts(opts []grpc.DialOption) ServerConfigOption

WithAdditionalGRPCOpts is an option to add an additional gRPC dial options in the REST server communication to the backend.

func WithAdditionalHandler

func WithAdditionalHandler(method string, path string, h runtime.HandlerFunc) ServerConfigOption

WithAdditionalHandler is an option to add an additional handler func in the REST server.

func WithAllowedHeaders

func WithAllowedHeaders(headers []string) ServerConfigOption

WithAllowedHeaders is an option to supply allowed headers in CORS.

func WithAllowedMethods

func WithAllowedMethods(methods []string) ServerConfigOption

WithAllowedMethods is an option to supply allowed methods in CORS.

func WithAllowedOrigins

func WithAllowedOrigins(origins []string) ServerConfigOption

WithAllowedOrigins is an option to supply allowed origins in CORS.

func WithEmbeddedOAuth2Server

func WithEmbeddedOAuth2Server(keyPath string, keyPassword string, saveOnCreate bool, opts ...oauth2.AuthorizationServerOption) ServerConfigOption

WithEmbeddedOAuth2Server configures our REST gateway to include an embedded OAuth 2.0 authorization server with the given parameters. This server can be used to authenticate and authorize API clients, such as our own micro-services as well as users logging in through the UI.

For the various options to configure the OAuth 2.0 server, please refer to https://pkg.go.dev/github.com/oxisto/oauth2go#AuthorizationServerOption.

In production scenarios, the usage of a dedicated authentication and authorization server is recommended.

Jump to

Keyboard shortcuts

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