gomstoolkit

package module
v0.0.0-...-f6efce6 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const RFC3339_TIME_FORMAT string = "2006-01-02T15:04:05-0700"

Variables

This section is empty.

Functions

func CustomTimeEncoder

func CustomTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

func GetMethodString

func GetMethodString(op Method) string

func GinZapLogger

func GinZapLogger(logger *zap.Logger) gin.HandlerFunc

Types

type Endpoint

type Endpoint[Req any, Res any] struct {
	Path        string
	Handler     EndpointHandler[Req, Res]
	Method      Method
	Description string
}

func (*Endpoint[Req, Res]) GetMethod

func (endpoint *Endpoint[Req, Res]) GetMethod() Method

func (*Endpoint[Req, Res]) GetPath

func (endpoint *Endpoint[Req, Res]) GetPath() string

func (*Endpoint[Req, Res]) Hit

func (endpoint *Endpoint[Req, Res]) Hit(ginCtx *gin.Context)

func (*Endpoint[Req, Res]) Info

func (endpoint *Endpoint[Req, Res]) Info(extended bool) string

type EndpointHandler

type EndpointHandler[Req any, Res any] func(*Req) (*Res, int, error)

type HTTPError

type HTTPError struct {
	Code    int      `json:"code"`
	Message string   `json:"message"`
	Errors  []string `json:"errors"`
}

func (*HTTPError) Error

func (httpError *HTTPError) Error() string

func (*HTTPError) Is

func (httpError *HTTPError) Is(target error) bool

func (*HTTPError) SetDefaultsForEmptyFields

func (httpError *HTTPError) SetDefaultsForEmptyFields()

type Handler

type Handler struct {
	Endpoint Hitable
}

type Hitable

type Hitable interface {
	Hit(*gin.Context)
	GetMethod() Method
	GetPath() string
	Info(bool) string
}

type LoggerConfig

type LoggerConfig struct {
	LogLevel       string
	LogOutputPaths []string
	LogErrorPaths  []string
	Encoder        string
	EncoderConfig  zapcore.EncoderConfig
	UseForGin      bool
	Enabled        bool
}

type Method

type Method int
const (
	GET     Method = iota
	POST    Method = iota
	DELETE  Method = iota
	PATCH   Method = iota
	PUT     Method = iota
	OPTIONS Method = iota
)

type Service

type Service struct {
	Endpoints   []Hitable
	Server      *gin.Engine
	Port        int
	Logger      *zap.Logger
	LoggerSugar *zap.SugaredLogger
	LoggerCfg   LoggerConfig
	Name        string
	ID          string
}

func New

func New(port int) *Service

func (*Service) ConfigureLogger

func (svc *Service) ConfigureLogger(cfg LoggerConfig)

func (*Service) RegisterEndpoint

func (svc *Service) RegisterEndpoint(endpoint Hitable)

func (*Service) Run

func (svc *Service) Run()

Jump to

Keyboard shortcuts

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