apiserver

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

* utils.go --- Utility functions. * * Copyright (c) 2021-2022 Paul Ward <asmodai@gmail.com> * * Author: Paul Ward <asmodai@gmail.com> * Maintainer: Paul Ward <asmodai@gmail.com> * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation files * (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, * publish, distribute, sublicense, and/or sell copies of the Software, * and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORSMiddleware

func CORSMiddleware() gin.HandlerFunc

func GetRouter

func GetRouter(mgr process.IManager) (*gin.Engine, error)

func SetDebugMode

func SetDebugMode(debug bool)

func Spawn

func Spawn(mgr process.IManager, lgr logger.ILogger, config *Config) (*process.Process, error)

Types

type Config

type Config struct {
	Addr    string `json:"address"`
	Cert    string `json:"cert_file"`
	Key     string `json:"key_file"`
	UseTLS  bool   `json:"use_tls"`
	LogFile string `json:"log_file"`
}

func NewConfig

func NewConfig(addr, log, cert, key string, tls bool) *Config

func NewDefaultConfig

func NewDefaultConfig() *Config

type Dispatcher

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

func NewDefaultDispatcher

func NewDefaultDispatcher() *Dispatcher

func NewDispatcher

func NewDispatcher(lgr logger.ILogger, config *Config) *Dispatcher

func (*Dispatcher) GetRouter

func (d *Dispatcher) GetRouter() *gin.Engine

func (*Dispatcher) Start

func (d *Dispatcher) Start()

func (*Dispatcher) Stop

func (d *Dispatcher) Stop()

type DispatcherProc

type DispatcherProc struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewDispatcherProc

func NewDispatcherProc(lgr logger.ILogger, config *Config) *DispatcherProc

func (*DispatcherProc) Action

func (p *DispatcherProc) Action(state **process.State)

type Document

type Document struct {
	Data    interface{}    `json:"data"`
	Error   *ErrorDocument `json:"error"`
	Elapsed string         `json:"elapsed_time",omitempty`
	// contains filtered or unexported fields
}

func NewDocument

func NewDocument(status int, data interface{}) *Document

func NewErrorDocument

func NewErrorDocument(status int, msg string) *Document

func (*Document) AddHeader

func (d *Document) AddHeader(key, value string)

func (*Document) SetError

func (d *Document) SetError(err *ErrorDocument)

func (*Document) Status

func (d *Document) Status() int

func (*Document) Write

func (d *Document) Write(ctx *gin.Context)

type ErrorDocument

type ErrorDocument struct {
	Status  int    `json:"status"`
	Message string `json:"message"`
}

func NewError

func NewError(status int, msg string) *ErrorDocument

type IServer

type IServer interface {
	ListenAndServeTLS(string, string) error
	ListenAndServe() error
	Shutdown(context.Context) error
	SetTLSConfig(*tls.Config)
}

type Server

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

func NewDefaultServer

func NewDefaultServer() *Server

func NewServer

func NewServer(addr string, router *gin.Engine) *Server

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

func (*Server) ListenAndServeTLS

func (s *Server) ListenAndServeTLS(cert, key string) error

func (*Server) SetTLSConfig

func (s *Server) SetTLSConfig(conf *tls.Config)

func (*Server) Shutdown

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

Jump to

Keyboard shortcuts

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