mirror of
https://github.com/Xevion/r2park.git
synced 2025-12-06 11:16:02 -06:00
Reorganize variables/funcs/type declarations, fix unnecessary Sprintf, move type def to types.go
This commit is contained in:
28
api.go
28
api.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user