MCPcopy Create free account
hub / github.com/PuerNya/git-proxy / NewFileReader

Function NewFileReader

main.go:331–363  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

329}
330
331func NewFileReader(path string) (*FileReader, error) {
332 file, err := os.Open(path)
333 if err != nil {
334 return nil, err
335 }
336 reader := FileReader{
337 LineChan: make(chan string),
338 CloseSignal: make(chan struct{}),
339 }
340 go func() {
341 defer file.Close()
342 scanner := bufio.NewScanner(file)
343 for scanner.Scan() {
344 line := strings.TrimSpace(scanner.Text())
345 if len(line) == 0 {
346 continue
347 }
348 lr := []rune(line)
349 if lr[0] == '#' || (len(lr) > 1 && lr[0] == '/' && lr[1] == '/') {
350 continue
351 }
352 for i, r := range lr {
353 if r == '#' || (r == '/' && i < len(lr)-1 && lr[i+1] == '/') {
354 line = strings.TrimSpace(string(lr[:i]))
355 break
356 }
357 }
358 reader.LineChan <- line
359 }
360 reader.CloseSignal <- struct{}{}
361 }()
362 return &reader, nil
363}
364
365func (r *FileReader) Close() {
366 close(r.LineChan)

Callers 2

loadDomainListDataFunction · 0.85
loadBlackListDataFunction · 0.85

Calls 1

CloseMethod · 0.45

Tested by

no test coverage detected