Making the output better

This commit is contained in:
Micheal Wilkinson
2026-03-18 00:44:37 +00:00
parent 981142eb60
commit 19fbe8191d
2 changed files with 11 additions and 4 deletions

View File

@@ -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) {

View File

@@ -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