From 19fbe8191d621a47420be18aa07688ecb14fe0a4 Mon Sep 17 00:00:00 2001 From: Micheal Wilkinson Date: Wed, 18 Mar 2026 00:44:37 +0000 Subject: [PATCH] Making the output better --- client/client.go | 14 ++++++++++---- justfile | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/client/client.go b/client/client.go index b6ff5db..65939da 100644 --- a/client/client.go +++ b/client/client.go @@ -7,6 +7,7 @@ import ( "io" "log" "net/http" + "os" "strings" "time" ) @@ -20,14 +21,16 @@ func doRequest(method, url string, body any) []byte { if body != nil { data, err := json.Marshal(body) if err != nil { - log.Fatalf("Failed to marshal request body: %v", err) + fmt.Println("Failed to marshal request body") + os.Exit(1) } reqBody = bytes.NewReader(data) } req, err := http.NewRequest(method, url, reqBody) if err != nil { - log.Fatalf("Failed to create request: %v", err) + fmt.Println("Failed to create request") + os.Exit(1) } if body != nil { req.Header.Set("Content-Type", "application/json") @@ -35,7 +38,9 @@ func doRequest(method, url string, body any) []byte { resp, err := httpClient.Do(req) if err != nil { - log.Fatalf("Failed to send request: %v", err) + fmt.Println("Failed to send request is the server running?") + os.Exit(1) + } defer resp.Body.Close() @@ -79,12 +84,13 @@ func ListNotes() { fmt.Printf("| %-*s | %-*s | %-*s |\n", idW, id, updatedW, updated, contentW, content) } sep := fmt.Sprintf("|-%s-|-%s-|-%s-|", strings.Repeat("-", idW), strings.Repeat("-", updatedW), strings.Repeat("-", contentW)) - + fmt.Println(strings.Repeat("-", idW+updatedW+contentW+10)) row("ID", "Updated", "Content") fmt.Println(sep) for _, n := range notes { row(fmt.Sprintf("%d", n.ID), n.LastUpdate.Format("2006-01-02 15:04:05"), n.Content) } + fmt.Println(strings.Repeat("-", idW+updatedW+contentW+10)) } func CreateNote(content string) { diff --git a/justfile b/justfile index abe8382..f40f731 100644 --- a/justfile +++ b/justfile @@ -9,6 +9,7 @@ build: clean @echo "Building notes..." @mkdir -p _build go build -o _build/notes -ldflags="-s -w" . + chmod +x ./_build/notes @echo "Build complete: ./_build/notes" # Run tests with short output