diff --git a/kml/kml.go b/cmd/tile38-cli/kml.go similarity index 97% rename from kml/kml.go rename to cmd/tile38-cli/kml.go index 80e0217e..eaeb4647 100644 --- a/kml/kml.go +++ b/cmd/tile38-cli/kml.go @@ -1,4 +1,4 @@ -package kml +package main import ( "bytes" @@ -16,7 +16,7 @@ type KML struct { points []pointT } -func New() *KML { +func NewKML() *KML { return &KML{} } diff --git a/cmd/tile38-cli/main.go b/cmd/tile38-cli/main.go index 2960796e..1f0e892a 100644 --- a/cmd/tile38-cli/main.go +++ b/cmd/tile38-cli/main.go @@ -15,7 +15,6 @@ import ( "github.com/peterh/liner" "github.com/tidwall/tile38/client" "github.com/tidwall/tile38/core" - "github.com/tidwall/tile38/kml" ) func userHomeDir() string { @@ -306,7 +305,7 @@ func main() { } func convert2kml(msg []byte) []byte { - k := kml.New() + k := NewKML() var m map[string]interface{} if err := json.Unmarshal(msg, &m); err == nil { if v, ok := m["points"].([]interface{}); ok { diff --git a/cmd/tile38-server/main.go b/cmd/tile38-server/main.go index 3469d12e..ed32b578 100644 --- a/cmd/tile38-server/main.go +++ b/cmd/tile38-server/main.go @@ -10,9 +10,8 @@ import ( "strconv" "github.com/tidwall/tile38/controller" + "github.com/tidwall/tile38/controller/log" "github.com/tidwall/tile38/core" - "github.com/tidwall/tile38/log" - "github.com/tidwall/tile38/server" ) var ( @@ -42,9 +41,8 @@ func main() { HideDebug: !veryVerbose, HideWarn: !(veryVerbose || verbose), }) - controller.DevMode = devMode - controller.ShowDebugMessages = veryVerbose - server.ShowDebugMessages = veryVerbose + core.DevMode = devMode + core.ShowDebugMessages = veryVerbose // _____ _ _ ___ ___ // |_ _|_| |___|_ | . | diff --git a/controller/aof.go b/controller/aof.go index b5c5ab27..11dd7c74 100644 --- a/controller/aof.go +++ b/controller/aof.go @@ -16,7 +16,7 @@ import ( "github.com/boltdb/bolt" "github.com/google/btree" "github.com/tidwall/tile38/client" - "github.com/tidwall/tile38/log" + "github.com/tidwall/tile38/controller/log" ) const backwardsBufferSize = 50000 diff --git a/bing/bing.go b/controller/bing/bing.go similarity index 100% rename from bing/bing.go rename to controller/bing/bing.go diff --git a/bing/bing_test.go b/controller/bing/bing_test.go similarity index 100% rename from bing/bing_test.go rename to controller/bing/bing_test.go diff --git a/bing/ext.go b/controller/bing/ext.go similarity index 100% rename from bing/ext.go rename to controller/bing/ext.go diff --git a/bing/ext_test.go b/controller/bing/ext_test.go similarity index 100% rename from bing/ext_test.go rename to controller/bing/ext_test.go diff --git a/controller/checksum.go b/controller/checksum.go index 6c0d0574..28828be8 100644 --- a/controller/checksum.go +++ b/controller/checksum.go @@ -10,7 +10,8 @@ import ( "os" "github.com/tidwall/tile38/client" - "github.com/tidwall/tile38/log" + "github.com/tidwall/tile38/controller/log" + "github.com/tidwall/tile38/core" ) // checksum performs a simple md5 checksum on the aof file @@ -100,7 +101,7 @@ func (c *Controller) matchChecksums(conn *client.Conn, pos, size int64) (match b // followCheckSome is not a full checksum. It just "checks some" data. // We will do some various checksums on the leader until we find the correct position to start at. func (c *Controller) followCheckSome(addr string, followc uint64) (pos int64, err error) { - if ShowDebugMessages { + if core.ShowDebugMessages { log.Debug("follow:", addr, ":check some") } c.mu.Lock() @@ -215,7 +216,7 @@ outer: pos -= bufsz } if pos == fullpos { - if ShowDebugMessages { + if core.ShowDebugMessages { log.Debug("follow: aof fully intact") } return pos, nil diff --git a/collection/collection.go b/controller/collection/collection.go similarity index 100% rename from collection/collection.go rename to controller/collection/collection.go diff --git a/collection/collection_test.go b/controller/collection/collection_test.go similarity index 100% rename from collection/collection_test.go rename to controller/collection/collection_test.go diff --git a/controller/controller.go b/controller/controller.go index 976a9074..cb6dc2c4 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -16,19 +16,13 @@ import ( "time" "github.com/google/btree" - "github.com/tidwall/tile38/collection" + "github.com/tidwall/tile38/controller/collection" + "github.com/tidwall/tile38/controller/log" + "github.com/tidwall/tile38/controller/server" "github.com/tidwall/tile38/core" "github.com/tidwall/tile38/geojson" - "github.com/tidwall/tile38/log" - "github.com/tidwall/tile38/server" ) -// DevMode puts application in to dev mode -var DevMode = false - -// ShowDebugMessages allows for log.Debug to print to console. -var ShowDebugMessages = false - type collectionT struct { Key string Collection *collection.Collection @@ -163,7 +157,7 @@ func isReservedFieldName(field string) bool { } func (c *Controller) handleInputCommand(line string, w io.Writer) error { - if ShowDebugMessages && line != "pInG" { + if core.ShowDebugMessages && line != "pInG" { log.Debug(line) } start := time.Now() @@ -319,7 +313,7 @@ func (c *Controller) command(line string, w io.Writer) (resp string, d commandDe d, err = c.cmdFlushDB(nline) resp = okResp() case "massinsert": - if !DevMode { + if !core.DevMode { err = fmt.Errorf("unknown command '%s'", cmd) return } diff --git a/controller/crud.go b/controller/crud.go index 9d2db618..a1b19c2a 100644 --- a/controller/crud.go +++ b/controller/crud.go @@ -8,7 +8,7 @@ import ( "time" "github.com/google/btree" - "github.com/tidwall/tile38/collection" + "github.com/tidwall/tile38/controller/collection" "github.com/tidwall/tile38/geojson" "github.com/tidwall/tile38/geojson/geohash" ) diff --git a/controller/dev.go b/controller/dev.go index 9312a3b2..1c9bb582 100644 --- a/controller/dev.go +++ b/controller/dev.go @@ -9,7 +9,7 @@ import ( "sync/atomic" "time" - "github.com/tidwall/tile38/log" + "github.com/tidwall/tile38/controller/log" ) func (c *Controller) cmdMassInsert(line string) error { diff --git a/controller/follow.go b/controller/follow.go index ed22a5c7..77d8c0ce 100644 --- a/controller/follow.go +++ b/controller/follow.go @@ -11,7 +11,8 @@ import ( "time" "github.com/tidwall/tile38/client" - "github.com/tidwall/tile38/log" + "github.com/tidwall/tile38/controller/log" + "github.com/tidwall/tile38/core" ) var errNoLongerFollowing = errors.New("no longer following") @@ -156,7 +157,7 @@ func (c *Controller) followStep(host string, port int, followc uint64) error { } return errors.New("invalid response to aof live request") } - if ShowDebugMessages { + if core.ShowDebugMessages { log.Debug("follow:", addr, ":read aof") } caughtUp := pos >= int64(stats.Stats.AOFSize) diff --git a/controller/live.go b/controller/live.go index 428ef67d..0270a438 100644 --- a/controller/live.go +++ b/controller/live.go @@ -10,9 +10,9 @@ import ( "sync" "github.com/tidwall/tile38/client" - "github.com/tidwall/tile38/collection" + "github.com/tidwall/tile38/controller/collection" + "github.com/tidwall/tile38/controller/log" "github.com/tidwall/tile38/geojson" - "github.com/tidwall/tile38/log" ) type liveBuffer struct { diff --git a/log/log.go b/controller/log/log.go similarity index 100% rename from log/log.go rename to controller/log/log.go diff --git a/controller/readonly.go b/controller/readonly.go index 054dec13..c51e75ce 100644 --- a/controller/readonly.go +++ b/controller/readonly.go @@ -3,7 +3,7 @@ package controller import ( "strings" - "github.com/tidwall/tile38/log" + "github.com/tidwall/tile38/controller/log" ) func (c *Controller) cmdReadOnly(line string) error { diff --git a/controller/scanner.go b/controller/scanner.go index a41b0d35..c199ae87 100644 --- a/controller/scanner.go +++ b/controller/scanner.go @@ -6,7 +6,7 @@ import ( "math" "strconv" - "github.com/tidwall/tile38/collection" + "github.com/tidwall/tile38/controller/collection" "github.com/tidwall/tile38/geojson" ) diff --git a/controller/search.go b/controller/search.go index eb16c095..d1443a5e 100644 --- a/controller/search.go +++ b/controller/search.go @@ -7,7 +7,7 @@ import ( "strings" "time" - "github.com/tidwall/tile38/bing" + "github.com/tidwall/tile38/controller/bing" "github.com/tidwall/tile38/geojson" "github.com/tidwall/tile38/geojson/geohash" ) diff --git a/server/server.go b/controller/server/server.go similarity index 94% rename from server/server.go rename to controller/server/server.go index 1daf0267..38b2ff29 100644 --- a/server/server.go +++ b/controller/server/server.go @@ -10,14 +10,12 @@ import ( "strings" "github.com/tidwall/tile38/client" - "github.com/tidwall/tile38/log" + "github.com/tidwall/tile38/controller/log" + "github.com/tidwall/tile38/core" ) var errCloseHTTP = errors.New("close http") -// ShowDebugMessages allows for log.Debug to print to console. -var ShowDebugMessages = false - // ListenAndServe starts a tile38 server at the specified address. func ListenAndServe( host string, port int, @@ -42,7 +40,7 @@ func handleConn( conn net.Conn, handler func(command []byte, conn net.Conn, rd *bufio.Reader, w io.Writer, websocket bool) error, ) { - if ShowDebugMessages { + if core.ShowDebugMessages { addr := conn.RemoteAddr().String() log.Debugf("opened connection: %s", addr) defer func() { diff --git a/core/options.go b/core/options.go new file mode 100644 index 00000000..eaab1bf6 --- /dev/null +++ b/core/options.go @@ -0,0 +1,7 @@ +package core + +// DevMode puts application in to dev mode +var DevMode = false + +// ShowDebugMessages allows for log.Debug to print to console. +var ShowDebugMessages = false