You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.0 KiB
Go
52 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
|
|
chat "git.wens.org.uk/chat/internal"
|
|
)
|
|
|
|
func main() {
|
|
parseArgs()
|
|
|
|
chat.Servers = make(map[string]*chat.Server)
|
|
chat.StartServer("root")
|
|
chat.SetUpHandlers()
|
|
|
|
fmt.Println("chat server listening on", chat.Address)
|
|
if err := http.ListenAndServe(chat.Address, nil); err != nil {
|
|
fmt.Fprintln(os.Stderr, err.Error())
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func parseArgs() {
|
|
db := flag.String("d", chat.DbAddress, "address for db server")
|
|
flag.Parse()
|
|
if chat.DbAddress != *db {
|
|
if !strings.HasPrefix(*db, "http://") {
|
|
*db = "http://" + *db
|
|
}
|
|
chat.DbAddress = *db
|
|
}
|
|
|
|
args := flag.Args()
|
|
if len(args) == 1 {
|
|
chat.Address = args[0]
|
|
}
|
|
|
|
if len(args) > 1 {
|
|
fmt.Fprintln(os.Stderr, "too many arguments. usage: <command> [options] [address]")
|
|
flag.PrintDefaults()
|
|
os.Exit(1)
|
|
}
|
|
|
|
if chat.JwtSecret == "" {
|
|
fmt.Println("Warning: JWT secret is empty string")
|
|
}
|
|
}
|