Help us shape the future of Go! Take the 2026 Go Developer Survey

server

package
v1.15.9 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package server contains the server functions

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFailedToGetFilePath is returned when runtime.Caller fails to get the current file path
	ErrFailedToGetFilePath = fmt.Errorf("failed to get current file path")
	// ErrSCIMSpecNotFound is returned when the SCIM spec file is not found
	ErrSCIMSpecNotFound = fmt.Errorf("SCIM spec file not found")
)

Functions

func ConfigureEcho added in v0.8.6

func ConfigureEcho(c LogConfig) *echo.Echo

ConfigureEcho sets up the echo server with the default middleware and logging

func CustomHTTPErrorHandler added in v0.8.6

func CustomHTTPErrorHandler(c echo.Context, err error)

CustomHTTPErrorHandler is a custom error handler that logs the error and returns a JSON response

func GenerateOpenAPISpecDocument added in v0.45.8

func GenerateOpenAPISpecDocument() (*openapi3.T, error)

GenerateOpenAPISpecDocument builds a fully-registered OpenAPI document

func NewOpenAPISpec

func NewOpenAPISpec() (*openapi3.T, error)

NewOpenAPISpec creates a new OpenAPI 3.1.0 specification based on the configured go interfaces and the operation types appended within the individual handlers

func NewRouter

func NewRouter(c LogConfig) (*route.Router, error)

NewRouter creates a wrapper router so that the echo server and OAS specification can be generated simultaneously

Types

type APIKey

type APIKey struct {
	Name string
}

APIKey is a struct that represents an API Key security scheme

func (*APIKey) Scheme

func (k *APIKey) Scheme() *openapi3.SecurityScheme

Scheme returns the API Key security scheme

type Basic

type Basic struct {
	Username string
	Password string
}

Basic is a struct that represents a Basic Auth security scheme

func (*Basic) Scheme

func (b *Basic) Scheme() *openapi3.SecurityScheme

Scheme returns the Basic Auth security scheme

type LogConfig added in v0.18.9

type LogConfig struct {
	// PrettyLog enables pretty logging output, defaults to json format
	PrettyLog bool
	// LogLevel sets the log level for the server, defaults to INFO
	LogLevel echo_log.Lvl
}

LogConfig is a struct that holds the configuration for logging in the echo server

type OAuth2

type OAuth2 struct {
	AuthorizationURL string
	TokenURL         string
	RefreshURL       string
	Scopes           map[string]string
}

OAuth2 is a struct that represents an OAuth2 security scheme

func (*OAuth2) Scheme

func (i *OAuth2) Scheme() *openapi3.SecurityScheme

Scheme returns the OAuth2 security scheme

type OpenID

type OpenID struct {
	ConnectURL string
}

OpenID is a struct that represents an OpenID Connect security scheme

func (*OpenID) Scheme

func (i *OpenID) Scheme() *openapi3.SecurityScheme

Scheme returns the OpenID Connect security scheme

type SchemaRegistry added in v0.25.0

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

SchemaRegistry manages OpenAPI schemas dynamically

func NewSchemaRegistry added in v0.25.0

func NewSchemaRegistry(spec *openapi3.T, opts ...openapi3gen.Option) *SchemaRegistry

NewSchemaRegistry creates a new schema registry

func (*SchemaRegistry) GetOrRegister added in v0.25.0

func (r *SchemaRegistry) GetOrRegister(v any) (*openapi3.SchemaRef, error)

GetOrRegister gets an existing schema reference or registers the type

func (*SchemaRegistry) GetRef added in v0.25.0

func (r *SchemaRegistry) GetRef(v any) *openapi3.SchemaRef

GetRef returns a reference to a registered schema by type

func (*SchemaRegistry) GetSchemas added in v0.25.0

func (r *SchemaRegistry) GetSchemas() map[string]any

GetSchemas returns all registered schemas (for backwards compatibility)

func (*SchemaRegistry) MustGetOrRegister added in v0.25.0

func (r *SchemaRegistry) MustGetOrRegister(v any) *openapi3.SchemaRef

MustGetOrRegister gets an existing schema reference or registers the type, panics on error

func (*SchemaRegistry) MustRegisterAll added in v0.25.0

func (r *SchemaRegistry) MustRegisterAll(models map[string]any)

MustRegisterAll registers multiple types at once, panics on any error

func (*SchemaRegistry) MustRegisterType added in v0.25.0

func (r *SchemaRegistry) MustRegisterType(v any) *openapi3.SchemaRef

MustRegisterType registers a type and panics on error (for use during initialization)

func (*SchemaRegistry) RegisterAll added in v0.25.0

func (r *SchemaRegistry) RegisterAll(models map[string]any) error

RegisterAll registers multiple types at once

func (*SchemaRegistry) RegisterType added in v0.25.0

func (r *SchemaRegistry) RegisterType(v any) (*openapi3.SchemaRef, error)

RegisterType registers a type and returns its schema reference

type Server

type Server struct {

	// Router makes the router directly accessible on the Server struct
	Router *route.Router
	// SchemaRegistry manages OpenAPI schemas dynamically
	SchemaRegistry *SchemaRegistry
	// contains filtered or unexported fields
}

Server is a struct that holds the configuration for the server

func NewServer

func NewServer(c config.Config) (*Server, error)

NewServer returns a new Server configuration

func (*Server) AddHandler

func (s *Server) AddHandler(r handler)

AddHandler provides the ability to add additional HTTP handlers that process requests. The handler that is provided should have a Routes(*echo.Group) function, which allows the routes to be added to the server.

func (*Server) StartEchoServer

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

StartEchoServer creates and starts the echo server with configured middleware and handlers

Jump to

Keyboard shortcuts

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