aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2025-08-03 01:34:28 +0200
committerThomas Voss <mail@thomasvoss.com> 2025-08-03 01:34:28 +0200
commitcd8e44e6251e7fee2facaa225e52537eb2ecf4a5 (patch)
treeacb5facc46c1c839351fe55659b4d08ee8d03b7f
parentf381c433d5287b0d858a143d069ff026719281b4 (diff)
Refactor
-rw-r--r--main.go4
-rw-r--r--src/wikipedia/wikipedia.go20
2 files changed, 10 insertions, 14 deletions
diff --git a/main.go b/main.go
index 6b24ef9..befa786 100644
--- a/main.go
+++ b/main.go
@@ -70,7 +70,9 @@ func main() {
}
i18n.Init(Try2(os.OpenRoot("po")).FS(), app.Debugp)
- wikipedia.Init(i18n.DefaultPrinter.Bcp)
+ if err := wikipedia.Init(i18n.DefaultPrinter.Bcp); err != nil {
+ log.Println(err)
+ }
dbx.Init(Try2(os.OpenRoot("src/dbx/sql")).FS())
app.BuildTemplates(Try2(os.OpenRoot("src/templates")).FS())
app.Run(*port)
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
}
}
}