gocom

package module
v0.0.34 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 22 Imported by: 0

README

gocom

ADL Indo golang common library. Provide basic feature for develops api server such as HTTP server, db, key/value, queue and pubsub

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCtrl

func AddCtrl(ctrl Controller)

func DB

func DB(name ...string) *gorm.DB

func DELETE

func DELETE(path string, handlers ...HandlerFunc)

func GET

func GET(path string, handlers ...HandlerFunc)

func KeyVal

func KeyVal(name ...string) keyval.KeyValClient

func Logger

func Logger() *zap.Logger

func NewJWT

func NewJWT(data map[string]interface{}, ttl ...time.Duration) (string, error)

func PATCH

func PATCH(path string, handlers ...HandlerFunc)

func POST

func POST(path string, handlers ...HandlerFunc)

func PUT

func PUT(path string, handlers ...HandlerFunc)

func PubSub

func PubSub(name ...string) pubsub.PubSubClient

func Queue

func Queue(name ...string) queue.QueueClient

func RegAppCreator

func RegAppCreator(name string, creator HttpAppCreatorFunc)

func RegDBCreator

func RegDBCreator(typeName string, creator DBCreatorFunc)

func ReleaseLock

func ReleaseLock(lock *DistLock) error

func Start

func Start()

func ValidateJWT

func ValidateJWT(token string) (map[string]interface{}, error)

Types

type App

type App interface {
	Get(path string, handlers ...HandlerFunc)
	Post(path string, handlers ...HandlerFunc)
	Put(path string, handlers ...HandlerFunc)
	Patch(path string, handlers ...HandlerFunc)
	Delete(path string, handlers ...HandlerFunc)
	Start()
}

type BaseRepo

type BaseRepo struct {
	ConnName string
}

func (*BaseRepo) AutoMigrate

func (o *BaseRepo) AutoMigrate(value interface{}) error

func (*BaseRepo) Create

func (o *BaseRepo) Create(value interface{}) *gorm.DB

func (*BaseRepo) Delete

func (o *BaseRepo) Delete(value interface{}) *gorm.DB

func (*BaseRepo) Exec

func (o *BaseRepo) Exec(sql string, args ...interface{}) *gorm.DB

func (*BaseRepo) Find

func (o *BaseRepo) Find(dest interface{}, conds ...interface{}) *gorm.DB

func (*BaseRepo) First

func (o *BaseRepo) First(dest interface{}, conds ...interface{}) *gorm.DB

func (*BaseRepo) Model

func (o *BaseRepo) Model(value interface{}) *gorm.DB

func (*BaseRepo) Raw

func (o *BaseRepo) Raw(sql string, args ...interface{}) *gorm.DB

func (*BaseRepo) Table

func (o *BaseRepo) Table(name string) *gorm.DB

func (*BaseRepo) Update

func (o *BaseRepo) Update(value interface{}) *gorm.DB

func (*BaseRepo) Where

func (o *BaseRepo) Where(query interface{}, args ...interface{}) *gorm.DB

type CodedError

type CodedError struct {
	Code    int
	Message string
}

func NewError

func NewError(code int, msg string) *CodedError

func (*CodedError) Error

func (o *CodedError) Error() string

type Context

type Context interface {
	Status(code int) Context
	Body() []byte
	Param(key string, defaulVal ...string) string
	Query(key string, defaulVal ...string) string
	FormValue(key string, defaulVal ...string) string
	Bind(target interface{}) error
	SetHeader(key string, value string)
	GetHeader(key string) string
	Set(key string, value string)
	Get(key string) string
	SendString(data string) error
	SendJSON(data interface{}) error
	SendPaged(data interface{}, currPage, totalPage int) error
	SendFile(filePath string, fileName string) error
	SendFileBytes(data []byte, fileName string) error
	SendResult(data interface{}) error
	SendError(err *CodedError) error
	Next() error
}

type Controller

type Controller interface {
	Init()
}

type DBCreatorFunc

type DBCreatorFunc func(dsn string) (*gorm.DB, error)

type DistLock

type DistLock struct {
	ID     string
	Name   string `gorm:"primarykey"`
	Mode   string
	Expire time.Time
}

func GetLock

func GetLock(name string, maxWait time.Duration, ttl time.Duration) *DistLock

func TryLock

func TryLock(name string, ttl time.Duration) *DistLock

func (*DistLock) IsExpired

func (o *DistLock) IsExpired() bool

func (*DistLock) Release

func (o *DistLock) Release() error

type FiberApp

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

func (*FiberApp) Delete

func (o *FiberApp) Delete(path string, handlers ...HandlerFunc)

func (*FiberApp) Get

func (o *FiberApp) Get(path string, handlers ...HandlerFunc)

func (*FiberApp) Patch

func (o *FiberApp) Patch(path string, handlers ...HandlerFunc)

func (*FiberApp) Post

func (o *FiberApp) Post(path string, handlers ...HandlerFunc)

func (*FiberApp) Put

func (o *FiberApp) Put(path string, handlers ...HandlerFunc)

func (*FiberApp) Start

func (o *FiberApp) Start()

type FiberContext

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

func (*FiberContext) Bind

func (o *FiberContext) Bind(target interface{}) error

func (*FiberContext) Body

func (o *FiberContext) Body() []byte

func (*FiberContext) FormValue

func (o *FiberContext) FormValue(key string, defaultVal ...string) string

func (*FiberContext) Get

func (o *FiberContext) Get(key string) string

func (*FiberContext) GetHeader

func (o *FiberContext) GetHeader(key string) string

func (*FiberContext) Next

func (o *FiberContext) Next() error

func (*FiberContext) Param

func (o *FiberContext) Param(key string, defaultVal ...string) string

func (*FiberContext) Query

func (o *FiberContext) Query(key string, defaultVal ...string) string

func (*FiberContext) SendError

func (o *FiberContext) SendError(err *CodedError) error

func (*FiberContext) SendFile

func (o *FiberContext) SendFile(filePath string, fileName string) error

func (*FiberContext) SendFileBytes

func (o *FiberContext) SendFileBytes(data []byte, fileName string) error

func (*FiberContext) SendJSON

func (o *FiberContext) SendJSON(data interface{}) error

func (*FiberContext) SendPaged

func (o *FiberContext) SendPaged(data interface{}, currPage, totalPage int) error

func (*FiberContext) SendResult

func (o *FiberContext) SendResult(data interface{}) error

func (*FiberContext) SendString

func (o *FiberContext) SendString(data string) error

func (*FiberContext) Set

func (o *FiberContext) Set(key string, value string)

func (*FiberContext) SetHeader

func (o *FiberContext) SetHeader(key, value string)

func (*FiberContext) Status

func (o *FiberContext) Status(code int) Context

type HandlerFunc

type HandlerFunc func(ctx Context) error

type HttpAppCreatorFunc

type HttpAppCreatorFunc func() App

type Result

type Result struct {
	Code     int         `json:"code"`
	Messages string      `json:"message"`
	Data     interface{} `json:"data"`
}

type ResultPaged

type ResultPaged struct {
	Result
	CurrPage  int `json:"currPage"`
	TotalPage int `json:"totalPage"`
}

Jump to

Keyboard shortcuts

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