Database is more usable now. All pages have been updated to use the database, and share an application configuration. Page Stack has been removed, no more pages hanging around in memory. Replaced with a 'Router' which uses an Enum to determine which page should be displayed, destroys the old page and initializes the new page all in one go. No more push, pop, rollback, etc. No more holding instances of pages. Logger has been updated with proper timestamps and sorting now works as expected."
27 lines
554 B
Go
27 lines
554 B
Go
package netreq
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
// Makes a GET request to the specified URL and returns the JSON response
|
|
// as a byte slice. If the request fails, it returns an error.
|
|
func GetJSON(url string) ([]byte, error) {
|
|
fmt.Println(url)
|
|
res, err := http.Get(url)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
body, err := io.ReadAll(res.Body)
|
|
res.Body.Close()
|
|
if res.StatusCode > 299 {
|
|
return nil, fmt.Errorf("request failed with status code %d: %s", res.StatusCode, string(body))
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return body, nil
|
|
}
|