-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from catmullet/speed_update
speed update/refactor
- Loading branch information
Showing
8 changed files
with
117 additions
and
130 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package geodb | ||
|
||
import ( | ||
"embed" | ||
) | ||
|
||
var ( | ||
//go:embed * | ||
GeoDbEmbedDirectory embed.FS | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package tz | ||
|
||
type geoStorage interface { | ||
StoreFile(filename string, obj interface{}) error | ||
LoadFile(filename string, obj interface{}) ([]byte, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module github.com/catmullet/tz | ||
|
||
go 1.15 | ||
go 1.16 | ||
|
||
require github.com/golang/snappy v0.0.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package tz | ||
|
||
import ( | ||
"embed" | ||
"encoding/json" | ||
"github.com/golang/snappy" | ||
"log" | ||
"strings" | ||
) | ||
|
||
type LocalGeoStorage struct { | ||
efs embed.FS | ||
} | ||
|
||
func newLocalGeoStorage(fs embed.FS) geoStorage { | ||
return &LocalGeoStorage{ | ||
efs: fs, | ||
} | ||
} | ||
|
||
func (lgs LocalGeoStorage) StoreFile(_ string, _ interface{}) error { | ||
log.Fatalln("local geo storage: store file not used") | ||
return nil | ||
} | ||
|
||
func (lgs LocalGeoStorage) LoadFile(filename string, obj interface{}) ([]byte, error) { | ||
var decodedJson, err = lgs.efs.ReadFile(filename) | ||
if strings.Contains(filename, "snappy") { | ||
decodedJson, err = snappy.Decode(nil, decodedJson) | ||
if err != nil { | ||
return decodedJson, err | ||
} | ||
} | ||
if err != nil { | ||
return decodedJson, err | ||
} | ||
return decodedJson, json.Unmarshal(decodedJson, &obj) | ||
} |