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,9 +7,8 @@ import (
"mapserver/db"
)
type PostgresAccessor struct {
db *sql.DB
db *sql.DB
}
func (db *PostgresAccessor) Migrate() error {
@ -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

@ -6,13 +6,13 @@ import (
type MapBlock struct {
Pos *coords.MapBlockCoords `json:"pos"`
Size int `json:"size"`
Version byte `json:"version"`
Underground bool `json:"underground"`
Mapdata *MapData `json:"mapdata"`
Metadata *Metadata `json:"metadata"`
BlockMapping map[int]string `json:"blockmapping"`
Mtime int64 `json:"mtime"`
Size int `json:"size"`
Version byte `json:"version"`
Underground bool `json:"underground"`
Mapdata *MapData `json:"mapdata"`
Metadata *Metadata `json:"metadata"`
BlockMapping map[int]string `json:"blockmapping"`
Mtime int64 `json:"mtime"`
}
type MapData struct {

View File

@ -1,33 +1,31 @@
package mapobjectdb
import (
"fmt"
"mapserver/coords"
"testing"
"fmt"
)
func TestNewMapBlockCoords(t *testing.T) {
attrs := make(map[string]string)
attrs["X"] = "y"
pos := coords.NewMapBlockCoords(1, 2, 3)
fmt.Println(pos)
fmt.Println(pos)
obj := NewMapObject(pos, 10, 12, 14, "xy")
fmt.Println(obj)
obj := NewMapObject(pos, 10, 12, 14, "xy")
fmt.Println(obj)
if obj.X != 26 {
t.Error("x coord off")
}
if obj.X != 26 {
t.Error("x coord off")
}
if obj.Y != 44 {
t.Error("Y coord off")
}
if obj.Z != 62 {
t.Error("Z coord off")
}
if obj.Y != 44 {
t.Error("Y coord off")
}
if obj.Z != 62 {
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

@ -5,9 +5,9 @@ import (
)
type ParamsType struct {
Help bool
Version bool
Debug bool
Help bool
Version bool
Debug bool
}
func Parse() ParamsType {

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

@ -13,10 +13,10 @@ const (
)
const (
CONFIG_BACKEND string = "backend"
CONFIG_PLAYER_BACKEND string = "player_backend"
CONFIG_PSQL_CONNECTION string = "pgsql_connection"
CONFIG_PSQL_MAPSERVER string = "pgsql_mapserver_connection"
CONFIG_BACKEND string = "backend"
CONFIG_PLAYER_BACKEND string = "player_backend"
CONFIG_PSQL_CONNECTION string = "pgsql_connection"
CONFIG_PSQL_MAPSERVER string = "pgsql_mapserver_connection"
)
type PsqlConfig struct {
@ -31,11 +31,10 @@ type WorldConfig struct {
Backend string
PlayerBackend string
PsqlConnection string
MapObjectConnection string
PsqlConnection string
MapObjectConnection string
}
func Parse(filename string) WorldConfig {
file, err := os.Open(filename)
if err != nil {