init
This commit is contained in:
Executable
+51
@@ -0,0 +1,51 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user