From 919b69ce4c9b89a81ae7532234adfeb9d27707ca Mon Sep 17 00:00:00 2001 From: Philippe Caseiro Date: Wed, 29 Jun 2022 16:30:20 +0200 Subject: [PATCH] Try 07 --- pkg/templater/repo-apk.go | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/pkg/templater/repo-apk.go b/pkg/templater/repo-apk.go index c531aca..6e679e1 100644 --- a/pkg/templater/repo-apk.go +++ b/pkg/templater/repo-apk.go @@ -1,7 +1,6 @@ package templater import ( - "bufio" "fmt" "io/ioutil" "os" @@ -17,31 +16,17 @@ type APKRepository struct { } func (hr *APKRepository) urlIsPresent() (bool, error) { - f, err := os.Open(APKConfigFile) + // read the whole file at once + b, err := ioutil.ReadFile(APKConfigFile) if err != nil { - return false, err + return err } - defer f.Close() - - // Splits on newlines by default. - scanner := bufio.NewScanner(f) - - line := 1 - for scanner.Scan() { - fmt.Printf("DBG:%s:%s:\n", scanner.Text(), hr.URL) - if strings.Contains(scanner.Text(), hr.URL) { - return true, nil - } - - line++ - } - fmt.Printf("END\n") - - if err := scanner.Err(); err != nil { - return false, err + s := string(b) + // //check whether s contains substring text + if strings.Contains(s, hr.URL) { + return true, nil } return false, nil - } func (hr *APKRepository) Add() error {