mirror of
https://github.com/Xevion/r2park.git
synced 2025-12-06 05:16:06 -06:00
Reorganize variables/funcs/type declarations, fix unnecessary Sprintf, move type def to types.go
This commit is contained in:
22
api.go
22
api.go
@@ -16,10 +16,14 @@ var (
|
|||||||
client *http.Client
|
client *http.Client
|
||||||
requestCounter uint
|
requestCounter uint
|
||||||
lastReload int64
|
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() {
|
func init() {
|
||||||
|
cacheExpiry = time.Now().Add(-time.Second) // Set the cache as expired initially
|
||||||
cookies, err := cookiejar.New(nil)
|
cookies, err := cookiejar.New(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
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 {
|
func GetLocations() []Location {
|
||||||
if time.Now().Before(cacheExpiry) {
|
if time.Now().Before(cacheExpiry) {
|
||||||
return cachedLocations
|
return cachedLocations
|
||||||
|
|||||||
2
debug.go
2
debug.go
@@ -24,7 +24,7 @@ func DebugRequest(req *http.Request) string {
|
|||||||
str += fmt.Sprintf("\n\n {error while reading request body buffer: %s}", err)
|
str += fmt.Sprintf("\n\n {error while reading request body buffer: %s}", err)
|
||||||
} else {
|
} else {
|
||||||
if len(body) == 0 {
|
if len(body) == 0 {
|
||||||
str += fmt.Sprintf("\n\n{empty body}")
|
str += "\n\n{empty body}"
|
||||||
} else {
|
} else {
|
||||||
str += fmt.Sprintf("\n\n%s", body)
|
str += fmt.Sprintf("\n\n%s", body)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user