Reorganize variables/funcs/type declarations, fix unnecessary Sprintf, move type def to types.go

This commit is contained in:
2023-12-12 04:16:18 -06:00
parent cc2536ab99
commit 29b8477e7a
3 changed files with 16 additions and 21 deletions

28
api.go
View File

@@ -13,13 +13,17 @@ import (
)
var (
client *http.Client
requestCounter uint
lastReload int64
parsePattern = regexp.MustCompile("\\s*(.+)\\n\\s+(.+)\\n\\s+(\\d+)\\s*")
client *http.Client
requestCounter uint
lastReload int64
parsePattern = regexp.MustCompile(`\s*(.+)\n\s+(.+)\n\s+(\d+)\s*`)
cachedLocations []Location
cachedLocationsMap map[uint]Location
cacheExpiry time.Time
)
func init() {
cacheExpiry = time.Now().Add(-time.Second) // Set the cache as expired initially
cookies, err := cookiejar.New(nil)
if err != nil {
log.Fatal(err)
@@ -90,22 +94,6 @@ func register(location uint, code string, make string, model string, plate strin
}
type Location struct {
id uint // Used for registration internally
name string // Used for autocomplete & location selection
address string // Not used in this application so far
}
var (
cachedLocations []Location
cachedLocationsMap map[uint]Location
cacheExpiry time.Time
)
func init() {
cacheExpiry = time.Now().Add(-time.Second) // Set the cache as expired initially
}
func GetLocations() []Location {
if time.Now().Before(cacheExpiry) {
return cachedLocations