2015-10-24 19:59:34 -07:00
|
|
|
package main // import "bitbucket.org/stendec/frankerfacez/socketserver/cmd/socketserver"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2015-10-24 22:38:04 -07:00
|
|
|
"../../listener"
|
2015-10-24 19:59:34 -07:00
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
var origin *string = flag.String("origin", "localhost:8001", "Client-visible origin of the socket server")
|
|
|
|
var bindAddress *string = flag.String("listen", "", "Address to bind to, if different from origin")
|
|
|
|
var certificateFile *string = flag.String("crt", "", "SSL certificate file")
|
|
|
|
var privateKeyFile *string = flag.String("key", "", "SSL private key file")
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if *origin == "" {
|
|
|
|
log.Fatalln("--origin argument required")
|
|
|
|
}
|
|
|
|
if *bindAddress == "" {
|
|
|
|
bindAddress = origin
|
|
|
|
}
|
|
|
|
if (*certificateFile == "") != (*privateKeyFile == "") {
|
|
|
|
log.Fatalln("Either both --crt and --key can be provided, or neither.")
|
|
|
|
}
|
|
|
|
|
2015-10-24 22:38:04 -07:00
|
|
|
conf := &listener.Config {
|
2015-10-24 19:59:34 -07:00
|
|
|
SSLKeyFile: *privateKeyFile,
|
|
|
|
SSLCertificateFile: *certificateFile,
|
|
|
|
UseSSL: *certificateFile != "",
|
|
|
|
|
|
|
|
Origin: *origin,
|
|
|
|
}
|
|
|
|
|
2015-10-24 22:38:04 -07:00
|
|
|
listener.SetupServerAndHandle(conf)
|
2015-10-24 19:59:34 -07:00
|
|
|
|
|
|
|
var err error
|
|
|
|
if conf.UseSSL {
|
|
|
|
err = http.ListenAndServeTLS(*bindAddress, *certificateFile, *privateKeyFile, nil)
|
|
|
|
} else {
|
|
|
|
err = http.ListenAndServe(*bindAddress, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("ListenAndServe: ", err)
|
|
|
|
}
|
|
|
|
}
|