interfaces

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2021 License: MIT Imports: 10 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigManual = map[string]string{
	"config:mysql:enable": `enable mysql database`,
	"config:mysql:host": `mysql server address, must be valid rules hostname_rfc1123
	ex: localhost, 127.0.0.1, service.domain, 10.10.10.10, etc.`,
	"config:mysql:port":     `mysql server port number`,
	"config:mysql:username": `mysql server username`,
	"config:mysql:password": `mysql server password`,
	"config:mysql:database": `mysql database name`,
	"config:mysql:options":  `this option will be added after username:password@protocol(address)/dbname?`,
	"config:mysql: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.
	see more : https://github.com/go-sql-driver/mysql`,
	"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.`,
}

Functions

func SetManual

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

Types

type ConsumerCallbacIsDone

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

type ConsumerCallback

type ConsumerCallback func(Messages, ConsumerCallbacIsDone)

type Database

type Database interface {
	Init(logger.Logger)
	SetTracer(tracing.Tracing)
	LoadRabbitMQ(string, RabbitMQProviderConfig) RabbitMQ
	LoadSQL(string, SQLConfig) SQL
	NewSQL(SQLConfig) SQL
	LoadEmbedded(EmbeddedOptions) Embedded
}

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
)

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 Provider

type Provider int
const (
	ProviderMysql Provider = iota + 1
)

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 SQL

type SQL interface {
	Orm() *gorm.DB
	MySQL() error
	SQLServer() error
	Close() error
}

type SQLConfig

type SQLConfig struct {
	Enable     bool   `yaml:"enable" default:"false" desc:"config:mysql:enable"`
	Host       string `yaml:"host" default:"127.0.0.1" desc:"config:mysql:host"`
	Port       int    `yaml:"port" default:"3306" desc:"config:mysql:port"`
	Username   string `yaml:"username" default:"root"  desc:"config:mysql:username"`
	Password   string `yaml:"password" default:"root" desc:"config:mysql:password"`
	Database   string `yaml:"database" default:"mydb" desc:"config:mysql:database"`
	Options    string `yaml:"options" default:"" desc:"config:mysql:options"`
	Connection string `yaml:"connection" default:"" desc:"config:mysql:connection"`
}

Jump to

Keyboard shortcuts

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