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 (
|
||||
dir string
|
||||
port int
|
||||
host string
|
||||
verbose bool
|
||||
veryVerbose bool
|
||||
devMode bool
|
||||
|
@ -25,7 +26,8 @@ var (
|
|||
)
|
||||
|
||||
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.BoolVar(&verbose, "v", false, "Enable verbose logging.")
|
||||
flag.BoolVar(&quiet, "q", false, "Quiet logging. Totally silent.")
|
||||
|
@ -53,13 +55,13 @@ func main() {
|
|||
_______ _______
|
||||
| | |
|
||||
|____ | _ | Tile38 %s (%s) %d bit (%s/%s)
|
||||
| | | Port: %d, PID: %d
|
||||
| | | Host: %s, Port: %d, PID: %d
|
||||
|____ | _ |
|
||||
| | | 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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ func (col *collectionT) Less(item btree.Item) bool {
|
|||
// Controller is a tile38 controller
|
||||
type Controller struct {
|
||||
mu sync.RWMutex
|
||||
host string
|
||||
port int
|
||||
f *os.File
|
||||
cols *btree.BTree // use both tree and map. provide ordering.
|
||||
|
@ -80,9 +81,10 @@ type Config struct {
|
|||
}
|
||||
|
||||
// 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)
|
||||
c := &Controller{
|
||||
host: host,
|
||||
port: port,
|
||||
dir: dir,
|
||||
cols: btree.New(16),
|
||||
|
@ -127,7 +129,7 @@ func ListenAndServe(port int, dir string) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
return server.ListenAndServe(port, handler)
|
||||
return server.ListenAndServe(host, port, handler)
|
||||
}
|
||||
|
||||
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.
|
||||
func ListenAndServe(
|
||||
port int,
|
||||
host string, port int,
|
||||
handler func(command []byte, conn net.Conn, rd *bufio.Reader, w io.Writer, websocket bool) 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 {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue