mirror of
https://github.com/juanfont/headscale.git
synced 2025-11-02 14:07:47 +09:00
Use gorm connection pool
This commit is contained in:
6
utils.go
6
utils.go
@@ -78,10 +78,6 @@ func encodeMsg(b []byte, pubKey *wgkey.Key, privKey *wgkey.Private) ([]byte, err
|
||||
}
|
||||
|
||||
func (h *Headscale) getAvailableIP() (*net.IP, error) {
|
||||
db, err := h.db()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
i := 0
|
||||
for {
|
||||
ip, err := getRandomIP()
|
||||
@@ -89,7 +85,7 @@ func (h *Headscale) getAvailableIP() (*net.IP, error) {
|
||||
return nil, err
|
||||
}
|
||||
m := Machine{}
|
||||
if result := db.First(&m, "ip_address = ?", ip.String()); errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||
if result := h.db.First(&m, "ip_address = ?", ip.String()); errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||
return ip, nil
|
||||
}
|
||||
i++
|
||||
|
||||
Reference in New Issue
Block a user