mirror of
https://github.com/singchia/frontier.git
synced 2025-10-07 09:10:58 +08:00
74 lines
1.6 KiB
Go
74 lines
1.6 KiB
Go
package service
|
|
|
|
import (
|
|
"github.com/jumboframes/armorigo/log"
|
|
|
|
"github.com/singchia/geminio/delegate"
|
|
"github.com/singchia/go-timer/v2"
|
|
)
|
|
|
|
type Logger log.Logger
|
|
type Timer timer.Timer
|
|
|
|
type Delegate delegate.ClientDelegate
|
|
|
|
type serviceOption struct {
|
|
logger Logger
|
|
tmr Timer
|
|
// to tell frontier which topics to receive, default no receiving
|
|
topics []string
|
|
// to tell frontier what service we are
|
|
service string
|
|
// delegate to know online offline stuff
|
|
delegate Delegate
|
|
serviceID uint64
|
|
readBufferSize, writeBufferSize int
|
|
}
|
|
|
|
type ServiceOption func(*serviceOption)
|
|
|
|
func OptionServiceLog(logger Logger) ServiceOption {
|
|
return func(opt *serviceOption) {
|
|
opt.logger = logger
|
|
}
|
|
}
|
|
|
|
// Pre set timer for the sdk
|
|
func OptionServiceTimer(tmr Timer) ServiceOption {
|
|
return func(opt *serviceOption) {
|
|
opt.tmr = tmr
|
|
}
|
|
}
|
|
|
|
func OptionServiceReceiveTopics(topics []string) ServiceOption {
|
|
return func(opt *serviceOption) {
|
|
opt.topics = topics
|
|
}
|
|
}
|
|
|
|
func OptionServiceName(service string) ServiceOption {
|
|
return func(opt *serviceOption) {
|
|
opt.service = service
|
|
}
|
|
}
|
|
|
|
// delegations for the service own connection, streams and more
|
|
func OptionServiceDelegate(delegate Delegate) ServiceOption {
|
|
return func(opt *serviceOption) {
|
|
opt.delegate = delegate
|
|
}
|
|
}
|
|
|
|
func OptionServiceID(serviceID uint64) ServiceOption {
|
|
return func(opt *serviceOption) {
|
|
opt.serviceID = serviceID
|
|
}
|
|
}
|
|
|
|
func OptionServiceBufferSize(read, write int) ServiceOption {
|
|
return func(opt *serviceOption) {
|
|
opt.readBufferSize = read
|
|
opt.writeBufferSize = write
|
|
}
|
|
}
|