tile38/cmd/tile38-server/main.go

96 lines
2.1 KiB
Go
Raw Normal View History

2016-03-05 02:18:33 +03:00
package main
import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"runtime"
"strconv"
2016-03-08 03:37:39 +03:00
"strings"
2016-03-05 02:18:33 +03:00
"github.com/tidwall/tile38/controller"
2016-03-06 17:55:00 +03:00
"github.com/tidwall/tile38/controller/log"
2016-03-05 02:18:33 +03:00
"github.com/tidwall/tile38/core"
)
var (
2016-03-08 16:11:03 +03:00
dir string
port int
host string
verbose bool
veryVerbose bool
devMode bool
quiet bool
2016-03-05 02:18:33 +03:00
)
func main() {
2016-03-08 03:37:39 +03:00
// parse non standard args.
nargs := []string{os.Args[0]}
for i := 1; i < len(os.Args); i++ {
switch os.Args[i] {
case "--protected-mode", "-protected-mode":
i++
if i < len(os.Args) {
switch strings.ToLower(os.Args[i]) {
case "no":
2016-03-08 16:11:03 +03:00
core.ProtectedMode = "no"
2016-03-08 03:37:39 +03:00
case "yes":
2016-03-08 16:11:03 +03:00
core.ProtectedMode = "yes"
2016-03-08 03:37:39 +03:00
}
continue
}
fmt.Fprintf(os.Stderr, "protected-mode must be 'yes' or 'no'\n")
os.Exit(1)
case "--dev", "-dev":
devMode = true
continue
}
nargs = append(nargs, os.Args[i])
}
os.Args = nargs
2016-03-05 23:39:36 +03:00
flag.IntVar(&port, "p", 9851, "The listening port.")
2016-03-08 03:37:39 +03:00
flag.StringVar(&host, "h", "", "The listening host.")
2016-03-05 02:18:33 +03:00
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.")
flag.BoolVar(&veryVerbose, "vv", false, "Enable very verbose logging.")
flag.Parse()
var logw io.Writer = os.Stderr
if quiet {
logw = ioutil.Discard
}
log.Default = log.New(logw, &log.Config{
HideDebug: !veryVerbose,
HideWarn: !(veryVerbose || verbose),
})
2016-03-06 17:55:00 +03:00
core.DevMode = devMode
core.ShowDebugMessages = veryVerbose
2016-03-08 03:37:39 +03:00
hostd := ""
if host != "" {
hostd = "Addr: " + host + ", "
}
2016-03-05 02:18:33 +03:00
// _____ _ _ ___ ___
// |_ _|_| |___|_ | . |
// | | | | | -_|_ | . |
// |_| |_|_|___|___|___|
fmt.Fprintf(logw, `
_______ _______
| | |
|____ | _ | Tile38 %s (%s) %d bit (%s/%s)
2016-03-08 03:37:39 +03:00
| | | %sPort: %d, PID: %d
2016-03-05 02:18:33 +03:00
|____ | _ |
| | | tile38.com
|_______|_______|
2016-03-08 03:37:39 +03:00
`+"\n", core.Version, core.GitSHA, strconv.IntSize, runtime.GOARCH, runtime.GOOS, hostd, port, os.Getpid())
2016-03-05 02:18:33 +03:00
2016-03-05 23:39:36 +03:00
if err := controller.ListenAndServe(host, port, dir); err != nil {
2016-03-05 02:18:33 +03:00
log.Fatal(err)
}
}