Authenticate Handler API and SDK, and much more (#183)
This commit is contained in:
1 parent
acce195dcb
commit
28dbcd84bd
89 files changed
+5296
-1943
No files matched your search
@@ -25,10 +25,12 @@ func writeStructTemplates() {
|
||||
Name string
|
||||
Package string
|
||||
StructFields string
|
||||
NameJsonMap map[string]string
|
||||
}{
|
||||
Name: inputStruct.outName,
|
||||
Package: inputStruct.outPkg,
|
||||
StructFields: inputStruct.structFields,
|
||||
NameJsonMap: inputStruct.nameJsonMap,
|
||||
})
|
||||
|
||||
case templateTypeDetail:
|
||||
@@ -61,11 +63,12 @@ func writeStructTemplates() {
|
||||
// TODO: Add documentation around SetDefault and how it behaves when the field corresponding to the provided key is already set.
|
||||
var structTemplate = template.Must(template.New("").Parse(
|
||||
`// Code generated by "make api"; DO NOT EDIT.
|
||||
package {{ .Package }}
|
||||
package {{ .Package }}
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/structs"
|
||||
|
||||
@@ -82,11 +85,25 @@ type {{ .Name }} struct {
|
||||
}
|
||||
|
||||
func (s *{{ .Name }}) SetDefault(key string) {
|
||||
s.defaultFields = strutil.AppendIfMissing(s.defaultFields, key)
|
||||
lowerKey := strings.ToLower(key)
|
||||
validMap := {{ printf "%#v" .NameJsonMap }}
|
||||
for k, v := range validMap {
|
||||
if k == lowerKey || v == lowerKey {
|
||||
s.defaultFields = strutil.AppendIfMissing(s.defaultFields, v)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *{{ .Name }}) UnsetDefault(key string) {
|
||||
s.defaultFields = strutil.StrListDelete(s.defaultFields, key)
|
||||
lowerKey := strings.ToLower(key)
|
||||
validMap := {{ printf "%#v" .NameJsonMap }}
|
||||
for k, v := range validMap {
|
||||
if k == lowerKey || v == lowerKey {
|
||||
s.defaultFields = strutil.StrListDelete(s.defaultFields, v)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s {{ .Name }}) MarshalJSON() ([]byte, error) {
|
||||
|
||||
Reference in new issue
Block a user