-
Notifications
You must be signed in to change notification settings - Fork 0
/
comment.go
35 lines (30 loc) · 673 Bytes
/
comment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package robin
import (
"encoding/base64"
"encoding/json"
"fmt"
)
type Comment struct {
JobDataFilename string `json:"job_data_filename"`
}
func (c *Comment) IsEmpty() bool {
return c.JobDataFilename == ""
}
func (c *Comment) Encode() string {
commentJSON, _ := json.Marshal(c)
return base64.RawStdEncoding.EncodeToString(commentJSON)
}
func (c *Comment) Decode(data string) error {
if data == "" {
return nil
}
commentJSON, err := base64.RawStdEncoding.DecodeString(data)
if err != nil {
return fmt.Errorf("unquote json: %w", err)
}
err = json.Unmarshal(commentJSON, c)
if err != nil {
return fmt.Errorf("unmarshal JSON: %w", err)
}
return nil
}