package data import ( "context" "encoding/json" "gorm.io/gorm" ) type Message struct { Src string `json:"src"` Dst string `json:"dst"` Msg string `json:"msg"` } func (m *Message) Convert(msgBody []byte) error { if err := json.Unmarshal(msgBody, &m); err != nil { return err } return nil } func (m *Message) Insert(ctx context.Context, db *gorm.DB) error { if err := db.WithContext(ctx).Create(&m).Error; err != nil { return err } return nil }