add idea server

This commit is contained in:
ehlxr 2018-01-22 11:44:36 +08:00
parent 6b2d7ad843
commit fa16b18360

View File

@ -9,6 +9,7 @@ import (
"encoding/hex" "encoding/hex"
"encoding/pem" "encoding/pem"
"flag" "flag"
"fmt"
"log" "log"
"net/http" "net/http"
"os" "os"
@ -19,18 +20,19 @@ import (
func main() { func main() {
log.SetOutput(os.Stdout) log.SetOutput(os.Stdout)
address := flag.String("addr", "127.0.0.1:9418", "Bind TCP Address") port := flag.Int("p", 1017, "port")
host := flag.String("host", "0.0.0.0", "Bind TCP Address")
flag.Parse() flag.Parse()
log.Println("Starting server at http://" + *address) addr := fmt.Sprintf("%s:%d", *host, *port)
log.Println("Quit the server with CTRL-C.") if strings.Contains(addr, "0.0.0.0") {
addr = strings.Replace(addr, "0.0.0.0", "127.0.0.1", 1)
if strings.Contains(*address, "0.0.0.0") {
*address = strings.Replace(*address, "0.0.0.0", "", 1)
} }
log.Println("Starting server at http://" + addr)
routerBinding() routerBinding()
err := http.ListenAndServe(*address, http.DefaultServeMux) err := http.ListenAndServe(addr, http.DefaultServeMux)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }