/
forms.go
43 lines (35 loc) · 1013 Bytes
/
forms.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
// Renders various HTML forms
package templates
import (
"reflect"
"strings"
"meguca/config"
)
func configurationTable(l string, v reflect.Value, key string) string {
// Copy over all spec structs, so the mutations don't affect them
noValues := specs[key]
withValues := make([]inputSpec, len(noValues))
copy(withValues, noValues)
// Assign values to all specs
for i, s := range withValues {
v := v.FieldByName(strings.Title(s.ID))
if !v.IsValid() {
continue
}
switch k := v.Kind(); k {
case reflect.Int:
v = v.Convert(reflect.TypeOf(int64(0)))
}
withValues[i].Val = v.Interface()
}
return tableForm(l, withValues)
}
// Renders the form for changing server configuration.
func ConfigureServer(l string, conf config.ServerConfig) string {
v := reflect.ValueOf(conf)
return configurationTable(l, v, "configureServer")
}
// ChangePassword renders a form for changing an account's password
func ChangePassword(l string) string {
return tableForm(l, specs["changePassword"])
}