-
Notifications
You must be signed in to change notification settings - Fork 4
/
string.go
39 lines (32 loc) · 950 Bytes
/
string.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
package types
import (
"github.com/dave/jennifer/jen"
"github.com/dipdup-net/go-lib/tzkt/api"
)
// String -
type String struct{}
// AsField -
func (String) 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(schema.Comment, name)).String().Tag(tags), nil
}
// AsCode -
func (String) AsCode(name, path string, schema api.JSONSchema, result *ContractTypeResult) (Code, error) {
typ := result.GetName(schema.Comment, name)
return Code{
Statement: jen.Comment(typ).Line().Type().Id(typ).String().Line(),
Name: typ,
}, nil
}
// AsType -
func (String) AsType(name, path string, schema api.JSONSchema, result *ContractTypeResult) (Code, error) {
return Code{
Statement: jen.String(),
Name: result.GetName(schema.Comment, name),
}, nil
}