server

package
v2.0.10 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var DefaultErrorHandler = func(ctx *fiber.Ctx, err error) error {
	code := fiber.StatusInternalServerError
	var e *fiber.Error
	if errors.As(err, &e) {
		code = e.Code
	}
	if code >= fiber.StatusInternalServerError {
		logrus.Error("[PANIC] "+fmt.Sprintf(" [%s] ", ctx.IP())+ctx.Route().Method+ctx.Route().Path+" -> ", err)
	}
	ctx.Set(fiber.HeaderContentType, fiber.MIMEApplicationJSON)
	return ctx.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",
	ErrorHandler:          DefaultErrorHandler,
}

DefaultFiberConfig that use for standard fiber configuration

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
	Config      *fiber.Config
	HealthCheck bool
	RequestId   bool
}

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) EnableHealthCheck added in v2.0.9

func (s *Server) EnableHealthCheck()

func (*Server) EnableRequestId added in v2.0.9

func (s *Server) EnableRequestId()

func (*Server) Run

func (s *Server) Run() error

type SkipperPath

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

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