gocom

package module
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: MIT Imports: 23 Imported by: 1

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 FileSecret

func FileSecret(dsn string, key string) (string, error)

func GET

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

func GetSecret

func GetSecret(name string) (string, error)

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 RegAppCreator

func RegAppCreator(name string, creator HttpAppCreatorFunc)

func RegDBCreator

func RegDBCreator(typeName string, creator DBCreatorFunc)

func RegKeyValCreator

func RegKeyValCreator(typeName string, creator KeyValCreatorFunc)

func RegPubSubCreator

func RegPubSubCreator(typeName string, creator PubSubCreatorFunc)

func RegQueueCreator

func RegQueueCreator(typeName string, creator QueueCreatorFunc)

func RegSecretFunc

func RegSecretFunc(typeName string, secFunc SecretFunc)

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 added in v0.1.12

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

func (*DistLock) IsExpired added in v0.1.12

func (o *DistLock) IsExpired() bool

func (*DistLock) Release

func (o *DistLock) Release() error

type DistObjClient added in v0.1.11

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

func DistObj added in v0.1.11

func DistObj(name ...string) *DistObjClient

func (*DistObjClient) AddImpl added in v0.1.11

func (o *DistObjClient) AddImpl(className string, impl interface{}) error

func (*DistObjClient) Invoke added in v0.1.11

func (o *DistObjClient) Invoke(className string, methodName string, param ...interface{}) ([]interface{}, error)

type DistObjReqMsg added in v0.1.11

type DistObjReqMsg struct {
	Params []interface{}
}

type DistObjResMsg added in v0.1.11

type DistObjResMsg struct {
	IsErr  bool
	ErrMsg string
	Result []interface{}
}

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 KeyValClient

type KeyValClient interface {
	Set(key string, val interface{}, ttl ...time.Duration) error
	SetNX(key string, val interface{}, ttl ...time.Duration) bool
	Get(key string) string
	GetInt(key string) int
	Del(key string) error

	LPush(key string, val interface{}) error
	LPop(key string) string
	LPopInt(key string) int
	RPush(key string, val interface{}) error
	RPop(key string) string
	RPopInt(key string) int
	Len(key string) int64
	AtIndex(key string, index int64) string
	AtIndexInt(key string, index int64) int
	Range(key string, start int64, stop int64) []string

	HSet(key string, values map[string]interface{}) error
	HGet(key, field string) string
	HGetAll(key string) map[string]string
	HDel(key string, fields ...string) error

	Expire(key string, ttl time.Duration) error
}

func KeyVal

func KeyVal(name ...string) KeyValClient

type KeyValCreatorFunc

type KeyValCreatorFunc func(url string) (KeyValClient, error)

type NatsPubSubClient

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

func (*NatsPubSubClient) Publish

func (o *NatsPubSubClient) Publish(subject string, msg interface{}) error

func (*NatsPubSubClient) QueueSubscribe

func (o *NatsPubSubClient) QueueSubscribe(subject string, queue string, eventHandler PubSubEventHandler)

func (*NatsPubSubClient) Request added in v0.1.11

func (o *NatsPubSubClient) Request(subject string, msg interface{}, timeOut ...time.Duration) (string, error)

func (*NatsPubSubClient) RequestSubscribe added in v0.1.11

func (o *NatsPubSubClient) RequestSubscribe(subject string, eventHandler PubSubReqEventHandler)

func (*NatsPubSubClient) Subscribe

func (o *NatsPubSubClient) Subscribe(subject string, eventHandler PubSubEventHandler)

type PubSubClient

type PubSubClient interface {
	Publish(subject string, msg interface{}) error
	Request(subject string, msg interface{}, timeOut ...time.Duration) (string, error)
	Subscribe(subject string, eventHandler PubSubEventHandler)
	RequestSubscribe(subject string, eventHandler PubSubReqEventHandler)
	QueueSubscribe(subject string, queue string, eventHandler PubSubEventHandler)
}

func PubSub

func PubSub(name ...string) PubSubClient

type PubSubCreatorFunc

type PubSubCreatorFunc func(connString string) (PubSubClient, error)

type PubSubEventHandler

type PubSubEventHandler func(name string, msg string)

type PubSubReqEventHandler added in v0.1.11

type PubSubReqEventHandler func(name string, msg string) string

type QueueClient

type QueueClient interface {
	Publish(name string, payload interface{}) error
	Consume(name string, consumer QueueConsumerFunc) error
}

func Queue

func Queue(name ...string) QueueClient

type QueueConsumerFunc

type QueueConsumerFunc func(payload string)

type QueueCreatorFunc

type QueueCreatorFunc func(url string) (QueueClient, error)

type RedisKeyVal

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

func (*RedisKeyVal) AtIndex

func (o *RedisKeyVal) AtIndex(key string, index int64) string

func (*RedisKeyVal) AtIndexInt

func (o *RedisKeyVal) AtIndexInt(key string, index int64) int

func (*RedisKeyVal) Del

func (o *RedisKeyVal) Del(key string) error

func (*RedisKeyVal) Expire added in v0.1.8

func (o *RedisKeyVal) Expire(key string, ttl time.Duration) error

func (*RedisKeyVal) Get

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

func (*RedisKeyVal) GetInt

func (o *RedisKeyVal) GetInt(key string) int

func (*RedisKeyVal) HDel added in v0.1.8

func (o *RedisKeyVal) HDel(key string, fields ...string) error

func (*RedisKeyVal) HGet added in v0.1.8

func (o *RedisKeyVal) HGet(key, field string) string

func (*RedisKeyVal) HGetAll added in v0.1.8

func (o *RedisKeyVal) HGetAll(key string) map[string]string

func (*RedisKeyVal) HSet added in v0.1.8

func (o *RedisKeyVal) HSet(key string, values map[string]interface{}) error

func (*RedisKeyVal) LPop

func (o *RedisKeyVal) LPop(key string) string

func (*RedisKeyVal) LPopInt

func (o *RedisKeyVal) LPopInt(key string) int

func (*RedisKeyVal) LPush

func (o *RedisKeyVal) LPush(key string, val interface{}) error

func (*RedisKeyVal) Len

func (o *RedisKeyVal) Len(key string) int64

func (*RedisKeyVal) RPop

func (o *RedisKeyVal) RPop(key string) string

func (*RedisKeyVal) RPopInt

func (o *RedisKeyVal) RPopInt(key string) int

func (*RedisKeyVal) RPush

func (o *RedisKeyVal) RPush(key string, val interface{}) error

func (*RedisKeyVal) Range

func (o *RedisKeyVal) Range(key string, start int64, stop int64) []string

func (*RedisKeyVal) Set

func (o *RedisKeyVal) Set(key string, val interface{}, ttl ...time.Duration) error

func (*RedisKeyVal) SetNX

func (o *RedisKeyVal) SetNX(key string, val interface{}, ttl ...time.Duration) bool

type RedisQueue

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

func (*RedisQueue) Consume

func (o *RedisQueue) Consume(name string, consumer QueueConsumerFunc) error

func (*RedisQueue) Publish

func (o *RedisQueue) Publish(name string, payload interface{}) error

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"`
}

type SecretFunc

type SecretFunc func(dsn string, key string) (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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