Working auth and photo json endpoint
Signed-off-by: Kris Nóva <kris@nivenly.com>
This commit is contained in:
parent
ef275f97f4
commit
e4323b6047
2032 changed files with 821464 additions and 52 deletions
24
vendor/github.com/melihmucuk/geocache/.gitignore
generated
vendored
Normal file
24
vendor/github.com/melihmucuk/geocache/.gitignore
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
4
vendor/github.com/melihmucuk/geocache/.travis.yml
generated
vendored
Normal file
4
vendor/github.com/melihmucuk/geocache/.travis.yml
generated
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
language: go
|
||||
go:
|
||||
- 1.6
|
||||
- tip
|
21
vendor/github.com/melihmucuk/geocache/LICENSE
generated
vendored
Normal file
21
vendor/github.com/melihmucuk/geocache/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Melih Mucuk
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
84
vendor/github.com/melihmucuk/geocache/README.md
generated
vendored
Normal file
84
vendor/github.com/melihmucuk/geocache/README.md
generated
vendored
Normal file
|
@ -0,0 +1,84 @@
|
|||
# geocache [](https://godoc.org/github.com/melihmucuk/geocache) [](https://goreportcard.com/report/melihmucuk/geocache) [](https://travis-ci.org/melihmucuk/geocache)
|
||||
|
||||
geocache is an in-memory cache that is suitable for geolocation based applications. It uses geolocation as a key for storing items. You can specify range on initialization and thats it! You can store any object, it uses interface.
|
||||
|
||||
### Installation
|
||||
|
||||
`go get github.com/melihmucuk/geocache`
|
||||
|
||||
### Usage
|
||||
|
||||

|
||||
|
||||
```go
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/melihmucuk/geocache"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c, err := geocache.NewCache(5*time.Minute, 30*time.Second, geocache.WithIn1KM)
|
||||
geoPoint := geocache.GeoPoint{Latitude: 40.9887, Longitude: 28.7817}
|
||||
if err != nil {
|
||||
fmt.Println("Error: ", err.Error())
|
||||
} else {
|
||||
c.Set(geoPoint, "helloooo", 2*time.Minute)
|
||||
v1, ok1 := c.Get(geocache.GeoPoint{Latitude: 41.2, Longitude: 29.3})
|
||||
v2, ok2 := c.Get(geocache.GeoPoint{Latitude: 41.2142, Longitude: 29.4234})
|
||||
v3, ok3 := c.Get(geocache.GeoPoint{Latitude: 40.9858, Longitude: 28.7852})
|
||||
v4, ok4 := c.Get(geocache.GeoPoint{Latitude: 40.9827, Longitude: 28.7883})
|
||||
fmt.Println(v1, ok1)
|
||||
fmt.Println(v2, ok2)
|
||||
fmt.Println(v3, ok3)
|
||||
fmt.Println(v4, ok4)
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
outputs:
|
||||
```
|
||||
<nil>, false
|
||||
<nil>, false
|
||||
helloooo, true
|
||||
helloooo, true
|
||||
```
|
||||
|
||||
### Information
|
||||
|
||||
You can specify 8 different range. More info can be found [here](http://gis.stackexchange.com/questions/8650/how-to-measure-the-accuracy-of-latitude-and-longitude).
|
||||
|
||||
* `WithIn11KM`
|
||||
|
||||
The first decimal place is worth up to 11.1 km `eg: 41.3, 29.6`
|
||||
|
||||
* `WithIn1KM`
|
||||
|
||||
The second decimal place is worth up to 1.1 km `eg: 41.36, 29.63`
|
||||
|
||||
* `WithIn110M`
|
||||
|
||||
The third decimal place is worth up to 110 m `eg: 41.367, 29.631`
|
||||
|
||||
* `WithIn11M`
|
||||
|
||||
The fourth decimal place is worth up to 11 m `eg: 41.3674, 29.6316`
|
||||
|
||||
* `WithIn1M`
|
||||
|
||||
The fifth decimal place is worth up to 1.1 m `eg: 41.36742, 29.63168`
|
||||
|
||||
* `WithIn11CM`
|
||||
|
||||
The sixth decimal place is worth up to 0.11 m `eg: 41.367421, 29.631689`
|
||||
|
||||
* `WithIn11MM`
|
||||
|
||||
The seventh decimal place is worth up to 11 mm `eg: 41.3674211, 29.6316893`
|
||||
|
||||
* `WithIn1MM`
|
||||
|
||||
The eighth decimal place is worth up to 1.1 mm `eg: 41.36742115, 29.63168932`
|
165
vendor/github.com/melihmucuk/geocache/cache.go
generated
vendored
Normal file
165
vendor/github.com/melihmucuk/geocache/cache.go
generated
vendored
Normal file
|
@ -0,0 +1,165 @@
|
|||
package geocache
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// Range specifies range of cache
|
||||
type Range int32
|
||||
|
||||
const (
|
||||
// WithIn11KM The first decimal place is worth up to 11.1 km
|
||||
// eg: 41.3, 29.6
|
||||
WithIn11KM Range = 1 + iota
|
||||
|
||||
// WithIn1KM The second decimal place is worth up to 1.1 km
|
||||
// eg: 41.36, 29.63
|
||||
WithIn1KM
|
||||
|
||||
// WithIn110M The third decimal place is worth up to 110 m
|
||||
// eg: 41.367, 29.631
|
||||
WithIn110M
|
||||
|
||||
// WithIn11M The fourth decimal place is worth up to 11 m
|
||||
// eg: 41.3674, 29.6316
|
||||
WithIn11M
|
||||
|
||||
// WithIn1M The fifth decimal place is worth up to 1.1 m
|
||||
// eg: 41.36742, 29.63168
|
||||
WithIn1M
|
||||
|
||||
// WithIn11CM The sixth decimal place is worth up to 0.11 m
|
||||
// eg: 41.367421, 29.631689
|
||||
WithIn11CM
|
||||
|
||||
// WithIn11MM The seventh decimal place is worth up to 11 mm
|
||||
// eg: 41.3674211, 29.6316893
|
||||
WithIn11MM
|
||||
|
||||
// WithIn1MM The eighth decimal place is worth up to 1.1 mm
|
||||
// eg: 41.36742115, 29.63168932
|
||||
WithIn1MM
|
||||
)
|
||||
|
||||
// Item struct keeps cache value and expiration time of object
|
||||
type Item struct {
|
||||
Object interface{}
|
||||
Expiration int64
|
||||
}
|
||||
|
||||
// Cache struct manages items, expirations and clean ups
|
||||
type Cache struct {
|
||||
items map[GeoPoint]Item
|
||||
m sync.RWMutex
|
||||
expiration time.Duration
|
||||
cleanUpInterval time.Duration
|
||||
precision int32
|
||||
stopCleanUp chan bool
|
||||
}
|
||||
|
||||
// GeoPoint specifies point that used as key of cache
|
||||
type GeoPoint struct {
|
||||
Latitude float64
|
||||
Longitude float64
|
||||
}
|
||||
|
||||
// NewCache creates new Cache with params and returns pointer of Cache and error
|
||||
// cleanUpInterval used for deleting expired objects from cache.
|
||||
func NewCache(expiration, cleanUpInterval time.Duration, withInRange Range) (*Cache, error) {
|
||||
if withInRange < 1 || withInRange > 8 {
|
||||
return nil, errors.New("Range must be within 1-8!")
|
||||
}
|
||||
|
||||
c := &Cache{items: make(map[GeoPoint]Item), expiration: expiration, cleanUpInterval: cleanUpInterval, precision: int32(withInRange), stopCleanUp: make(chan bool)}
|
||||
|
||||
ticker := time.NewTicker(cleanUpInterval)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
c.cleanUp()
|
||||
case <-c.stopCleanUp:
|
||||
ticker.Stop()
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// Set adds object to cache with given geopoint
|
||||
func (c *Cache) Set(position GeoPoint, value interface{}, expiration time.Duration) {
|
||||
var exp int64
|
||||
if expiration == 0 {
|
||||
expiration = c.expiration
|
||||
}
|
||||
|
||||
if expiration > 0 {
|
||||
exp = time.Now().Add(expiration).UnixNano()
|
||||
}
|
||||
c.m.Lock()
|
||||
defer c.m.Unlock()
|
||||
c.items[position.truncate(c.precision)] = Item{Object: value, Expiration: exp}
|
||||
}
|
||||
|
||||
// Get gets object from cache with given geopoint
|
||||
func (c *Cache) Get(position GeoPoint) (interface{}, bool) {
|
||||
c.m.RLock()
|
||||
defer c.m.RUnlock()
|
||||
item, found := c.items[position.truncate(c.precision)]
|
||||
return item.Object, found
|
||||
}
|
||||
|
||||
// Items returns cached items
|
||||
func (c *Cache) Items() map[GeoPoint]Item {
|
||||
c.m.RLock()
|
||||
defer c.m.RUnlock()
|
||||
return c.items
|
||||
}
|
||||
|
||||
// ItemCount returns cached items count
|
||||
func (c *Cache) ItemCount() int {
|
||||
c.m.RLock()
|
||||
defer c.m.RUnlock()
|
||||
n := len(c.items)
|
||||
return n
|
||||
}
|
||||
|
||||
// Flush deletes all cached items
|
||||
func (c *Cache) Flush() {
|
||||
c.m.Lock()
|
||||
defer c.m.Unlock()
|
||||
c.items = map[GeoPoint]Item{}
|
||||
}
|
||||
|
||||
// StopCleanUp stops clean up process.
|
||||
func (c *Cache) StopCleanUp() {
|
||||
c.stopCleanUp <- true
|
||||
}
|
||||
|
||||
func (c *Cache) cleanUp() {
|
||||
c.m.Lock()
|
||||
defer c.m.Unlock()
|
||||
for k, v := range c.items {
|
||||
if v.Expiration < time.Now().UnixNano() {
|
||||
delete(c.items, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (g GeoPoint) truncate(precision int32) GeoPoint {
|
||||
dLat := decimal.NewFromFloat(g.Latitude)
|
||||
dLong := decimal.NewFromFloat(g.Longitude)
|
||||
lat, _ := dLat.Truncate(precision).Float64()
|
||||
long, _ := dLong.Truncate(precision).Float64()
|
||||
|
||||
return GeoPoint{
|
||||
Latitude: lat,
|
||||
Longitude: long,
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue