server

package
v0.0.0-...-7a9e484 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package server provides an executable server which exposes a REST API.

Package server provides an executable server which exposes a REST API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Driver string `json:"driver"`
	DSN    string `json:"dsn"`
	Addr   string `json:"addr"`
}

Config concludes important configuration values which will be consumed by the API server.

type Server

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

Server represents an full-featured, executable REST API server. It is the central place where all individual components are being wired up.

It initializes and holds all storage objects as well as the business services. Each service requires multiple storage objects and the server will pass its own objects by reference to the corresponding services.

Since a service assumes that the storage objects are ready to use, each storage is initialized first and will then be passed to the service.

func New

func New(config *Config) (*Server, error)

New is the actual entry point for the API server binary. It initializes all server components like the internal HTTP server or the router. Most importantly, it will create a database connection pool which will be passed to the storage factories, and the resulting storage object will be passed to the services.

This function is also the place where dependency injection happens: The server decides which storage implementations will be used - e. g. maria.Restaurant for the Server.restaurant field.

func (*Server) Run

func (s *Server) Run()

Run starts the internal HTTP server which makes the API server listen on the port specified in the passed Config instance. This function will panic in case an error occurs.

Jump to

Keyboard shortcuts

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