36 lines
624 B
Go
36 lines
624 B
Go
package utils
|
|
|
|
import (
|
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
|
"wireguard-dashboard/client"
|
|
)
|
|
|
|
type wireguard struct{}
|
|
|
|
func Wireguard() wireguard {
|
|
return wireguard{}
|
|
}
|
|
|
|
// GetSpecClient
|
|
// @description: 获取指定客户端链接信息
|
|
// @receiver wireguard
|
|
// @param pk
|
|
// @return *wgtypes.Peer
|
|
// @return error
|
|
func (wireguard) GetSpecClient(pk string) (*wgtypes.Peer, error) {
|
|
device, err := client.WireguardClient.Devices()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for _, v := range device {
|
|
for _, p := range v.Peers {
|
|
if p.PublicKey.String() == pk {
|
|
return &p, nil
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil, nil
|
|
}
|