/
file.go
53 lines (45 loc) · 1.08 KB
/
file.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package contract
import (
"encoding/json"
"fmt"
"time"
"dfss/dfssp/entities"
)
// FileJSON is the structure used to store file information in JSON format
type FileJSON struct {
Name string
Hash string
Hosted bool
}
// SignerJSON is the structure used to store signers information in JSON format
type SignerJSON struct {
Email string
Hash string
}
// JSON is the structure used to store contract information in JSON format
type JSON struct {
UUID string
Date *time.Time
Comment string
File *FileJSON
Signers []SignerJSON
}
// GetJSON returns indented json from a contract and some ttp information (nil allowed)
func GetJSON(c *entities.Contract) ([]byte, error) {
data := JSON{
UUID: c.ID.Hex(),
Date: &c.Date,
Comment: c.Comment,
File: &FileJSON{
Name: c.File.Name,
Hash: fmt.Sprintf("%x", c.File.Hash),
Hosted: c.File.Hosted,
},
Signers: make([]SignerJSON, len(c.Signers)),
}
for i, s := range c.Signers {
data.Signers[i].Email = s.Email
data.Signers[i].Hash = fmt.Sprintf("%x", s.Hash)
}
return json.MarshalIndent(data, "", " ")
}