Making the output better
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user