Making the output better
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -20,14 +21,16 @@ func doRequest(method, url string, body any) []byte {
|
|||||||
if body != nil {
|
if body != nil {
|
||||||
data, err := json.Marshal(body)
|
data, err := json.Marshal(body)
|
||||||
if err != nil {
|
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)
|
reqBody = bytes.NewReader(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest(method, url, reqBody)
|
req, err := http.NewRequest(method, url, reqBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to create request: %v", err)
|
fmt.Println("Failed to create request")
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if body != nil {
|
if body != nil {
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
@@ -35,7 +38,9 @@ func doRequest(method, url string, body any) []byte {
|
|||||||
|
|
||||||
resp, err := httpClient.Do(req)
|
resp, err := httpClient.Do(req)
|
||||||
if err != nil {
|
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()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
@@ -79,12 +84,13 @@ func ListNotes() {
|
|||||||
fmt.Printf("| %-*s | %-*s | %-*s |\n", idW, id, updatedW, updated, contentW, content)
|
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))
|
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")
|
row("ID", "Updated", "Content")
|
||||||
fmt.Println(sep)
|
fmt.Println(sep)
|
||||||
for _, n := range notes {
|
for _, n := range notes {
|
||||||
row(fmt.Sprintf("%d", n.ID), n.LastUpdate.Format("2006-01-02 15:04:05"), n.Content)
|
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) {
|
func CreateNote(content string) {
|
||||||
|
|||||||
1
justfile
1
justfile
@@ -9,6 +9,7 @@ build: clean
|
|||||||
@echo "Building notes..."
|
@echo "Building notes..."
|
||||||
@mkdir -p _build
|
@mkdir -p _build
|
||||||
go build -o _build/notes -ldflags="-s -w" .
|
go build -o _build/notes -ldflags="-s -w" .
|
||||||
|
chmod +x ./_build/notes
|
||||||
@echo "Build complete: ./_build/notes"
|
@echo "Build complete: ./_build/notes"
|
||||||
|
|
||||||
# Run tests with short output
|
# Run tests with short output
|
||||||
|
|||||||
Reference in New Issue
Block a user