gofactory

package module
v0.0.0-...-6035df5 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2025 License: MIT Imports: 35 Imported by: 0

README

gofactory

A microservice framework that can be quickly built, supporting service registration and discovery (based on redis)

  • Supported servers include: http service, tcp service, mqtt broker(v5), websocket service(requires http service support)
  • Supported clients include: rabbitmq, mqtt(v3/v5), database(mysql/sqlserver), redis

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OptDBHost

func OptDBHost(driver db.Drive, host, username, password string, databases ...string) dbOpts

func OptDiscoverByRedis

func OptDiscoverByRedis(opts ...redisOpts) discoverOpts

func OptDiscoverByUDP

func OptDiscoverByUDP(port int) discoverOpts

func OptDiscoverInfo

func OptDiscoverInfo(name, alias, source, rootpath string, address map[ProtocolType]string) discoverOpts

func OptDiscoverInfoTimeout

func OptDiscoverInfoTimeout(timeo, interval time.Duration) discoverOpts

OptDiscoverInfoTimeout sets the timeout of service info.

The timeout should between 1 minute and 3 seconds.

func OptMqttAddr

func OptMqttAddr(s string) mqttBrokerOpts

func OptMqttAuth

func OptMqttAuth(user, pwd string) mqttOpts

func OptMqttAuthConfig

func OptMqttAuthConfig(ac *auth.Ledger) mqttBrokerOpts

func OptMqttAuthFromfile

func OptMqttAuthFromfile(f string) mqttBrokerOpts

func OptMqttClientBufferSize

func OptMqttClientBufferSize(s int) mqttBrokerOpts

func OptMqttClientID

func OptMqttClientID(s string) mqttOpts

func OptMqttFailureCache

func OptMqttFailureCache(max int, expire time.Duration, expireFunc func(topic string, body []byte)) mqttOpts

func OptMqttHost

func OptMqttHost(s string, t *tls.Config) mqttOpts

func OptMqttInsideClient

func OptMqttInsideClient(b bool) mqttBrokerOpts

func OptMqttMaxMsgExpirySeconds

func OptMqttMaxMsgExpirySeconds(t time.Duration) mqttBrokerOpts

func OptMqttMaxSessionExpirySeconds

func OptMqttMaxSessionExpirySeconds(t time.Duration) mqttBrokerOpts

func OptMqttRecvFunc

func OptMqttRecvFunc(f func(topic string, body []byte)) mqttOpts

func OptMqttSendTimeout

func OptMqttSendTimeout(d time.Duration) mqttOpts

func OptMqttSubscribe

func OptMqttSubscribe(s map[string]byte) mqttOpts

func OptMqttTlsAddr

func OptMqttTlsAddr(s string, t *tls.Config) mqttBrokerOpts

func OptMqttTlsFromFile

func OptMqttTlsFromFile(s, cert, key, ca string) mqttBrokerOpts

func OptMqttWSAddr

func OptMqttWSAddr(s string) mqttBrokerOpts

func OptMqttWebAddr

func OptMqttWebAddr(s string) mqttBrokerOpts

func OptRedisAddr

func OptRedisAddr(s string) redisOpts

func OptRedisAuth

func OptRedisAuth(user, pwd string) redisOpts

func OptRedisDatabase

func OptRedisDatabase(i int) redisOpts

func OptRedisReadTimeout

func OptRedisReadTimeout(d time.Duration) redisOpts

func OptRedisWriteTimeout

func OptRedisWriteTimeout(d time.Duration) redisOpts

func OptRmqAuth

func OptRmqAuth(addr, host, user, pwd string, t *tls.Config) rmqOpts

func OptRmqConsumer

func OptRmqConsumer(exchange, queueName string, queueDurable, queueAutoDelete bool, recvFunc func(topic string, body []byte)) rmqOpts

func OptRmqProducer

func OptRmqProducer(exchange string) rmqOpts

func OptTCPBindAddr

func OptTCPBindAddr(s string) tcpOpts

func OptTCPClient

func OptTCPClient(c tcpfactory.Client) tcpOpts

func OptTCPHelloMessages

func OptTCPHelloMessages(m []*tcpfactory.SendMessage) tcpOpts

func OptTCPReadTimeout

func OptTCPReadTimeout(t time.Duration) tcpOpts

func OptWebBind

func OptWebBind(s, cert, key string) webOpts

func OptWebEngineFunc

func OptWebEngineFunc(f func() *gin.Engine) webOpts

func OptWebHosts

func OptWebHosts(hosts ...string) webOpts

func OptWebTimeout

func OptWebTimeout(read, write, idle time.Duration) webOpts

Types

type Opt

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

type Opts

type Opts func(opt *Opt)

func SetMode

func SetMode(m RunMode) Opts

func WithBoltDB

func WithBoltDB(name string) Opts

func WithDBClient

func WithDBClient(opts ...dbOpts) Opts

func WithDiscover

func WithDiscover(opts ...discoverOpts) Opts

func WithEmptyServer

func WithEmptyServer() Opts

func WithLogger

func WithLogger(l logger.Logger) Opts

func WithMQTTBroker

func WithMQTTBroker(opts ...mqttBrokerOpts) Opts

func WithMqttClient

func WithMqttClient(opts ...mqttOpts) Opts

func WithRMQConsumer

func WithRMQConsumer(opts ...rmqOpts) Opts

func WithRedisClient

func WithRedisClient(opts ...redisOpts) Opts

func WithRmqProducer

func WithRmqProducer(opts ...rmqOpts) Opts

func WithTCPServer

func WithTCPServer(opts ...tcpOpts) Opts

func WithWebServer

func WithWebServer(opts ...webOpts) Opts

type ProtocolType

type ProtocolType byte
const (
	ProtocolTCP ProtocolType = iota
	ProtocolHTTP
	ProtocolHTTPS
	ProtocolMQTT
	ProtocolMQTTTLS
	ProtocolMQTTWS
)

type RunMode

type RunMode byte
const (
	Dev RunMode = iota
	Debug
	Release
)

type Service

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

func New

func New(opts ...Opts) (*Service, error)

func (*Service) AppendRootPath

func (s *Service) AppendRootPath(ss, sep string) string

func (*Service) DBClient

func (s *Service) DBClient(dbidx int) (*sql.DB, error)

DBClient returns a *sql.DB connection for the specified database index. It ensures the database index is within the valid range before retrieving the SQL database client.

func (*Service) DBExec

func (s *Service) DBExec(sql string, args ...interface{}) (int64, int64, error)

func (*Service) DBExecBydb

func (s *Service) DBExecBydb(dbidx int, sql string, args ...interface{}) (int64, int64, error)

func (*Service) DBExecPrepare

func (s *Service) DBExecPrepare(sql string, args ...interface{}) error

func (*Service) DBExecPrepareBydb

func (s *Service) DBExecPrepareBydb(dbidx int, sql string, args ...interface{}) error

func (*Service) DBOrm

func (s *Service) DBOrm(dbidx int) (*gorm.DB, error)

func (*Service) DBQuery

func (s *Service) DBQuery(sql string, rowcount int, args ...interface{}) (*db.QueryData, error)

func (*Service) DBQueryBydb

func (s *Service) DBQueryBydb(dbidx int, sql string, rowcount int, args ...interface{}) (*db.QueryData, error)

func (*Service) DoRequest

func (s *Service) DoRequest(req *http.Request, opts ...httpclient.ReqOpts) (int, []byte, map[string]string, error)

func (*Service) MqttBrokerSubscribe

func (s *Service) MqttBrokerSubscribe(topic string, subscriptionId int, handler mqtt.InlineSubFn) error

func (*Service) MqttBrokerWrite

func (s *Service) MqttBrokerWrite(topic string, body []byte, qos byte) error

func (*Service) MqttWrite

func (s *Service) MqttWrite(topic string, body []byte, qos byte) error

func (*Service) PickAll

func (s *Service) PickAll() map[string]string

func (*Service) PickService

func (s *Service) PickService(name string, protocol ProtocolType) (string, error)

func (*Service) RMQWrite

func (s *Service) RMQWrite(topic string, body []byte, expire time.Duration)

func (*Service) RedisClientLoaded

func (s *Service) RedisClientLoaded() error

func (*Service) RedisDelHashField

func (s *Service) RedisDelHashField(key, field string) error

func (*Service) RedisDelKey

func (s *Service) RedisDelKey(key string) error

func (*Service) RedisExpireKey

func (s *Service) RedisExpireKey(key string, expire time.Duration) error

func (*Service) RedisRead

func (s *Service) RedisRead(key string) (string, error)

func (*Service) RedisReadHashField

func (s *Service) RedisReadHashField(key, field string) (string, error)

func (*Service) RedisReadHashMap

func (s *Service) RedisReadHashMap(key string) (map[string]string, error)

func (*Service) RedisReadKeys

func (s *Service) RedisReadKeys(key string) ([]string, error)

func (*Service) RedisWrite

func (s *Service) RedisWrite(key string, value any, expire time.Duration) error

func (*Service) RedisWriteHashField

func (s *Service) RedisWriteHashField(key, field string, value any) error

func (*Service) RedisWriteHashMap

func (s *Service) RedisWriteHashMap(key string, value map[string]any) error

func (*Service) Run

func (s *Service) Run()

func (*Service) Start

func (s *Service) Start()

func (*Service) TcpWrite

func (s *Service) TcpWrite(target string, msgs ...*tcpfactory.SendMessage)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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