diff options
author | Thomas Voss <mail@thomasvoss.com> | 2025-08-03 01:34:28 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2025-08-03 01:34:28 +0200 |
commit | cd8e44e6251e7fee2facaa225e52537eb2ecf4a5 (patch) | |
tree | acb5facc46c1c839351fe55659b4d08ee8d03b7f /src | |
parent | f381c433d5287b0d858a143d069ff026719281b4 (diff) |
Refactor
Diffstat (limited to 'src')
-rw-r--r-- | src/wikipedia/wikipedia.go | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/src/wikipedia/wikipedia.go b/src/wikipedia/wikipedia.go index 275f2d6..e55e9da 100644 --- a/src/wikipedia/wikipedia.go +++ b/src/wikipedia/wikipedia.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io" - "log" "net/http" "net/url" "strconv" @@ -17,13 +16,12 @@ var ( titlemap = make(map[string]map[string]string) ) -func Init(locale string) { +func Init(locale string) error { defaultLocale = locale base := fmt.Sprintf("https://%s.wikipedia.org/w/api.php", defaultLocale) u, err := url.Parse(base) if err != nil { - log.Println(err) - return + return err } var resp APIResponse @@ -46,13 +44,11 @@ func Init(locale string) { respjson, err := http.Get(u.String()) if err != nil { - log.Println(err) - return + return err } if respjson.StatusCode >= 400 && respjson.StatusCode != http.StatusTooManyRequests { - log.Printf("Failed to GET %s: %s\n", u, respjson.Status) - return + return fmt.Errorf("Failed to GET %s: %s", u, respjson.Status) } defer respjson.Body.Close() @@ -63,14 +59,12 @@ func Init(locale string) { body, err := io.ReadAll(respjson.Body) if err != nil { - log.Println(err) - return + return err } resp = APIResponse{} if err = json.Unmarshal(body, &resp); err != nil { - log.Println(err) - return + return err } for _, page := range resp.Query.Pages { @@ -89,7 +83,7 @@ func Init(locale string) { } if resp.Continue == nil { - break + return nil } } } |