forked from uadmin/uadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
80 lines (72 loc) · 2.23 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package uadmin
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"path"
"path/filepath"
"strings"
"github.com/uadmin/uadmin/colors"
)
const welcomeMessage = "" +
` ___ __ _` + "\n" +
colors.FGBlueB + ` __ __` + colors.FGNormal + `/ | ____/ /___ ___ (_)___` + "\n" +
colors.FGBlueB + ` / / / /` + colors.FGNormal + ` /| |/ __ / __ '__ \/ / __ \` + "\n" +
colors.FGBlueB + `/ /_/ /` + colors.FGNormal + ` ___ / /_/ / / / / / / / / / /` + "\n" +
colors.FGBlueB + `\__,_/` + colors.FGNormal + `_/ |_\__,_/_/ /_/ /_/_/_/ /_/` + "\n"
const w2 = `` +
` ______ __` + "\n" +
` /\ _ \ /\ \ __` + "\n" +
colors.FGBlueB + ` __ __` + colors.FGNormal + `\ \ \L\ \ \_\ \ ___ ___ /\_\ ___` + "\n" +
colors.FGBlueB + `/\ \/\ \` + colors.FGNormal + `\ \ __ \ /'_' \ /' __' __'\/\ \ /' _ '\` + "\n" +
colors.FGBlueB + `\ \ \_\ \` + colors.FGNormal + `\ \ \/\ \/\ \L\ \/\ \/\ \/\ \ \ \/\ \/\ \` + "\n" +
colors.FGBlueB + ` \ \____/` + colors.FGNormal + ` \ \_\ \_\ \___,_\ \_\ \_\ \_\ \_\ \_\ \_\` + "\n" +
colors.FGBlueB + ` \/___/ ` + colors.FGNormal + ` \/_/\/_/\/__,_ /\/_/\/_/\/_/\/_/\/_/\/_/` + "\n" +
``
// StartServer !
func StartServer() {
if !registered {
Register()
}
if !handlersRegistered {
registerHandlers()
}
if val := getBindIP(); val != "" {
BindIP = val
}
if BindIP == "" {
BindIP = "0.0.0.0"
}
Trail(OK, "Server Started: http://%s:%d", BindIP, Port)
fmt.Println(welcomeMessage)
log.Println(http.ListenAndServe(fmt.Sprintf("%s:%d", BindIP, Port), nil))
}
// StartSecureServer !
func StartSecureServer(certFile, keyFile string) {
if !registered {
Register()
}
if !handlersRegistered {
registerHandlers()
}
if val := getBindIP(); val != "" {
BindIP = val
}
if BindIP == "" {
BindIP = "0.0.0.0"
}
Trail(OK, "Server Started: https://%s:%d\n", BindIP, Port)
fmt.Println(welcomeMessage)
log.Println(http.ListenAndServeTLS(fmt.Sprintf("%s:%d", BindIP, Port), certFile, keyFile, nil))
}
func getBindIP() string {
// Check if there is a bind ip file in the source code
ex, _ := os.Executable()
buf, err := ioutil.ReadFile(path.Join(filepath.Dir(ex), ".bindip"))
if err == nil {
return strings.Replace(string(buf), "\n", "", -1)
}
return ""
}