mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 07:19:26 +00:00
Backend refactor and additions
This commit is contained in:
parent
052ce611f9
commit
5de99b32cd
4 changed files with 37 additions and 3 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -14,6 +15,34 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func GetServerIP(w http.ResponseWriter, r *http.Request) {
|
||||
ifs, err := net.Interfaces()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
for _, ifi := range ifs {
|
||||
addrs, err := ifi.Addrs()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
for _, addr := range addrs {
|
||||
var ip net.IP
|
||||
|
||||
switch v := addr.(type) {
|
||||
case *net.IPNet:
|
||||
ip = v.IP
|
||||
case *net.IPAddr:
|
||||
ip = v.IP
|
||||
}
|
||||
|
||||
if ip != nil && ip.To4() != nil {
|
||||
json.NewEncoder(w).Encode(ip.String())
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func DeviceList(w http.ResponseWriter, r *http.Request) {
|
||||
log.Println("device list")
|
||||
dir := "devices"
|
||||
|
|
@ -29,7 +58,7 @@ func DeviceList(w http.ResponseWriter, r *http.Request) {
|
|||
ext := filepath.Ext(filePath)
|
||||
device := strings.TrimSuffix(file.Name(), ext)
|
||||
|
||||
log.Println(device, ext)
|
||||
// log.Println(device, ext)
|
||||
|
||||
if _, ok := devices[device]; !ok {
|
||||
devices[device] = make(map[string]interface{})
|
||||
|
|
@ -47,6 +76,8 @@ func DeviceList(w http.ResponseWriter, r *http.Request) {
|
|||
"devices": devices,
|
||||
}
|
||||
|
||||
log.Println(result)
|
||||
|
||||
json.NewEncoder(w).Encode(result)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue