@@ -7,18 +7,21 @@ import (
77 "net/http"
88)
99
10- type layerType int
10+ // LayerType is the table/function type of a layer
11+ type LayerType int
1112
1213const (
13- layerTypeTable = 1
14- layerTypeFunction = 2
14+ // LayerTypeTable is a table layer
15+ LayerTypeTable = 1
16+ // LayerTypeFunction is a function layer
17+ LayerTypeFunction = 2
1518)
1619
17- func (lt layerType ) String () string {
20+ func (lt LayerType ) String () string {
1821 switch lt {
19- case layerTypeTable :
22+ case LayerTypeTable :
2023 return "table"
21- case layerTypeFunction :
24+ case LayerTypeFunction :
2225 return "function"
2326 default :
2427 return "unknown"
@@ -30,80 +33,77 @@ func (lt layerType) String() string {
3033// a TileRequest containing SQL to produce tiles
3134// given an input tile
3235type Layer interface {
33- GetType () layerType
34- GetId () string
36+ GetType () LayerType
37+ GetID () string
3538 GetDescription () string
3639 GetName () string
3740 GetSchema () string
3841 GetTileRequest (tile Tile , r * http.Request ) TileRequest
39- WriteLayerJson (w http.ResponseWriter , req * http.Request ) error
42+ WriteLayerJSON (w http.ResponseWriter , req * http.Request ) error
4043}
4144
4245type TileRequest struct {
43- LayerId string
46+ LayerID string
4447 Tile Tile
45- Sql string
48+ SQL string
4649 Args []interface {}
4750}
4851
49- // A global array of Layer where the state is held for performance
50- // Refreshed when LoadLayerTableList is called
51- // Key is of the form: schemaname.tablename
52- var globalLayers map [string ]Layer
53-
54- func GetLayer (lyrId string ) (Layer , error ) {
55- if lyr , ok := globalLayers [lyrId ]; ok {
52+ func getLayer (lyrID string ) (Layer , error ) {
53+ lyr , ok := globalLayers [lyrID ]
54+ if ok {
5655 return lyr , nil
57- } else {
58- return lyr , errors .New (fmt .Sprintf ("Unable to get layer '%s'" , lyrId ))
5956 }
57+ return lyr , errors .New (fmt .Sprintf ("Unable to get layer '%s'" , lyrID ))
6058}
6159
62- func LoadLayers () error {
60+ func loadLayers () error {
6361 _ , errBnd := getServerBounds ()
6462 if errBnd != nil {
6563 return errBnd
6664 }
67- tableLayers , errTl := GetTableLayers ()
65+ tableLayers , errTl := getTableLayers ()
6866 if errTl != nil {
6967 return errTl
7068 }
71- functionLayers , errFl := GetFunctionLayers ()
69+ functionLayers , errFl := getFunctionLayers ()
7270 if errFl != nil {
7371 return errFl
7472 }
7573 // Empty the global layer map
74+ globalLayersMutex .Lock ()
7675 globalLayers = make (map [string ]Layer )
7776 for _ , lyr := range tableLayers {
78- globalLayers [lyr .GetId ()] = lyr
77+ globalLayers [lyr .GetID ()] = lyr
7978 }
8079 for _ , lyr := range functionLayers {
81- globalLayers [lyr .GetId ()] = lyr
80+ globalLayers [lyr .GetID ()] = lyr
8281 }
82+ globalLayersMutex .Unlock ()
8383
8484 return nil
8585}
8686
87- type LayerJson struct {
87+ type layerJSON struct {
8888 Type string `json:"type"`
89- Id string `json:"id"`
89+ ID string `json:"id"`
9090 Name string `json:"name"`
9191 Schema string `json:"schema"`
9292 Description string `json:"description"`
93- DetailUrl string `json:"detailurl"`
93+ DetailURL string `json:"detailurl"`
9494}
9595
96- func GetJsonLayers (r * http.Request ) map [string ]LayerJson {
97- json := make (map [string ]LayerJson )
96+ func getJSONLayers (r * http.Request ) map [string ]layerJSON {
97+ json := make (map [string ]layerJSON )
9898 urlBase := serverURLBase (r )
9999 for k , v := range globalLayers {
100- json [k ] = LayerJson {
100+ json [k ] = layerJSON {
101101 Type : v .GetType ().String (),
102- Id : v .GetId (),
102+ ID : v .GetID (),
103103 Name : v .GetName (),
104104 Schema : v .GetSchema (),
105105 Description : v .GetDescription (),
106- DetailUrl : fmt .Sprintf ("%s/%s.json" , urlBase , v .GetId ()),
106+ DetailURL : fmt .Sprintf ("%s/%s.json" , urlBase , v .GetID ()),
107107 }
108108 }
109109 return json
0 commit comments