mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-26 10:37:04 -06:00
This adds a new codegen that reads .noms files and generates Go API for these types Issue #304
29 lines
680 B
Cheetah
29 lines
680 B
Cheetah
// {{.Name}}
|
|
|
|
type {{.Name}} struct {
|
|
l types.List
|
|
}
|
|
|
|
func {{.Name}}FromVal(val types.Value) {{.Name}} {
|
|
// TODO: Validate here
|
|
return {{.Name}}{val.(types.List)}
|
|
}
|
|
|
|
func (self {{.Name}}) NomsValue() types.Value {
|
|
return self.l
|
|
}
|
|
|
|
{{$name := .Name}}
|
|
{{range $index, $field := .Choices}}
|
|
func (self {{$name}}) {{.Name}}() ({{userType .T}}, bool) {
|
|
if int32(self.l.Get(types.Int32(0)).(types.Int32) != {{$index}} {
|
|
return {{userZero .T}}, false
|
|
}
|
|
return {{valueToUser "self.l.Get(types.Int32(1))" .T}}, true
|
|
}
|
|
|
|
func (self {{$name}}) Set{{.Name}}(val {{userType .T}}) {{$name}} {
|
|
return {{$name}}{types.NewList(types.Int32({{$index}}), {{userToValue "val" .T}})}
|
|
}
|
|
{{end}}
|