server

package
v2.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultQueryPage = 1
	DefaultQuerySize = 20
	MaxQuerySize     = 100
)

Variables

View Source
var DefaultErrorHandler = func(c *fiber.Ctx, err error) error {
	code := fiber.StatusInternalServerError
	if e, ok := err.(*fiber.Error); ok {
		code = e.Code
	}
	c.Set(fiber.HeaderContentType, fiber.MIMEApplicationJSON)
	return c.Status(code).JSON(fiber.Map{"error": err.Error()})
}

DefaultErrorHandler that process return errors from handlers

View Source
var DefaultFiberConfig = fiber.Config{
	Prefork:               util.GetEnv("HTTP_PRE_FORK", "false") == "true",
	ServerHeader:          util.GetEnv("HTTP_SERVER_HEADER", "GoFiber"),
	ProxyHeader:           util.GetEnv("HTTP_PROXY_HEADER", httputil.HeaderXForwardedFor),
	ReduceMemoryUsage:     util.GetEnv("HTTP_REDUCE_MEMORY_USAGE", "true") == "true",
	DisableStartupMessage: util.GetEnv("HTTP_DISABLE_STARTUP_MESSAGE", "true") == "true",
}

DefaultFiberConfig that use for standard fiber configuration

View Source
var DefaultServerAccessLog = func(lvl logrus.Level) fiber.Handler {
	logOut := logrus.New()
	logOut.SetLevel(lvl)
	return logger.New(logger.Config{
		Format:     "${time} ${method} ${path} - ${ip} - ${status} - ${latency}\n",
		TimeZone:   "Asia/Bangkok",
		TimeFormat: time.ANSIC,
		Output:     logOut.WriterLevel(lvl),
	})
}

DefaultServerAccessLog that use for enable fiber log to specific router

Functions

func ApplyStaticRoute

func ApplyStaticRoute(s *fiber.App, publicDir string)

ApplyStaticRoute that use for serve angular built

func NoCache

func NoCache(h http.Handler) http.Handler

Types

type Config

type Config struct {
	Host string
	Port string
	// Fiber Config
	Config *fiber.Config
}

type Pagination

type Pagination struct {
	Page int
	Size int
}

func GetPagination

func GetPagination(ctx *fiber.Ctx) Pagination

func (*Pagination) Offset

func (p *Pagination) Offset() int

type Result

type Result struct {
	Error   interface{} `json:"error,omitempty"`
	Message interface{} `json:"msg,omitempty"`
	Data    interface{} `json:"data,omitempty"`
	Total   int         `json:"total,omitempty"`
	Count   int         `json:"count,omitempty"`
}

type Server

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

func New

func New(config Config) Server

func (*Server) App

func (s *Server) App() *fiber.App

func (*Server) Run

func (s *Server) Run() error

type SkipperPath

type SkipperPath struct {
	Prefix string
	Paths  map[string]bool
}

func NewSkipperPath

func NewSkipperPath(prefix string) SkipperPath

func (*SkipperPath) Add

func (s *SkipperPath) Add(path string, method string)

func (*SkipperPath) Delete

func (s *SkipperPath) Delete(path string, method string)

func (*SkipperPath) Test

func (s *SkipperPath) Test(ctx *fiber.Ctx) bool

Jump to

Keyboard shortcuts

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