GetValues creates a map with values from the key-value format string
(s string)
| 102 | |
| 103 | // GetValues creates a map with values from the key-value format string |
| 104 | func (a *HookAuth) GetValues(s string) { |
| 105 | m := map[string]string{} |
| 106 | |
| 107 | // make line breaks consistent on Windows platform |
| 108 | s = strings.ReplaceAll(s, "\r\n", "\n") |
| 109 | |
| 110 | // iterate input lines |
| 111 | for val := range strings.Lines(s) { |
| 112 | v := strings.SplitN(val, "=", 2) |
| 113 | |
| 114 | // skips non key and value format |
| 115 | if len(v) != 2 { |
| 116 | continue |
| 117 | } |
| 118 | |
| 119 | fieldKey := strings.TrimSpace(v[0]) |
| 120 | fieldValue := strings.TrimSpace(v[1]) |
| 121 | |
| 122 | if a.Fields.IsValid(fieldKey) { |
| 123 | m[fieldKey] = fieldValue |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | a.Fields.Values = m |
| 128 | } |
| 129 | |
| 130 | // SaveUser updates the existing user or creates a new one when not found |
| 131 | func (a *HookAuth) SaveUser() (*users.User, error) { |