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

22
api.go
View File

@@ -16,10 +16,14 @@ var (
client *http.Client
requestCounter uint
lastReload int64
parsePattern = regexp.MustCompile("\\s*(.+)\\n\\s+(.+)\\n\\s+(\\d+)\\s*")
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

View File

@@ -24,7 +24,7 @@ func DebugRequest(req *http.Request) string {
str += fmt.Sprintf("\n\n {error while reading request body buffer: %s}", err)
} else {
if len(body) == 0 {
str += fmt.Sprintf("\n\n{empty body}")
str += "\n\n{empty body}"
} else {
str += fmt.Sprintf("\n\n%s", body)
}

7
types.go Normal file
View File

@@ -0,0 +1,7 @@
package main
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
}