refactor
This commit is contained in:
parent
4e09ee93a5
commit
72de5cc778
@ -1,4 +1,4 @@
|
|||||||
package kml
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -16,7 +16,7 @@ type KML struct {
|
|||||||
points []pointT
|
points []pointT
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *KML {
|
func NewKML() *KML {
|
||||||
return &KML{}
|
return &KML{}
|
||||||
}
|
}
|
||||||
|
|
@ -15,7 +15,6 @@ import (
|
|||||||
"github.com/peterh/liner"
|
"github.com/peterh/liner"
|
||||||
"github.com/tidwall/tile38/client"
|
"github.com/tidwall/tile38/client"
|
||||||
"github.com/tidwall/tile38/core"
|
"github.com/tidwall/tile38/core"
|
||||||
"github.com/tidwall/tile38/kml"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func userHomeDir() string {
|
func userHomeDir() string {
|
||||||
@ -306,7 +305,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func convert2kml(msg []byte) []byte {
|
func convert2kml(msg []byte) []byte {
|
||||||
k := kml.New()
|
k := NewKML()
|
||||||
var m map[string]interface{}
|
var m map[string]interface{}
|
||||||
if err := json.Unmarshal(msg, &m); err == nil {
|
if err := json.Unmarshal(msg, &m); err == nil {
|
||||||
if v, ok := m["points"].([]interface{}); ok {
|
if v, ok := m["points"].([]interface{}); ok {
|
||||||
|
@ -10,9 +10,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/tidwall/tile38/controller"
|
"github.com/tidwall/tile38/controller"
|
||||||
|
"github.com/tidwall/tile38/controller/log"
|
||||||
"github.com/tidwall/tile38/core"
|
"github.com/tidwall/tile38/core"
|
||||||
"github.com/tidwall/tile38/log"
|
|
||||||
"github.com/tidwall/tile38/server"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -42,9 +41,8 @@ func main() {
|
|||||||
HideDebug: !veryVerbose,
|
HideDebug: !veryVerbose,
|
||||||
HideWarn: !(veryVerbose || verbose),
|
HideWarn: !(veryVerbose || verbose),
|
||||||
})
|
})
|
||||||
controller.DevMode = devMode
|
core.DevMode = devMode
|
||||||
controller.ShowDebugMessages = veryVerbose
|
core.ShowDebugMessages = veryVerbose
|
||||||
server.ShowDebugMessages = veryVerbose
|
|
||||||
|
|
||||||
// _____ _ _ ___ ___
|
// _____ _ _ ___ ___
|
||||||
// |_ _|_| |___|_ | . |
|
// |_ _|_| |___|_ | . |
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/boltdb/bolt"
|
"github.com/boltdb/bolt"
|
||||||
"github.com/google/btree"
|
"github.com/google/btree"
|
||||||
"github.com/tidwall/tile38/client"
|
"github.com/tidwall/tile38/client"
|
||||||
"github.com/tidwall/tile38/log"
|
"github.com/tidwall/tile38/controller/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
const backwardsBufferSize = 50000
|
const backwardsBufferSize = 50000
|
||||||
|
@ -10,7 +10,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/tidwall/tile38/client"
|
"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
|
// 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.
|
// 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.
|
// 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) {
|
func (c *Controller) followCheckSome(addr string, followc uint64) (pos int64, err error) {
|
||||||
if ShowDebugMessages {
|
if core.ShowDebugMessages {
|
||||||
log.Debug("follow:", addr, ":check some")
|
log.Debug("follow:", addr, ":check some")
|
||||||
}
|
}
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
@ -215,7 +216,7 @@ outer:
|
|||||||
pos -= bufsz
|
pos -= bufsz
|
||||||
}
|
}
|
||||||
if pos == fullpos {
|
if pos == fullpos {
|
||||||
if ShowDebugMessages {
|
if core.ShowDebugMessages {
|
||||||
log.Debug("follow: aof fully intact")
|
log.Debug("follow: aof fully intact")
|
||||||
}
|
}
|
||||||
return pos, nil
|
return pos, nil
|
||||||
|
@ -16,19 +16,13 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/btree"
|
"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/core"
|
||||||
"github.com/tidwall/tile38/geojson"
|
"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 {
|
type collectionT struct {
|
||||||
Key string
|
Key string
|
||||||
Collection *collection.Collection
|
Collection *collection.Collection
|
||||||
@ -163,7 +157,7 @@ func isReservedFieldName(field string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) handleInputCommand(line string, w io.Writer) error {
|
func (c *Controller) handleInputCommand(line string, w io.Writer) error {
|
||||||
if ShowDebugMessages && line != "pInG" {
|
if core.ShowDebugMessages && line != "pInG" {
|
||||||
log.Debug(line)
|
log.Debug(line)
|
||||||
}
|
}
|
||||||
start := time.Now()
|
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)
|
d, err = c.cmdFlushDB(nline)
|
||||||
resp = okResp()
|
resp = okResp()
|
||||||
case "massinsert":
|
case "massinsert":
|
||||||
if !DevMode {
|
if !core.DevMode {
|
||||||
err = fmt.Errorf("unknown command '%s'", cmd)
|
err = fmt.Errorf("unknown command '%s'", cmd)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/btree"
|
"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"
|
||||||
"github.com/tidwall/tile38/geojson/geohash"
|
"github.com/tidwall/tile38/geojson/geohash"
|
||||||
)
|
)
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tidwall/tile38/log"
|
"github.com/tidwall/tile38/controller/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Controller) cmdMassInsert(line string) error {
|
func (c *Controller) cmdMassInsert(line string) error {
|
||||||
|
@ -11,7 +11,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tidwall/tile38/client"
|
"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")
|
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")
|
return errors.New("invalid response to aof live request")
|
||||||
}
|
}
|
||||||
if ShowDebugMessages {
|
if core.ShowDebugMessages {
|
||||||
log.Debug("follow:", addr, ":read aof")
|
log.Debug("follow:", addr, ":read aof")
|
||||||
}
|
}
|
||||||
caughtUp := pos >= int64(stats.Stats.AOFSize)
|
caughtUp := pos >= int64(stats.Stats.AOFSize)
|
||||||
|
@ -10,9 +10,9 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/tidwall/tile38/client"
|
"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/geojson"
|
||||||
"github.com/tidwall/tile38/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type liveBuffer struct {
|
type liveBuffer struct {
|
||||||
|
@ -3,7 +3,7 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/tidwall/tile38/log"
|
"github.com/tidwall/tile38/controller/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Controller) cmdReadOnly(line string) error {
|
func (c *Controller) cmdReadOnly(line string) error {
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/tidwall/tile38/collection"
|
"github.com/tidwall/tile38/controller/collection"
|
||||||
"github.com/tidwall/tile38/geojson"
|
"github.com/tidwall/tile38/geojson"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tidwall/tile38/bing"
|
"github.com/tidwall/tile38/controller/bing"
|
||||||
"github.com/tidwall/tile38/geojson"
|
"github.com/tidwall/tile38/geojson"
|
||||||
"github.com/tidwall/tile38/geojson/geohash"
|
"github.com/tidwall/tile38/geojson/geohash"
|
||||||
)
|
)
|
||||||
|
@ -10,14 +10,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/tidwall/tile38/client"
|
"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")
|
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.
|
// ListenAndServe starts a tile38 server at the specified address.
|
||||||
func ListenAndServe(
|
func ListenAndServe(
|
||||||
host string, port int,
|
host string, port int,
|
||||||
@ -42,7 +40,7 @@ func handleConn(
|
|||||||
conn net.Conn,
|
conn net.Conn,
|
||||||
handler func(command []byte, conn net.Conn, rd *bufio.Reader, w io.Writer, websocket bool) error,
|
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()
|
addr := conn.RemoteAddr().String()
|
||||||
log.Debugf("opened connection: %s", addr)
|
log.Debugf("opened connection: %s", addr)
|
||||||
defer func() {
|
defer func() {
|
7
core/options.go
Normal file
7
core/options.go
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user