~repos /gromer

#golang#htmx#ssr

git clone https://pyrossh.dev/repos/gromer.git

gromer is a framework and cli to build multipage web apps in golang using htmx and alpinejs.


2b1a6b29 Peter John

4 years ago
Fix field name
Files changed (1) hide show
  1. cmd/gromer/main.go +11 -5
cmd/gromer/main.go CHANGED
@@ -173,8 +173,10 @@ func main() {
173
173
  if st, ok := typeSpec.Type.(*ast.StructType); ok {
174
174
  mapsOfInputParams[typeSpec.Name.Name] = map[string]interface{}{}
175
175
  for _, f := range st.Fields.List {
176
+ if len(f.Names) > 0 {
176
- fieldName := lowerFirst(f.Names[0].Name)
177
+ fieldName := lowerFirst(f.Names[0].Name)
177
- mapsOfInputParams[typeSpec.Name.Name][fieldName] = fmt.Sprintf("%+s", f.Type)
178
+ mapsOfInputParams[typeSpec.Name.Name][fieldName] = fmt.Sprintf("%+s", f.Type)
179
+ }
178
180
  }
179
181
  }
180
182
  }
@@ -184,9 +186,13 @@ func main() {
184
186
  if decl.Name.Name == method {
185
187
  list := decl.Type.Params.List
186
188
  lastParam := list[len(list)-1]
189
+ if spec, ok := lastParam.Type.(*ast.Ident); ok {
190
+ if spec.IsExported() {
187
- lastParamTypeName := fmt.Sprintf("%+s", lastParam.Type)
191
+ // TODO: need to read from imported files and pick up the struct and
192
+ // convert it to json
188
- if v, ok := mapsOfInputParams[lastParamTypeName]; ok {
193
+ } else if v, ok := mapsOfInputParams[spec.Name]; ok {
189
- params = v
194
+ params = v
195
+ }
190
196
  }
191
197
  }
192
198
  }