aboutsummaryrefslogtreecommitdiff
path: root/cache.go
diff options
context:
space:
mode:
Diffstat (limited to 'cache.go')
-rw-r--r--cache.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/cache.go b/cache.go
new file mode 100644
index 0000000..6eed536
--- /dev/null
+++ b/cache.go
@@ -0,0 +1,60 @@
+package main
+
+import (
+ "time"
+)
+
+var FileRoot string = "http://localhost:8080/files/"
+
+type APICache struct {
+ Id uint64 `json:"id"`
+ Latitude float64 `json:"latitude"`
+ Longitude float64 `json:"longitude"`
+ Created time.Time `json:"created"`
+ URI string `json:"uri"`
+}
+
+type APICaches []APICache
+
+type DBCache struct {
+ Id uint64
+ Latitude float64
+ Longitude float64
+ Created time.Time
+ Path string
+}
+
+type DBCaches []DBCache
+
+type PostCache struct {
+ Latitude float64
+ Longitude float64
+ Data string
+}
+
+func PathToURI(path string) string {
+ return FileRoot + path
+}
+
+func DBToAPI(db DBCache) APICache {
+ var api APICache
+
+ api.Id = db.Id
+ api.Latitude = db.Latitude
+ api.Longitude = db.Longitude
+ api.Created = db.Created
+ api.URI = PathToURI(db.Path)
+
+ return api
+}
+
+func PostToDB(post PostCache, filename string) DBCache {
+ var db DBCache
+
+ db.Latitude = post.Latitude
+ db.Longitude = post.Longitude
+ db.Created = time.Now()
+ db.Path = filename
+
+ return db
+}