123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package pomeloClient
- import (
- "time"
- cfacade "github.com/mhaya/facade"
- )
- type (
- options struct {
- serializer cfacade.ISerializer // protocol serializer
- heartBeat int // second
- requestTimeout time.Duration // Send request timeout
- handshake string // handshake content
- isErrorBreak bool // an error occurs,is it break
- }
- Option func(options *options)
- // HandshakeSys struct
- HandshakeSys struct {
- Dict map[string]uint16 `json:"dict"`
- Heartbeat int `json:"heartbeat"`
- Serializer string `json:"serializer"`
- }
- // HandshakeData struct
- HandshakeData struct {
- Code int `json:"code"`
- Sys HandshakeSys `json:"sys"`
- }
- )
- func (p *options) Serializer() cfacade.ISerializer {
- return p.serializer
- }
- func WithSerializer(serializer cfacade.ISerializer) Option {
- return func(options *options) {
- options.serializer = serializer
- }
- }
- func WithHeartbeat(heartBeat int) Option {
- return func(options *options) {
- options.heartBeat = heartBeat
- }
- }
- func WithRequestTimeout(requestTimeout time.Duration) Option {
- return func(options *options) {
- options.requestTimeout = requestTimeout
- }
- }
- func WithHandshake(handshake string) Option {
- return func(options *options) {
- options.handshake = handshake
- }
- }
- func WithErrorBreak(isBreak bool) Option {
- return func(options *options) {
- options.isErrorBreak = isBreak
- }
- }
|