gitee.com/woood2/luca@v1.0.4/internal/mq/greet.go (about) 1 package mq 2 3 import ( 4 "encoding/json" 5 ) 6 7 const TopicGreet = "luca_greet" 8 9 type Greet struct { 10 From string 11 To string 12 } 13 14 func (g *Greet) Topic() string { 15 return TopicGreet 16 } 17 18 func (g *Greet) Encode() (data []byte, err error) { 19 return json.Marshal(g) 20 } 21 22 func (g *Greet) Length() int { 23 if data, err := json.Marshal(g); err != nil { 24 return 0 25 } else { 26 return len(data) 27 } 28 } 29 30 func (g *Greet) Decode(data []byte) error { 31 return json.Unmarshal(data, g) 32 }