Default HTTP(S) port to -1 + random port on config set to 0
This commit is contained in:
parent
8847f220fd
commit
7da25057cf
18
http/http.go
18
http/http.go
|
|
@ -5,6 +5,7 @@ import (
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -28,13 +29,15 @@ const (
|
||||||
RETURN_VALUE_OK = "OK"
|
RETURN_VALUE_OK = "OK"
|
||||||
RETURN_VALUE_NOK = "NOK"
|
RETURN_VALUE_NOK = "NOK"
|
||||||
|
|
||||||
|
MAX_PORT_VAL = 65535
|
||||||
|
|
||||||
StatusUnknownError = 520
|
StatusUnknownError = 520
|
||||||
StatusUnreachable = 523
|
StatusUnreachable = 523
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
HttpPortBind = 9090
|
HttpPortBind = -1
|
||||||
HttpsPortBind = 9093
|
HttpsPortBind = -1
|
||||||
CertPath = "./cert.pem"
|
CertPath = "./cert.pem"
|
||||||
KeyPath = "./key.pem"
|
KeyPath = "./key.pem"
|
||||||
|
|
||||||
|
|
@ -43,8 +46,11 @@ var (
|
||||||
MaxTimeout = 300 // 5 min
|
MaxTimeout = 300 // 5 min
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
|
}
|
||||||
|
|
||||||
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// TODO
|
|
||||||
fmt.Fprintf(w, "Welcome to HTTP authentification over XMPP")
|
fmt.Fprintf(w, "Welcome to HTTP authentification over XMPP")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,9 +126,15 @@ func Run() {
|
||||||
|
|
||||||
if HttpPortBind > 0 {
|
if HttpPortBind > 0 {
|
||||||
go runHttp()
|
go runHttp()
|
||||||
|
} else if HttpPortBind == 0 {
|
||||||
|
HttpPortBind = rand.Intn(MAX_PORT_VAL)
|
||||||
|
go runHttp()
|
||||||
}
|
}
|
||||||
if HttpsPortBind > 0 {
|
if HttpsPortBind > 0 {
|
||||||
go runHttps()
|
go runHttps()
|
||||||
|
} else if HttpsPortBind == 0 {
|
||||||
|
HttpsPortBind = rand.Intn(MAX_PORT_VAL)
|
||||||
|
go runHttps()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue