diff options
| author | David Schlachter <t480-debian-git@schlachter.ca> | 2026-01-08 00:12:05 -0500 |
|---|---|---|
| committer | David Schlachter <t480-debian-git@schlachter.ca> | 2026-01-08 00:12:05 -0500 |
| commit | e2b5d4e8bf68dc5b790a5424fbc30ebda46c2f04 (patch) | |
| tree | 00b4a04cca2782aaaa1fd69bca9594a6d8943025 /main.go | |
| parent | e3cc2555ec52312deb5498df07ffb8b6e03c7329 (diff) | |
Move card adding logic to new file
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 49 |
1 files changed, 2 insertions, 47 deletions
@@ -3,9 +3,6 @@ package main import ( - "bytes" - "encoding/json" - "io" "log" "net/http" "os" @@ -82,49 +79,7 @@ func main() { c := http.DefaultClient c.Timeout = 5 * time.Second - // Create the card - noteRequest := addNote{ - Action: "addNote", - Version: 6, - Params: addNoteParams{ - Note: note{ - DeckName: deckName, - ModelName: modelName, - Fields: fields{ - Front: word, - Back: definition, - }, - Options: options{ - AllowDuplicate: false, - DuplicateScope: "deck", - }, - }, - }, + if err := addCard(c, word, definition); err != nil { + log.Fatalf("creating card: %s", err) } - - jsonBytes, err := json.Marshal(noteRequest) - if err != nil { - log.Fatalf("marshaling JSON: %s", err) - } - - req, err := http.NewRequest("POST", apiURL, bytes.NewBuffer(jsonBytes)) - req.Header.Set("Content-Type", "application/json") - - resp, err := c.Do(req) - if err != nil { - log.Fatalf("making request: %s", err) - } - defer resp.Body.Close() - - body, _ := io.ReadAll(resp.Body) - - var jsonResp struct { - Error string `json:"error"` - } - - json.Unmarshal(body, &jsonResp) - if jsonResp.Error != "" { - log.Fatalf("creating card: %s", jsonResp.Error) - } - } |
