interfaces

package
v1.0.1001 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: MIT Imports: 18 Imported by: 0

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:rabbitmq:enable": `enable rabbitmq database message brokers`,
	"config:rabbitmq:host": `rabbitmq server address, must be valid rules hostname_rfc1123
	ex: localhost, 127.0.0.1, service.domain, 10.10.10.10, etc.`,
	"config:rabbitmq:port":                `rabbitmq server port number`,
	"config:rabbitmq:username":            `rabbitmq server username`,
	"config:rabbitmq:password":            `rabbitmq server password`,
	"config:rabbitmq:reconnectDuration":   `rabbitmq reconnect duration (in second).`,
	"config:rabbitmq:dedicatedConnection": `dedicated connection for each consumer, more reliable but more cost.`,
	"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 ConsumerCallback

type ConsumerCallback func(Messages, ConsumerCallbackIsDone)

type ConsumerCallbackIsDone

type ConsumerCallbackIsDone struct {
	Done       context.CancelFunc
	EndRequest func()
}

type Database

type Database interface {
	Init(logger.Logger) Database
	SetTracer(tracing.Tracing)
	LoadRabbitMQ(string, RabbitMQProviderConfig) RabbitMQ
	LoadSQL(string, SQLConfig) SQL
	LoadRedis(string, RedisProviderConfig) Redis
	LoadEmbedded(EmbeddedOptions) Embedded
	LoadKafka(string, KafkaProviderConfig) Kafka
	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 Kafka

type Kafka interface {
	Consumer(KafkaOptions, ConsumerCallback)
	Producer(ProducerIsReady)
	Push(ctx context.Context, id string, options KafkaOptions, body interface{}, cb ConsumerCallback) error
}

type KafkaOptions

type KafkaOptions struct {
	Topic          string
	RegistryValue  string
	Group          string
	SchemeVersion  int
	SchemeID       int
	Encoding       Encoding
	MultipleThread bool
	Limiter        int
}

type KafkaProviderConfig

type KafkaProviderConfig struct {
	Enable           bool   `yaml:"enable" default:"false" desc:"config:kafka:enable"`
	Host             string `yaml:"host" default:"127.0.0.1:9092" desc:"config:kafka:host"`
	Registry         string `yaml:"registry" default:"" desc:"config:kafka:registry"`
	Username         string `yaml:"username" default:""  desc:"config:kafka:username"`
	Password         string `yaml:"password" default:"" desc:"config:kafka:password"`
	SecurityProtocol string `yaml:"securityProtocol" default:"SASL_SSL"  desc:"config:kafka:securityProtocol"`
	Mechanisms       string `yaml:"mechanisms" default:"PLAIN"  desc:"config:kafka:mechanisms"`
	Debug            string `yaml:"debug" default:"consumer"  desc:"config:kafka:debug"`
}

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 ProducerIsReady

type ProducerIsReady func()

type Provider

type Provider int

type RabbitMQ

type RabbitMQ interface {
	Consumer(RabbitMQOptions, ConsumerCallback)
	Producer(RabbitMQOptions)
	Push(ctx context.Context,
		id, exchange,
		key string,
		body interface{},
		cb ConsumerCallback) error
}

type RabbitMQOptions

type RabbitMQOptions struct {
	Exchange     string
	ExchangeType string
	RoutingKey   string
	Durable      bool
	AutoDeleted  bool
	NoWait       bool
	Encoding     Encoding
}

type RabbitMQProviderConfig

type RabbitMQProviderConfig struct {
	Enable              bool   `yaml:"enable" default:"false" desc:"config:rabbitmq:enable"`
	Host                string `yaml:"host" default:"127.0.0.1" desc:"config:rabbitmq:host"`
	Port                int    `yaml:"port" default:"5672" desc:"config:rabbitmq:port"`
	Username            string `yaml:"username" default:"guest"  desc:"config:rabbitmq:username"`
	Password            string `yaml:"password" default:"guest" desc:"config:rabbitmq:password"`
	ReconnectDuration   int    `yaml:"reconnectDuration" default:"5" desc:"config:rabbitmq:reconnectDuration"`
	DedicatedConnection bool   `yaml:"dedicatedConnection" default:"false" desc:"config:rabbitmq:dedicatedConnection"`
}

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