Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
  • Loading branch information
uubulb committed Feb 12, 2025
1 parent 0e26110 commit 447065d
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 66 deletions.
3 changes: 2 additions & 1 deletion cmd/dashboard/controller/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (

"github.com/gin-gonic/gin"
"github.com/jinzhu/copier"
"gorm.io/gorm"

"github.com/nezhahq/nezha/model"
"github.com/nezhahq/nezha/service/singleton"
"gorm.io/gorm"
)

// List notification
Expand Down
3 changes: 2 additions & 1 deletion cmd/dashboard/controller/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func updateServer(c *gin.Context) (any, error) {
return nil, newGormError("%v", err)
}

s.CopyFromRunningServer(singleton.ServerShared.GetList()[s.ID])
rs, _ := singleton.ServerShared.Get(s.ID)
s.CopyFromRunningServer(rs)
singleton.ServerShared.Update(&s, "")

return nil, nil
Expand Down
26 changes: 0 additions & 26 deletions cmd/dashboard/controller/ws_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/dashboard/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func DispatchKeepalive() {
}

func ServeNAT(w http.ResponseWriter, r *http.Request, natConfig *model.NAT) {
server := singleton.ServerShared.GetList()[natConfig.ServerID]
server, _ := singleton.ServerShared.Get(natConfig.ServerID)
if server == nil || server.TaskStream == nil {
w.WriteHeader(http.StatusServiceUnavailable)
w.Write([]byte("server not found or not connected"))
Expand Down
37 changes: 0 additions & 37 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"maps"
"math/big"
"net/netip"
"os"
"regexp"
"slices"
"strconv"
Expand Down Expand Up @@ -71,35 +70,6 @@ func GetIPFromHeader(headerValue string) (string, error) {
return ip.String(), nil
}

// SplitIPAddr 传入/分割的v4v6混合地址,返回v4和v6地址与有效地址
func SplitIPAddr(v4v6Bundle string) (string, string, string) {
ipList := strings.Split(v4v6Bundle, "/")
ipv4 := ""
ipv6 := ""
validIP := ""
if len(ipList) > 1 {
// 双栈
ipv4 = ipList[0]
ipv6 = ipList[1]
validIP = ipv4
} else if len(ipList) == 1 {
// 仅ipv4|ipv6
if strings.Contains(ipList[0], ":") {
ipv6 = ipList[0]
validIP = ipv6
} else {
ipv4 = ipList[0]
validIP = ipv4
}
}
return ipv4, ipv6, validIP
}

func IsFileExists(path string) bool {
_, err := os.Stat(path)
return err == nil
}

func GenerateRandomString(n int) (string, error) {
const letters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
lettersLength := big.NewInt(int64(len(letters)))
Expand Down Expand Up @@ -131,13 +101,6 @@ func IfOr[T any](a bool, x, y T) T {
return y
}

func IfOrFn[T any](a bool, x, y func() T) T {
if a {
return x()
}
return y()
}

func Itoa[T constraints.Integer](i T) string {
switch any(i).(type) {
case int, int8, int16, int32, int64:
Expand Down

0 comments on commit 447065d

Please sign in to comment.