diff options
| author | Kevin Chabowski <kevin@kch42.de> | 2014-06-01 13:21:45 +0200 | 
|---|---|---|
| committer | Kevin Chabowski <kevin@kch42.de> | 2014-06-01 13:21:45 +0200 | 
| commit | aff7bc512d5726a020e4107690abd24ae91b1b48 (patch) | |
| tree | 1dd1e5f0222ca6b0a547c412dfe9a8d2c32015fa /main.go | |
| parent | e9fa4b6c8a552bfe715f048f189e813d7026b442 (diff) | |
| download | simplechat-aff7bc512d5726a020e4107690abd24ae91b1b48.tar.gz simplechat-aff7bc512d5726a020e4107690abd24ae91b1b48.tar.bz2 simplechat-aff7bc512d5726a020e4107690abd24ae91b1b48.zip | |
Added TLS support
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 19 | 
1 files changed, 18 insertions, 1 deletions
| @@ -16,6 +16,9 @@ var (  	tplpath    = flag.String("tplpath", "tpls", "Path to templates")  	staticpath = flag.String("staticpath", "static", "Path to static page elements")  	perroom    = flag.Int("perroom", -1, "Maximum amount of users per room (negative for unlimited)") +	usetls     = flag.Bool("tls", false, "Should TLS be used?") +	certfile   = flag.String("tlscert", "", "TLS certificate file") +	keyfile    = flag.String("tlskey", "", "TLS key file")  )  func main() { @@ -39,5 +42,19 @@ func main() {  	r.HandleFunc("/chat/{chatroom:.+}/", Chatpage)  	r.HandleFunc("/chat/{chatroom:.+}", Chatpage)  	http.Handle("/", r) -	http.ListenAndServe(*laddr, nil) + +	var listenServe func() error +	if *usetls { +		listenServe = func() error { +			return http.ListenAndServeTLS(*laddr, *certfile, *keyfile, nil) +		} +	} else { +		listenServe = func() error { +			return http.ListenAndServe(*laddr, nil) +		} +	} + +	if err := listenServe(); err != nil { +		log.Fatal(err) +	}  } | 
