mirror of https://github.com/tidwall/tile38.git
-host flag, fixes #2
This commit is contained in:
parent
22c21e1ff7
commit
5b0a255ea6
|
@ -18,6 +18,7 @@ import (
|
||||||
var (
|
var (
|
||||||
dir string
|
dir string
|
||||||
port int
|
port int
|
||||||
|
host string
|
||||||
verbose bool
|
verbose bool
|
||||||
veryVerbose bool
|
veryVerbose bool
|
||||||
devMode bool
|
devMode bool
|
||||||
|
@ -25,7 +26,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.IntVar(&port, "p", 9851, "The listening port for communication.")
|
flag.IntVar(&port, "p", 9851, "The listening port.")
|
||||||
|
flag.StringVar(&host, "h", "127.0.0.1", "The listening host.")
|
||||||
flag.StringVar(&dir, "d", "data", "The data directory.")
|
flag.StringVar(&dir, "d", "data", "The data directory.")
|
||||||
flag.BoolVar(&verbose, "v", false, "Enable verbose logging.")
|
flag.BoolVar(&verbose, "v", false, "Enable verbose logging.")
|
||||||
flag.BoolVar(&quiet, "q", false, "Quiet logging. Totally silent.")
|
flag.BoolVar(&quiet, "q", false, "Quiet logging. Totally silent.")
|
||||||
|
@ -53,13 +55,13 @@ func main() {
|
||||||
_______ _______
|
_______ _______
|
||||||
| | |
|
| | |
|
||||||
|____ | _ | Tile38 %s (%s) %d bit (%s/%s)
|
|____ | _ | Tile38 %s (%s) %d bit (%s/%s)
|
||||||
| | | Port: %d, PID: %d
|
| | | Host: %s, Port: %d, PID: %d
|
||||||
|____ | _ |
|
|____ | _ |
|
||||||
| | | tile38.com
|
| | | tile38.com
|
||||||
|_______|_______|
|
|_______|_______|
|
||||||
`+"\n", core.Version, core.GitSHA, strconv.IntSize, runtime.GOARCH, runtime.GOOS, port, os.Getpid())
|
`+"\n", core.Version, core.GitSHA, strconv.IntSize, runtime.GOARCH, runtime.GOOS, host, port, os.Getpid())
|
||||||
|
|
||||||
if err := controller.ListenAndServe(port, dir); err != nil {
|
if err := controller.ListenAndServe(host, port, dir); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ func (col *collectionT) Less(item btree.Item) bool {
|
||||||
// Controller is a tile38 controller
|
// Controller is a tile38 controller
|
||||||
type Controller struct {
|
type Controller struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
|
host string
|
||||||
port int
|
port int
|
||||||
f *os.File
|
f *os.File
|
||||||
cols *btree.BTree // use both tree and map. provide ordering.
|
cols *btree.BTree // use both tree and map. provide ordering.
|
||||||
|
@ -80,9 +81,10 @@ type Config struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenAndServe starts a new tile38 server
|
// ListenAndServe starts a new tile38 server
|
||||||
func ListenAndServe(port int, dir string) error {
|
func ListenAndServe(host string, port int, dir string) error {
|
||||||
log.Infof("Server started, Tile38 version %s, git %s", core.Version, core.GitSHA)
|
log.Infof("Server started, Tile38 version %s, git %s", core.Version, core.GitSHA)
|
||||||
c := &Controller{
|
c := &Controller{
|
||||||
|
host: host,
|
||||||
port: port,
|
port: port,
|
||||||
dir: dir,
|
dir: dir,
|
||||||
cols: btree.New(16),
|
cols: btree.New(16),
|
||||||
|
@ -127,7 +129,7 @@ func ListenAndServe(port int, dir string) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return server.ListenAndServe(port, handler)
|
return server.ListenAndServe(host, port, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) setCol(key string, col *collection.Collection) {
|
func (c *Controller) setCol(key string, col *collection.Collection) {
|
||||||
|
|
|
@ -20,10 +20,10 @@ 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(
|
||||||
port int,
|
host string, port int,
|
||||||
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,
|
||||||
) error {
|
) error {
|
||||||
ln, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
|
ln, err := net.Listen("tcp", fmt.Sprintf("%s:%d", host, port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue