mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-18 04:40:03 +02:00
api/message: for codec implementations, define a function instead of global variables.
This commit is contained in:
parent
6801b536bf
commit
8ffd86daac
4 changed files with 41 additions and 38 deletions
|
|
@ -7,17 +7,19 @@ import (
|
|||
"github.com/eosswedenorg/thalos/api/message"
|
||||
)
|
||||
|
||||
var (
|
||||
json_codec = jsontime.ConfigWithCustomTimeFormat
|
||||
encoder = json_codec.Marshal
|
||||
decoder = json_codec.Unmarshal
|
||||
)
|
||||
func createCodec() message.Codec {
|
||||
json_codec := jsontime.ConfigWithCustomTimeFormat
|
||||
|
||||
return message.Codec{
|
||||
Encoder: json_codec.Marshal,
|
||||
Decoder: json_codec.Unmarshal,
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Set timeformat used by eos api.
|
||||
jsontime.SetDefaultTimeFormat("2006-01-02T15:04:05.000", time.UTC)
|
||||
|
||||
message.RegisterCodec("json", message.Codec{
|
||||
Encoder: encoder,
|
||||
Decoder: decoder,
|
||||
})
|
||||
// Register the json codec.
|
||||
message.RegisterCodec("json", createCodec())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue