interfaces

package
v1.0.1003 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2024 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigManual = map[string]string{

	"config:autoReconnect": `auto reconnect database in first init`,
	"config:startInterval": `first timeout duration after failed`,
	"config:maxError":      `how many reconnect before trigger error`,

	"config:sql:name":   `database config name, optional`,
	"config:sql:enable": `enable sql database`,
	"config:sql:host": `sql server address, must be valid rules hostname_rfc1123
	ex: localhost, 127.0.0.1, service.domain, 10.10.10.10, etc.`,
	"config:sql:port":     `sql server port number`,
	"config:sql:username": `sql server username`,
	"config:sql:password": `sql server password`,
	"config:sql:database": `sql database name`,
	"config:sql:options":  `this option will be added after connection string`,
	"config:sql:connection": `if this value not empty, another mysql parameter will be ignored.
	use this, if you have a custom protocol connection.
	like username:password@unix(/tmp/mysql.sock)/dbname.`,
	"config:sql:dbPath": `sqlite database file location path`,
	"config:redis:name": `database config name, optional`,
	"config:redis:host": `redis server address, must be valid rules hostname_rfc1123
	ex: localhost, 127.0.0.1, service.domain, 10.10.10.10, etc.`,
	"config:redis:port":     `redis server port number`,
	"config:redis:password": `redis server password`,
	"config:redis:pool":     `number of redis pool`,
	"config:mongo:name":     `database config name, optional`,
}
View Source
var RecordNotFound = errors.New("record not found in database")

RecordNotFound - global error record not found type

Functions

func SetManual

func SetManual(man map[string]string) map[string]string

Types

type Database

type Database interface {
	Init(logger.Logger) Database
	SetTracer(tracing.Tracing)
	LoadSQL(string, SQLConfig) SQL
	LoadRedis(string, RedisProviderConfig) Redis
	LoadEmbedded(EmbeddedOptions) Embedded
	LoadMongo(tag string, config MongoProviderConfig) Mongo
}

type Embedded

type Embedded interface {
	DB() *nutsdb.DB
	Set(bucket string, key string, value interface{}, encoding Encoding) (err error)
	Get(bucket string, key string, value interface{}, encoding Encoding) (err error)
	Delete(bucket string, key string) (err error)
	GetAllKeys(bucket string) (keys []string, err error)
}

type EmbeddedOptions

type EmbeddedOptions struct {
	Directory string
}

type Encoder

type Encoder struct {
	Raw      io.Reader
	Encoding Encoding
	// contains filtered or unexported fields
}

func (*Encoder) Context

func (c *Encoder) Context() context.Context

func (*Encoder) Decode

func (c *Encoder) Decode(data interface{}) error

func (*Encoder) Encode

func (c *Encoder) Encode(data interface{}) (res []byte, err error)

func (*Encoder) Exchange

func (c *Encoder) Exchange() string

func (*Encoder) RoutingKey

func (c *Encoder) RoutingKey() string

func (*Encoder) SetContext

func (c *Encoder) SetContext(ctx context.Context)

type Encoding

type Encoding int
const (
	EncodingBase64Gob Encoding = iota
	EncodingGob
	EncodingProto
	EncodingNone
	EncodingJSON
)

type Messages

type Messages interface {
	Exchange() string
	RoutingKey() string
	Decode(interface{}) error
	SetContext(context.Context)
	Context() context.Context
}

func NewEncoder

func NewEncoder(raw io.Reader, exchange, routingKey string, enc Encoding) Messages

type Mongo

type Mongo interface {
	Client() *mongo.Client
	Start() (err error)
	UseEncryption(encLib encryption.Encryption) Mongo
	ODM() MongoODM
	WithMonitor(enable bool) Mongo
	GetConfig() MongoProviderConfig
}

type MongoIndex

type MongoIndex struct {
	Collection         string
	Field              string
	Unique             bool
	Compound           bool
	PrimaryKey         bool
	Desc               bool
	ExpiredAfterSecond int32
}

MongoIndex - indexing mongodb

type MongoODM

type MongoODM interface {
	Error() error
	Collection(model interface{}, name string) MongoODM
	NativeCollection() *mongo.Collection
	Index() MongoODM
	Create(ctx context.Context, data interface{}) *MongoTransaction
	Upsert(ctx context.Context, data interface{}, matchKey []string) *MongoTransaction
	Filter(filter map[string]interface{}) MongoODM
	Find(ctx context.Context, dest interface{}) *MongoTransaction
	FindRaw(ctx context.Context) (results []bson.Raw, cc *MongoTransaction)
	Drop(ctx context.Context) MongoODM
	Update(ctx context.Context, data map[string]interface{}) *MongoTransaction
	Delete(ctx context.Context) *MongoTransaction
	SetSort(sortBy string, desc bool) MongoODM
	SetLimit(limit int64) MongoODM
	SetSkip(skip int64) MongoODM
	Count(ctx context.Context) (res int64, err error)
}

type MongoProviderConfig

type MongoProviderConfig struct {
	Name              string `yaml:"name" default:"" desc:"config:mongo:name"`
	Enable            bool   `yaml:"enable" default:"false" desc:"config:mongo:enable"`
	Uri               string `yaml:"uri" default:"" desc:"config:mongo:uri"`
	Host              string `yaml:"host" default:"127.0.0.1" desc:"config:mongo:host"`
	Port              int    `yaml:"port" default:"27017" desc:"config:mongo:port"`
	UserName          string `yaml:"username" default:"root" desc:"config:mongo:username"`
	Password          string `yaml:"password" default:"root" desc:"config:mongo:password"`
	Database          string `yaml:"database" default:"sample_database" desc:"config:mongo:database"`
	Options           string `yaml:"options" default:"" desc:"config:mongo:options"`
	TimeoutConnection int    `yaml:"timeoutConnection" default:"5000" desc:"config:mongo:timeoutConnection"`
	AutoReconnect     bool   `yaml:"autoReconnect" default:"false"  desc:"config:autoReconnect"`
	StartInterval     int    `yaml:"startInterval" default:"2"  desc:"config:startInterval"`
	MaxError          int    `yaml:"maxError" default:"5"  desc:"config:maxError"`
}

MongoProviderConfig - Mongodb configuration

If Uri not empty, Host, Port, UserName, Password and Options will be ignored

type MongoTransaction

type MongoTransaction struct {
	Error        error
	InsertedIDs  []primitive.ObjectID
	EffectedIDs  []primitive.ObjectID
	DeletedCount int64
}

type ORM

type ORM interface {
	AutoMigrate(dst ...interface{}) (err error)
	Model(dst interface{}) OrmModel
}

ORM - Overlay for Gorm Interfaces

type OrmModel

type OrmModel interface {
	Debug() OrmModel
	WithContext(ctx context.Context) OrmModel
	Drop() error
	Truncate() error
	Limit(limit int) OrmModel
	Offset(offset int) OrmModel
	Order(query ...clause.OrderByColumn) OrmModel
	Equal(query ...interface{}) OrmModel
	NotEqual(query ...interface{}) OrmModel
	Or(query ...interface{}) OrmModel
	Create(data interface{}) (err error)
	Upsert(data interface{}) (err error)
	Update(data map[string]interface{}) (err error)
	Find(dst interface{}) error
	First(dst interface{}) error
	FindRaw() (res []interface{}, err error)
	Delete() (rowEffected int64, err error)
	Where(query interface{}, args ...interface{}) OrmModel
}

type Provider

type Provider int

type Redis

type Redis interface {
	Init() error
	GetClient() (pool radix.Client)
	GetConfig() RedisProviderConfig
}

type RedisProviderConfig

type RedisProviderConfig struct {
	Name          string `yaml:"name" default:"" desc:"config:redis:name"`
	Enable        bool   `yaml:"enable" default:"false" desc:"config:redis:enable"`
	Host          string `yaml:"host" default:"127.0.0.1" desc:"config:redis:host"`
	Port          int    `yaml:"port" default:"6379" desc:"config:redis:port"`
	Password      string `yaml:"password" default:"" desc:"config:redis:password"`
	Pool          int    `yaml:"pool" default:"10" desc:"config:redis:pool"`
	AutoReconnect bool   `yaml:"autoReconnect" default:"false"  desc:"config:autoReconnect"`
	StartInterval int    `yaml:"startInterval" default:"2"  desc:"config:startInterval"`
	MaxError      int    `yaml:"maxError" default:"5"  desc:"config:maxError"`
}

type SQL

type SQL interface {
	Config() SQLConfig
	UseEncryption(encLib encryption.Encryption) SQL
	Gorm() *gorm.DB
	ORM() ORM
	Start() error
	Close() error
	GetEncryption() (encLib encryption.Encryption)
}

type SQLConfig

type SQLConfig struct {
	Name               string `yaml:"name" default:"" desc:"config:sql:name"`
	Driver             string `yaml:"driver" default:"mysql" desc:"config:sql:enable"`
	Enable             bool   `yaml:"enable" default:"false" desc:"config:sql:enable"`
	Host               string `yaml:"host" default:"127.0.0.1" desc:"config:sql:host"`
	Port               int    `yaml:"port" default:"3306" desc:"config:sql:port"`
	Username           string `yaml:"username" default:"root"  desc:"config:sql:username"`
	Password           string `yaml:"password" default:"root" desc:"config:sql:password"`
	Database           string `yaml:"database" default:"sample_database" desc:"config:sql:database"`
	Options            string `yaml:"options" default:"" desc:"config:sql:options"`
	Connection         string `yaml:"connection" default:"" desc:"config:sql:connection"`
	AutoReconnect      bool   `yaml:"autoReconnect" default:"false"  desc:"config:autoReconnect"`
	StartInterval      int    `yaml:"startInterval" default:"2"  desc:"config:startInterval"`
	MaxError           int    `yaml:"maxError" default:"5"  desc:"config:maxError"`
	DBPath             string `yaml:"dbPath" default:"./sqlite.db" desc:"config:sql:dbPath"`
	SsLMode            string `yaml:"sslMode" default:"disable" desc:"config:sql:sslMode"`
	TimeoutConnection  int    `yaml:"timeoutConnection" default:"5000" desc:"config:sql:timeoutConnection"`
	TimeoutTransaction int    `yaml:"timeoutTransaction" default:"5000" desc:"config:sql:timeoutTransaction"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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