MCPcopy Index your code
hub / github.com/foxcpp/maddy / readFile

Function readFile

internal/table/file.go:196–236  ·  view source on GitHub ↗
(path string, out map[string][]string)

Source from the content-addressed store, hash-verified

194}
195
196func readFile(path string, out map[string][]string) error {
197 f, err := os.Open(path)
198 if err != nil {
199 return err
200 }
201
202 scnr := bufio.NewScanner(f)
203 lineCounter := 0
204
205 parseErr := func(text string) error {
206 return fmt.Errorf("%s:%d: %s", path, lineCounter, text)
207 }
208
209 for scnr.Scan() {
210 lineCounter++
211 if strings.HasPrefix(scnr.Text(), "#") {
212 continue
213 }
214
215 text := strings.TrimSpace(scnr.Text())
216 if text == "" {
217 continue
218 }
219
220 parts := strings.SplitN(text, ":", 2)
221 if len(parts) == 1 {
222 parts = append(parts, "")
223 }
224
225 from := strings.TrimSpace(parts[0])
226 if len(from) == 0 {
227 return parseErr("empty address before colon")
228 }
229
230 for _, to := range strings.Split(parts[1], ",") {
231 to := strings.TrimSpace(to)
232 out[from] = append(out[from], to)
233 }
234 }
235 return scnr.Err()
236}
237
238func (f *File) Lookup(_ context.Context, val string) (string, bool, error) {
239 // The existing map is never modified, instead it is replaced with a new

Callers 3

TestReadFileFunction · 0.85
ConfigureMethod · 0.85
reloadMethod · 0.85

Calls 2

ErrMethod · 0.80
OpenMethod · 0.65

Tested by 1

TestReadFileFunction · 0.68