mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 15:29: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
|
|
@ -67,6 +67,8 @@ func ApiPost(w http.ResponseWriter, r *http.Request) {
|
||||||
DeleteMacro(w, r)
|
DeleteMacro(w, r)
|
||||||
case "/macro/play":
|
case "/macro/play":
|
||||||
PlayMacro("", w, r)
|
PlayMacro("", w, r)
|
||||||
|
case "/device/server/ip":
|
||||||
|
GetServerIP(w, r)
|
||||||
case "/device/list":
|
case "/device/list":
|
||||||
DeviceList(w, r)
|
DeviceList(w, r)
|
||||||
case "/device/access/check":
|
case "/device/access/check":
|
||||||
|
|
@ -82,7 +84,6 @@ func ApiPost(w http.ResponseWriter, r *http.Request) {
|
||||||
case "/device/link/remove":
|
case "/device/link/remove":
|
||||||
RemoveLink("", w, r)
|
RemoveLink("", w, r)
|
||||||
case "/device/handshake":
|
case "/device/handshake":
|
||||||
log.Println("handshake")
|
|
||||||
Handshake(w, r)
|
Handshake(w, r)
|
||||||
case "/panel/list":
|
case "/panel/list":
|
||||||
PanelList(w, r)
|
PanelList(w, r)
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -14,6 +15,34 @@ import (
|
||||||
"time"
|
"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) {
|
func DeviceList(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Println("device list")
|
log.Println("device list")
|
||||||
dir := "devices"
|
dir := "devices"
|
||||||
|
|
@ -29,7 +58,7 @@ func DeviceList(w http.ResponseWriter, r *http.Request) {
|
||||||
ext := filepath.Ext(filePath)
|
ext := filepath.Ext(filePath)
|
||||||
device := strings.TrimSuffix(file.Name(), ext)
|
device := strings.TrimSuffix(file.Name(), ext)
|
||||||
|
|
||||||
log.Println(device, ext)
|
// log.Println(device, ext)
|
||||||
|
|
||||||
if _, ok := devices[device]; !ok {
|
if _, ok := devices[device]; !ok {
|
||||||
devices[device] = make(map[string]interface{})
|
devices[device] = make(map[string]interface{})
|
||||||
|
|
@ -47,6 +76,8 @@ func DeviceList(w http.ResponseWriter, r *http.Request) {
|
||||||
"devices": devices,
|
"devices": devices,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println(result)
|
||||||
|
|
||||||
json.NewEncoder(w).Encode(result)
|
json.NewEncoder(w).Encode(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ var Endpoints = Allowed{
|
||||||
"/macro/list",
|
"/macro/list",
|
||||||
"/macro/delete",
|
"/macro/delete",
|
||||||
"/macro/play",
|
"/macro/play",
|
||||||
|
"/device/server/ip",
|
||||||
"/device/list",
|
"/device/list",
|
||||||
"/device/access/check",
|
"/device/access/check",
|
||||||
"/device/access/request",
|
"/device/access/request",
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"be/app"
|
"be/app"
|
||||||
|
"be/app/helper"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -12,7 +13,7 @@ func main() {
|
||||||
apiInit(w, r)
|
apiInit(w, r)
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Println(http.ListenAndServe(":6970", nil))
|
log.Println(http.ListenAndServe(":"+helper.EnvGet("MCRM__PORT"), nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiInit(w http.ResponseWriter, r *http.Request) {
|
func apiInit(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue