-
Notifications
You must be signed in to change notification settings - Fork 4
/
timestamp.go
45 lines (38 loc) · 1.14 KB
/
timestamp.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
package types
import (
"github.com/dave/jennifer/jen"
"github.com/dipdup-net/go-lib/tzkt/api"
)
// Timestamp -
type Timestamp struct{}
// AsField -
func (Timestamp) AsField(name, path string, schema api.JSONSchema, isRequired bool, result *ContractTypeResult) (jen.Code, error) {
tags := map[string]string{
"json": name,
}
if isRequired {
tags["validate"] = TagRequired
}
return jen.Id(fieldName("Time", name)).Add(
jen.Qual("github.com/dipdup-net/go-lib/tools/tezgen", "Timestamp"),
).Tag(tags), nil
}
// AsCode -
func (Timestamp) AsCode(name, path string, schema api.JSONSchema, result *ContractTypeResult) (Code, error) {
typName := result.GetName("Time", name)
return Code{
Statement: jen.Comment(typName).Line().Type().Id(typName).Add(
jen.Qual("github.com/dipdup-net/go-lib/tools/tezgen", "Timestamp"),
).Line(),
Name: typName,
}, nil
}
// AsType -
func (Timestamp) AsType(name, path string, schema api.JSONSchema, result *ContractTypeResult) (Code, error) {
return Code{
Statement: jen.Add(
jen.Qual("github.com/dipdup-net/go-lib/tools/tezgen", "Timestamp"),
).Line(),
Name: result.GetName("Time", name),
}, nil
}