rest

package
v1.4.8 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: Apache-2.0 Imports: 20 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 int16 = 8080
)

Functions

func GetReadyChannel added in v1.4.0

func GetReadyChannel() chan bool

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

func GetServerPort added in v1.3.13

func GetServerPort() (int, error)

GetServerPort returns the actual port used by the REST API

func RunServer

func RunServer(ctx context.Context, grpcPort int, httpPort int, 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 added in v1.3.14

func StopServer(ctx context.Context)

StopServer is in charge of stopping the REST API.

Types

type ServerConfigOption added in v1.4.0

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

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

func WithAdditionalHandler added in v1.4.0

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 added in v1.3.13

func WithAllowedHeaders(headers []string) ServerConfigOption

WithAllowedHeaders is an option to supply allowed headers in CORS.

func WithAllowedMethods added in v1.3.13

func WithAllowedMethods(methods []string) ServerConfigOption

WithAllowedMethods is an option to supply allowed methods in CORS.

func WithAllowedOrigins added in v1.3.13

func WithAllowedOrigins(origins []string) ServerConfigOption

WithAllowedOrigins is an option to supply allowed origins in CORS.

func WithEmbeddedOAuth2Server added in v1.4.0

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