highLevelConfFields returns all the possible fields of a serverconfig.Config, in their JSON form. This allows checking that the parameters in the high-level server configuration file are at least valid names, which is useful to catch typos.
()
| 912 | // server configuration file are at least valid names, which is useful to catch |
| 913 | // typos. |
| 914 | func highLevelConfFields() map[string]bool { |
| 915 | knownFields := make(map[string]bool) |
| 916 | var c serverconfig.Config |
| 917 | s := reflect.ValueOf(&c).Elem() |
| 918 | for i := 0; i < s.NumField(); i++ { |
| 919 | f := s.Type().Field(i) |
| 920 | jsonTag, ok := f.Tag.Lookup("json") |
| 921 | if !ok { |
| 922 | panic(fmt.Sprintf("%q field in serverconfig.Config does not have a json tag", f.Name)) |
| 923 | } |
| 924 | jsonFields := strings.Split(strings.TrimSuffix(strings.TrimPrefix(jsonTag, `"`), `"`), ",") |
| 925 | jsonName := jsonFields[0] |
| 926 | if jsonName == "" { |
| 927 | panic(fmt.Sprintf("no json field name for %q field in serverconfig.Config", f.Name)) |
| 928 | } |
| 929 | knownFields[jsonName] = true |
| 930 | } |
| 931 | return knownFields |
| 932 | } |
| 933 | |
| 934 | // KeyRingAndId returns the GPG identity keyring path and the user's |
| 935 | // GPG keyID (TODO: length/case), if configured. TODO: which error |