server

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JsonHandler

func JsonHandler(svr *Server, cfg config.Options, route config.Route) fiber.Handler

JsonHandler provides a Fiber Handler for rendering JSON responses (1) Unmarshal the incoming request body, in the event of failure respond with 400. (2) Find the response body for the route, including any variants. (3) Unmarshal the raw response body, in the event of failure respond with 500. (4) Respond to the client with the found response.

Types

type LogEntry

type LogEntry struct {
	Id        string       `json:"id"`
	Route     config.Route `json:"route"`
	Request   Request      `json:"request"`
	Response  Response     `json:"response"`
	Timestamp time.Time    `json:"timestamp"`
}

type Options

type Options struct {
	Host string
	Port string
}

type Request

type Request struct {
	Body interface{} `json:"body"`
}

type RequestLog

type RequestLog struct {
	Entries map[string]LogEntry
	// contains filtered or unexported fields
}

func NewRequestLog

func NewRequestLog(logger logging.Logger) RequestLog

func (*RequestLog) Record

func (l *RequestLog) Record(route config.Route, request interface{}, response Response) LogEntry

Record adds a new entry to the RequestLog

type Response

type Response struct {
	StatusCode int    `json:"statusCode"`
	Response   string `json:"response"`
}

type Server

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

func NewServer

func NewServer(cfg config.Config, logger logging.Logger, opt Options) Server

func (*Server) Listen

func (s *Server) Listen() error

Listen is a wrapper around the Fiber App's listen where the host is derived from the server options.

func (*Server) PrintConfig

func (s *Server) PrintConfig()

PrintConfig outputs the defined routes in table form and the final host that the server is listening on.

Jump to

Keyboard shortcuts

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