1
0
forked from MTSR/mapserver

go fmt & public config

This commit is contained in:
NatureFreshMilk 2019-02-07 08:02:13 +01:00
parent 4919714e35
commit b049e33bb2
12 changed files with 42 additions and 54 deletions

View File

@ -7,7 +7,6 @@ import (
"mapserver/db"
)
type PostgresAccessor struct {
db *sql.DB
}
@ -21,7 +20,6 @@ func convertRows(pos int64, data []byte, mtime int64) *db.Block {
return &db.Block{Pos: c, Data: data, Mtime: mtime}
}
func (this *PostgresAccessor) FindBlocksByMtime(gtmtime int64, limit int) ([]*db.Block, error) {
blocks := make([]*db.Block, 0)
@ -76,7 +74,6 @@ func (this *PostgresAccessor) FindLegacyBlocksByPos(lastpos *coords.MapBlockCoor
return blocks, nil
}
func (this *PostgresAccessor) CountBlocks(frommtime, tomtime int64) (int, error) {
rows, err := this.db.Query(countBlocksQuery, frommtime, tomtime)
if err != nil {
@ -99,7 +96,6 @@ func (this *PostgresAccessor) CountBlocks(frommtime, tomtime int64) (int, error)
return 0, nil
}
func (this *PostgresAccessor) GetBlock(pos *coords.MapBlockCoords) (*db.Block, error) {
rows, err := this.db.Query(getBlockQuery, pos.X, pos.Y, pos.Z)
if err != nil {

View File

@ -44,7 +44,6 @@ const countBlocksQuery = `
select count(*) from blocks b where b.mtime >= ? and b.mtime <= ?
`
const getBlockQuery = `
select pos,data,mtime from blocks b
where b.posx = ?

View File

@ -36,7 +36,6 @@ const countBlocksQuery = `
select count(*) from blocks b where b.mtime >= ? and b.mtime <= ?
`
const getBlockQuery = `
select pos,data,mtime from blocks b where b.pos = ?
`

View File

@ -55,7 +55,6 @@ func convertRows(pos int64, data []byte, mtime int64) *db.Block {
return &db.Block{Pos: c, Data: data, Mtime: mtime}
}
func (this *Sqlite3Accessor) FindBlocksByMtime(gtmtime int64, limit int) ([]*db.Block, error) {
blocks := make([]*db.Block, 0)
@ -83,7 +82,6 @@ func (this *Sqlite3Accessor) FindBlocksByMtime(gtmtime int64, limit int) ([]*db.
return blocks, nil
}
func (this *Sqlite3Accessor) FindLegacyBlocksByPos(lastpos *coords.MapBlockCoords, limit int) ([]*db.Block, error) {
blocks := make([]*db.Block, 0)
pc := coords.CoordToPlain(lastpos)
@ -112,8 +110,6 @@ func (this *Sqlite3Accessor) FindLegacyBlocksByPos(lastpos *coords.MapBlockCoord
return blocks, nil
}
func (db *Sqlite3Accessor) CountBlocks(frommtime, tomtime int64) (int, error) {
rows, err := db.db.Query(countBlocksQuery, frommtime, tomtime)
if err != nil {

View File

@ -1,12 +1,11 @@
package mapobjectdb
import (
"fmt"
"mapserver/coords"
"testing"
"fmt"
)
func TestNewMapBlockCoords(t *testing.T) {
attrs := make(map[string]string)
attrs["X"] = "y"
@ -29,5 +28,4 @@ func TestNewMapBlockCoords(t *testing.T) {
t.Error("Z coord off")
}
}

View File

@ -3,8 +3,8 @@ package sqlite
import (
"fmt"
"io/ioutil"
"mapserver/mapobjectdb"
"mapserver/coords"
"mapserver/mapobjectdb"
"os"
"testing"
)

View File

@ -1,6 +1,5 @@
package sqlite
const migrateScript = `
PRAGMA foreign_keys = ON;
@ -40,7 +39,6 @@ create table if not exists tiles(
);
`
const getMapDataPosQuery = `
select o.id, o.type, o.mtime,
o.x, o.y, o.z,
@ -54,13 +52,10 @@ and o.posx <= ? and o.posy <= ? and o.posz <= ?
order by o.id
`
const removeMapDataQuery = `
delete from objects where posx = ? and posy = ? and posz = ?
`
const addMapDataQuery = `
insert into
objects(x,y,z,posx,posy,posz,type,mtime)

View File

@ -5,7 +5,6 @@ import (
"mapserver/mapobjectdb"
)
func (db *Sqlite3Accessor) GetTile(pos *coords.TileCoords) (*mapobjectdb.Tile, error) {
rows, err := db.db.Query(getTileQuery, pos.LayerId, pos.X, pos.Y, pos.Zoom)
if err != nil {
@ -39,14 +38,11 @@ func (db *Sqlite3Accessor) GetTile(pos *coords.TileCoords) (*mapobjectdb.Tile, e
return nil, nil
}
func (db *Sqlite3Accessor) SetTile(tile *mapobjectdb.Tile) error {
_, err := db.db.Exec(setTileQuery, tile.Pos.X, tile.Pos.Y, tile.Pos.Zoom, tile.Pos.LayerId, tile.Data, tile.Mtime)
return err
}
func (db *Sqlite3Accessor) RemoveTile(pos *coords.TileCoords) error {
_, err := db.db.Exec(removeTileQuery, pos.X, pos.Y, pos.Zoom, pos.LayerId)
return err

View File

@ -3,14 +3,24 @@ package web
import (
"encoding/json"
"mapserver/app"
"mapserver/layer"
"net/http"
)
//Public facing config
type PublicConfig struct {
Layers []layer.Layer `json:"layers"`
}
type ConfigHandler struct {
ctx *app.App
}
func (h *ConfigHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
resp.Header().Add("content-type", "application/json")
json.NewEncoder(resp).Encode(h.ctx.Config)
webcfg := PublicConfig{}
webcfg.Layers = h.ctx.Config.Layers
json.NewEncoder(resp).Encode(webcfg)
}

View File

@ -35,7 +35,6 @@ type WorldConfig struct {
MapObjectConnection string
}
func Parse(filename string) WorldConfig {
file, err := os.Open(filename)
if err != nil {