bucharest

package module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoENV = errors.New("ENV is not present in this context")
View Source
var ErrNoGORM = errors.New("*gorm.DB is not present in this context")
View Source
var ErrNoLogrus = errors.New("*logrus.Logger is not present in this context")
View Source
var ErrNoRedis = errors.New("*redis.Client is not present in this context")
View Source
var ErrNoSQL = errors.New("*sql.DB is not present in this context")
View Source
var ErrNoSQLX = errors.New("*sqlx.DB is not present in this context")

Functions

func NewGinHandlerFunc

func NewGinHandlerFunc(ctx Context, handlerFunc HandlerFunc) gin.HandlerFunc

func NewGinHandlerFuncWithData

func NewGinHandlerFuncWithData(ctx Context, handlerFunc HandlerFuncWithData, data Map) gin.HandlerFunc

Types

type BuchatrestContext

type BuchatrestContext struct {
	context.Context
	// contains filtered or unexported fields
}

func (*BuchatrestContext) ENV

func (ctx *BuchatrestContext) ENV() ENV

func (*BuchatrestContext) GORM

func (ctx *BuchatrestContext) GORM() *gorm.DB

func (*BuchatrestContext) Log

func (ctx *BuchatrestContext) Log() *logrus.Logger

func (*BuchatrestContext) Redis

func (ctx *BuchatrestContext) Redis() *redis.Client

func (*BuchatrestContext) SQL

func (ctx *BuchatrestContext) SQL() *sql.DB

func (*BuchatrestContext) SQLX

func (ctx *BuchatrestContext) SQLX() *sqlx.DB

func (*BuchatrestContext) SetValue added in v0.1.1

func (ctx *BuchatrestContext) SetValue(key, val interface{})

func (*BuchatrestContext) String

func (d *BuchatrestContext) String() string

func (*BuchatrestContext) Update added in v0.1.5

func (ctx *BuchatrestContext) Update(option *ContextOptions)

type Context

type Context interface {
	context.Context
	ENV() ENV
	GORM() *gorm.DB
	Log() *logrus.Logger
	Redis() *redis.Client
	SQL() *sql.DB
	SQLX() *sqlx.DB
	SetValue(key, val interface{})
	Update(option *ContextOptions)
}

func AddValuesToContext

func AddValuesToContext(ctx Context, values MapAny) Context

func NewContextWithOptions

func NewContextWithOptions(options *ContextOptions) Context

type ContextOptions

type ContextOptions struct {
	ENV    ENV
	GORM   *gorm.DB
	Logrus *logrus.Logger
	Parent context.Context
	SQL    *sql.DB
	SQLX   *sqlx.DB
	Redis  *redis.Client
}

type ENV

type ENV interface {
	All() Map
	Bool(key string) bool
	Int(key string) int
	String(key string) string
	Viper() *viper.Viper
}

func NewENV

func NewENV(filename string) (ENV, error)

type HTTPContext

type HTTPContext interface {
	Context
	// Handler info
	HandlerName() string
	HandlerNames() []string

	// request
	FullPath() string
	ContentType() string
	Cookie(name string) (string, error)
	ClientIP() string
	RemoteIP() (net.IP, bool)
	GetHeader(key string) string
	GetRawData() ([]byte, error)
	IsWebsocket() bool

	// handler control
	Next()
	IsAborted() bool
	Abort()
	AbortWithStatusJSON(code int, jsonObj interface{})
	AbortWithStatus(code int)

	// Setter and Getter
	Get(key string) (interface{}, bool)
	Set(key string, value interface{})
	MustGet(key string) interface{}
	GetString(key string) (s string)
	GetBool(key string) (b bool)
	GetInt(key string) (i int)
	GetInt64(key string) (i64 int64)
	GetUint(key string) (ui uint)
	GetUint64(key string) (ui64 uint64)
	GetFloat64(key string) (f64 float64)
	GetTime(key string) (t time.Time)
	GetDuration(key string) (d time.Duration)
	GetStringSlice(key string) (ss []string)
	GetStringMap(key string) (sm map[string]interface{})
	GetStringMapString(key string) (sms map[string]string)
	GetStringMapStringSlice(key string) (smss map[string][]string)

	// parameter and query
	Param(key string) string
	Query(key string) string
	DefaultQuery(key, defaultValue string) string
	GetQuery(key string) (string, bool)
	QueryArray(key string) []string
	GetQueryArray(key string) ([]string, bool)
	QueryMap(key string) map[string]string
	GetQueryMap(key string) (map[string]string, bool)

	// urlencoded
	PostForm(key string) string
	DefaultPostForm(key, defaultValue string) string
	GetPostForm(key string) (string, bool)
	PostFormArray(key string) []string
	GetPostFormArray(key string) ([]string, bool)
	PostFormMap(key string) map[string]string
	GetPostFormMap(key string) (map[string]string, bool)

	// multipart
	FormFile(name string) (*multipart.FileHeader, error)
	MultipartForm() (*multipart.Form, error)
	SaveUploadedFile(file *multipart.FileHeader, dst string) error

	// binder
	Bind(obj interface{}) error
	BindJSON(obj interface{}) error
	BindXML(obj interface{}) error
	BindQuery(obj interface{}) error
	BindYAML(obj interface{}) error
	BindHeader(obj interface{}) error
	BindUri(obj interface{}) error
	MustBindWith(obj interface{}, b binding.Binding) error
	ShouldBind(obj interface{}) error
	ShouldBindJSON(obj interface{}) error
	ShouldBindXML(obj interface{}) error
	ShouldBindQuery(obj interface{}) error
	ShouldBindYAML(obj interface{}) error
	ShouldBindHeader(obj interface{}) error
	ShouldBindUri(obj interface{}) error
	ShouldBindWith(obj interface{}, b binding.Binding) error
	ShouldBindBodyWith(obj interface{}, bb binding.BindingBody) (err error)

	// response header
	Status(code int)
	Header(key, value string)
	SetSameSite(samesite http.SameSite)
	SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
	SetAccepted(formats ...string)

	// response body
	Render(code int, r render.Render)
	HTML(code int, name string, obj interface{})
	IndentedJSON(code int, obj interface{})
	SecureJSON(code int, obj interface{})
	JSONP(code int, obj interface{})
	JSON(code int, obj interface{})
	AsciiJSON(code int, obj interface{})
	PureJSON(code int, obj interface{})
	XML(code int, obj interface{})
	YAML(code int, obj interface{})
	ProtoBuf(code int, obj interface{})
	String(code int, format string, values ...interface{})
	Redirect(code int, location string)
	Data(code int, contentType string, data []byte)
	DataFromReader(code int, contentLength int64, contentType string, reader io.Reader, extraHeaders map[string]string)
	File(filepath string)
	FileFromFS(filepath string, fs http.FileSystem)
	FileAttachment(filepath, filename string)
	SSEvent(name string, message interface{})
	Stream(step func(w io.Writer) bool) bool

	GetGin() (*gin.Context, bool)
	Gin() *gin.Context
	// contains filtered or unexported methods
}

type HTTPError

type HTTPError interface {
	OriginalError() error
	GetStatus() int
	GetJSON() interface{}
}

func GinLoggerWithConfig

func GinLoggerWithConfig(ctx HTTPContext, data Map) HTTPError

func NewBadRequestError

func NewBadRequestError(err error) HTTPError

func NewInternalServerError

func NewInternalServerError(err error) HTTPError

type HandlerFunc

type HandlerFunc func(HTTPContext) HTTPError

type HandlerFuncWithData

type HandlerFuncWithData func(HTTPContext, Map) HTTPError

type HandlersChain

type HandlersChain []HandlerFunc

type HttpError added in v0.1.1

type HttpError struct {
	Message interface{} `json:"message"`
	// contains filtered or unexported fields
}

func (*HttpError) GetJSON added in v0.1.1

func (e *HttpError) GetJSON() interface{}

func (*HttpError) GetStatus added in v0.1.1

func (e *HttpError) GetStatus() int

func (*HttpError) OriginalError added in v0.1.1

func (e *HttpError) OriginalError() error

type LogLevelFromGinParam added in v0.0.3

type LogLevelFromGinParam func(*gin.LogFormatterParams) logrus.Level

type Map

type Map map[string]interface{}

type MapAny

type MapAny map[interface{}]interface{}

type MockContext

type MockContext interface {
	Context
	SQLMock() sqlmock.Sqlmock
}

func NewMockContext

func NewMockContext(parentContext Context, mock sqlmock.Sqlmock) MockContext

type ValidationErrors

type ValidationErrors struct {
	Error string `json:"error"`
	Param string `json:"param,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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