aboutsummaryrefslogtreecommitdiff
path: root/cache.go
blob: 6eed5364d381295457c0df6dec583b476b4a0e5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
}