53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
"src.dualinventive.com/go/config"
|
|
"src.dualinventive.com/go/websocketserver/internal/wss"
|
|
)
|
|
|
|
type cfg struct {
|
|
config.Config `yaml:",inline"`
|
|
|
|
RedisURIs []string `yaml:"redis_uris"`
|
|
MTIWssURI string `yaml:"mtiwss_uri"`
|
|
HTTPListen string `yaml:"http_listen"`
|
|
}
|
|
|
|
var (
|
|
// ApplicationName is the name of the application
|
|
ApplicationName = "wss"
|
|
// ApplicationVersion is the version of the application
|
|
ApplicationVersion = "0.0.0-dev"
|
|
|
|
configuration = cfg{
|
|
RedisURIs: []string{"127.0.0.1:6379"},
|
|
MTIWssURI: "http://127.0.0.1:8080/",
|
|
HTTPListen: ":3003",
|
|
}
|
|
)
|
|
|
|
func main() {
|
|
var confFile string
|
|
flag.StringVar(&confFile, "config", ApplicationName, "Configuration-file name")
|
|
flag.Parse()
|
|
err := config.Load(confFile, &configuration)
|
|
if err != nil {
|
|
logrus.Fatal("Unable to load configuration file:", err)
|
|
}
|
|
|
|
logrus.Infof("Starting %s (version %s)", ApplicationName, ApplicationVersion)
|
|
|
|
s, err := wss.NewServer(configuration.RedisURIs, configuration.HTTPListen, configuration.MTIWssURI)
|
|
if err != nil {
|
|
logrus.Fatal("Unable to run websocket server:", err)
|
|
}
|
|
defer s.Close()
|
|
|
|
if err := s.ListenAndServe(); err != nil {
|
|
logrus.Errorf("listener quit: %v", err)
|
|
}
|
|
}
|