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

View File

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

View File

@ -36,7 +36,6 @@ const countBlocksQuery = `
select count(*) from blocks b where b.mtime >= ? and b.mtime <= ? select count(*) from blocks b where b.mtime >= ? and b.mtime <= ?
` `
const getBlockQuery = ` const getBlockQuery = `
select pos,data,mtime from blocks b where b.pos = ? 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} return &db.Block{Pos: c, Data: data, Mtime: mtime}
} }
func (this *Sqlite3Accessor) FindBlocksByMtime(gtmtime int64, limit int) ([]*db.Block, error) { func (this *Sqlite3Accessor) FindBlocksByMtime(gtmtime int64, limit int) ([]*db.Block, error) {
blocks := make([]*db.Block, 0) blocks := make([]*db.Block, 0)
@ -83,7 +82,6 @@ func (this *Sqlite3Accessor) FindBlocksByMtime(gtmtime int64, limit int) ([]*db.
return blocks, nil return blocks, nil
} }
func (this *Sqlite3Accessor) FindLegacyBlocksByPos(lastpos *coords.MapBlockCoords, limit int) ([]*db.Block, error) { func (this *Sqlite3Accessor) FindLegacyBlocksByPos(lastpos *coords.MapBlockCoords, limit int) ([]*db.Block, error) {
blocks := make([]*db.Block, 0) blocks := make([]*db.Block, 0)
pc := coords.CoordToPlain(lastpos) pc := coords.CoordToPlain(lastpos)
@ -112,8 +110,6 @@ func (this *Sqlite3Accessor) FindLegacyBlocksByPos(lastpos *coords.MapBlockCoord
return blocks, nil return blocks, nil
} }
func (db *Sqlite3Accessor) CountBlocks(frommtime, tomtime int64) (int, error) { func (db *Sqlite3Accessor) CountBlocks(frommtime, tomtime int64) (int, error) {
rows, err := db.db.Query(countBlocksQuery, frommtime, tomtime) rows, err := db.db.Query(countBlocksQuery, frommtime, tomtime)
if err != nil { if err != nil {

View File

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

View File

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

View File

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

View File

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

View File

@ -3,14 +3,24 @@ package web
import ( import (
"encoding/json" "encoding/json"
"mapserver/app" "mapserver/app"
"mapserver/layer"
"net/http" "net/http"
) )
//Public facing config
type PublicConfig struct {
Layers []layer.Layer `json:"layers"`
}
type ConfigHandler struct { type ConfigHandler struct {
ctx *app.App ctx *app.App
} }
func (h *ConfigHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { func (h *ConfigHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
resp.Header().Add("content-type", "application/json") 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 MapObjectConnection string
} }
func Parse(filename string) WorldConfig { func Parse(filename string) WorldConfig {
file, err := os.Open(filename) file, err := os.Open(filename)
if err != nil { if err != nil {