Skip to content

Commit

Permalink
feat: Add the DefaultBodyCodec and SetDefaultBodyCodec
Browse files Browse the repository at this point in the history
Change-Id: I3dad7bc59f84b03097f1e039f5101d24272b7cb0
  • Loading branch information
andeya committed Jun 25, 2019
1 parent 8e88eb2 commit f8cb51a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion config.go
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"github.com/henrylee2cn/cfgo"
"github.com/henrylee2cn/teleport/codec"
"github.com/henrylee2cn/teleport/socket"
)

Expand Down Expand Up @@ -98,14 +99,31 @@ func (p *PeerConfig) check() error {
p.slowCometDuration = p.SlowCometDuration
}
if len(p.DefaultBodyCodec) == 0 {
p.DefaultBodyCodec = "json"
p.DefaultBodyCodec = DefaultBodyCodec().Name()
}
if p.RedialInterval <= 0 {
p.RedialInterval = time.Millisecond * 100
}
return nil
}

var defaultBodyCodec codec.Codec = new(codec.JSONCodec)

// DefaultBodyCodec gets the default body codec.
func DefaultBodyCodec() codec.Codec {
return defaultBodyCodec
}

// SetDefaultBodyCodec sets the default body codec.
func SetDefaultBodyCodec(codecID byte) error {
c, err := codec.Get(codecID)
if err != nil {
return err
}
defaultBodyCodec = c
return nil
}

// DefaultProtoFunc gets the default builder of socket communication protocol
// func DefaultProtoFunc() tp.ProtoFunc
var DefaultProtoFunc = socket.DefaultProtoFunc
Expand Down

0 comments on commit f8cb51a

Please sign in to comment.