xhttp

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: Apache-2.0 Imports: 8 Imported by: 1

README

Neuron HTTP Server

This repository extends Neuron and provides HTTP Server that implements neuron/server.Server interface.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API interface {
	server.EndpointsGetter
	InitializeAPI(c *core.Controller) error
	SetRoutes(router *httprouter.Router) error
}

API is an interface used for the server API's.

type Option

type Option func(o *Options)

Option is a function that changes options in some way.

func WithAPI

func WithAPI(api API) Option

WithAPI is a server option that stores provided API in given http server.

func WithAPIVersion

func WithAPIVersion(version string, api API) Option

WithAPIVersion is a server option that stores the api for provided version.

func WithHostname

func WithHostname(hostname string) Option

WithHostname sets the hostname option for the server.

func WithPort

func WithPort(port int) Option

WithPort sets the port option for the server.

func WithTLSConfig

func WithTLSConfig(tlsConfig *tls.Config) Option

WithTLSConfig sets the tls config option for the server.

type Options

type Options struct {
	VersionedAPIs map[string][]API
	APIs          []API
	Hostname      string
	Port          int
	TLSConfig     *tls.Config
}

Options are the http server options.

type Server

type Server struct {
	Options    *Options
	Endpoints  []*server.Endpoint
	Router     *httprouter.Router
	Server     http.Server
	Controller *core.Controller
}

Server is an http server implementation. It implements neuron/server.Server interface.

func New

func New(options ...Option) *Server

New creates new server.

func (*Server) GetEndpoints

func (s *Server) GetEndpoints() []*server.Endpoint

GetEndpoints gets all stored server endpoints.

func (*Server) Initialize

func (s *Server) Initialize(c *core.Controller) error

Initialize initializes server with provided options.

func (*Server) Serve

func (s *Server) Serve() error

Serve serves all routes stored in given server.

func (*Server) Shutdown

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

Shutdown gently shutdown the server connection.

type VersionedServer

type VersionedServer struct {
	Router    *httprouter.Router
	Endpoints []*server.Endpoint
	Options   *Options
	// contains filtered or unexported fields
}

VersionedServer is a server.VersionedServer implementation for the http Server with multiple API versions.

func NewVersioned

func NewVersioned(options ...Option) *VersionedServer

NewVersioned creates new versioned API.

func (*VersionedServer) GetEndpoints

func (v *VersionedServer) GetEndpoints() []*server.Endpoint

GetEndpoints implements server.VersionedServer.

func (*VersionedServer) InitializeVersion

func (v *VersionedServer) InitializeVersion(version string, c *core.Controller) error

InitializeVersion initializes all API stored for given 'version'.

func (*VersionedServer) Serve

func (v *VersionedServer) Serve() error

Serve implements server.VersionedServer.

func (*VersionedServer) Shutdown

func (v *VersionedServer) Shutdown(ctx context.Context) error

Shutdown gently shutdown the server connection.

Directories

Path Synopsis
api
jsonapi Module

Jump to

Keyboard shortcuts

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