Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e13a6d4cd | ||
|
|
9d039b4e2c | ||
| 543383186a | |||
|
|
46a56e130f | ||
|
|
aa900d5e3b | ||
|
|
91cb3a48f8 | ||
|
|
e05c3a06ae |
@@ -6,7 +6,7 @@ on:
|
|||||||
- '*'
|
- '*'
|
||||||
|
|
||||||
env:
|
env:
|
||||||
APP_NAME: slideshowApp
|
APP_NAME: slideshowapp
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,4 +1,6 @@
|
|||||||
images/
|
images/
|
||||||
slideshowApp
|
slideshowApp
|
||||||
|
slideshowapp
|
||||||
schedule.json
|
schedule.json
|
||||||
*.log
|
*.log
|
||||||
|
*.exe
|
||||||
8
env/enviroment.go
vendored
8
env/enviroment.go
vendored
@@ -26,7 +26,13 @@ func Load(path string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (key EnvKey) GetValue() string {
|
func (key EnvKey) GetValue() string {
|
||||||
return os.Getenv(string(key))
|
keyStr := string(key)
|
||||||
|
value := os.Getenv(keyStr)
|
||||||
|
if key == Port && value == "" {
|
||||||
|
value = "8080"
|
||||||
|
}
|
||||||
|
|
||||||
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
func (key EnvKey) SetValue(value string) {
|
func (key EnvKey) SetValue(value string) {
|
||||||
|
|||||||
@@ -20,34 +20,34 @@ func GetLocalIP() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getActiveIP() string {
|
func getActiveIP() string {
|
||||||
conn, err := net.Dial("udp", "8.8.8.8:80")
|
addrs, err := net.InterfaceAddrs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
addr := conn.LocalAddr()
|
for _, address := range addrs {
|
||||||
if udpAddr, ok := addr.(*net.UDPAddr); ok {
|
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
||||||
return udpAddr.IP.String()
|
|
||||||
|
if ipnet.IP.To4() != nil {
|
||||||
|
ipStr := ipnet.IP.String()
|
||||||
|
|
||||||
|
if ipnet.IP.IsLinkLocalUnicast() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return ipStr
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func InfoHandler(w http.ResponseWriter, r *http.Request) {
|
func InfoHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
port := env.Port.GetValue()
|
|
||||||
if port == "" {
|
|
||||||
port = "8080"
|
|
||||||
}
|
|
||||||
|
|
||||||
speed := env.IntervalDefault.GetValue()
|
|
||||||
if speed == "" {
|
|
||||||
speed = "10"
|
|
||||||
}
|
|
||||||
|
|
||||||
data := map[string]string{
|
data := map[string]string{
|
||||||
"ip": GetLocalIP(),
|
"ip": GetLocalIP(),
|
||||||
"port": port,
|
"port": env.Port.GetValue(),
|
||||||
"speed": GetInterval(),
|
"speed": GetInterval(),
|
||||||
}
|
}
|
||||||
err := json.NewEncoder(w).Encode(data)
|
err := json.NewEncoder(w).Encode(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user