mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-25 05:35:52 -05:00
chore: apply lint recommendations
This commit is contained in:
parent
02ae7a0563
commit
4435a4f19d
2
acls.go
2
acls.go
@ -262,7 +262,7 @@ func expandAlias(
|
||||
}
|
||||
if len(ips) == 0 {
|
||||
return ips, fmt.Errorf(
|
||||
"%w. %v isn't owned by a TagOwner and no forced tags are defined.",
|
||||
"%w. %v isn't owned by a TagOwner and no forced tags are defined",
|
||||
errInvalidTag,
|
||||
alias,
|
||||
)
|
||||
|
@ -498,13 +498,13 @@ func nodesToPtables(
|
||||
namespace = pterm.LightYellow(machine.Namespace.Name)
|
||||
}
|
||||
|
||||
var IpV4Address string
|
||||
var IpV6Address string
|
||||
var IPV4Address string
|
||||
var IPV6Address string
|
||||
for _, addr := range machine.IpAddresses {
|
||||
if netaddr.MustParseIP(addr).Is4() {
|
||||
IpV4Address = addr
|
||||
IPV4Address = addr
|
||||
} else {
|
||||
IpV6Address = addr
|
||||
IPV6Address = addr
|
||||
}
|
||||
}
|
||||
|
||||
@ -513,7 +513,7 @@ func nodesToPtables(
|
||||
machine.Name,
|
||||
nodeKey.ShortString(),
|
||||
namespace,
|
||||
strings.Join([]string{IpV4Address, IpV6Address}, ", "),
|
||||
strings.Join([]string{IPV4Address, IPV6Address}, ", "),
|
||||
strconv.FormatBool(ephemeral),
|
||||
lastSeenTime,
|
||||
online,
|
||||
|
@ -128,7 +128,7 @@ func (h *Headscale) DERPHandler(ctx *gin.Context) {
|
||||
|
||||
if !fastStart {
|
||||
pubKey := h.privateKey.Public()
|
||||
pubKeyStr := pubKey.UntypedHexString()
|
||||
pubKeyStr := pubKey.UntypedHexString() // nolint
|
||||
fmt.Fprintf(conn, "HTTP/1.1 101 Switching Protocols\r\n"+
|
||||
"Upgrade: DERP\r\n"+
|
||||
"Connection: Upgrade\r\n"+
|
||||
|
@ -664,9 +664,11 @@ func getTags(
|
||||
aclPolicy *ACLPolicy,
|
||||
machine Machine,
|
||||
stripEmailDomain bool,
|
||||
) (validTags []string, invalidTags []string) {
|
||||
) ([]string, []string) {
|
||||
validTags := make([]string, 0)
|
||||
invalidTags := make([]string, 0)
|
||||
if aclPolicy == nil {
|
||||
return
|
||||
return validTags, invalidTags
|
||||
}
|
||||
validTagMap := make(map[string]bool)
|
||||
invalidTagMap := make(map[string]bool)
|
||||
|
10
poll.go
10
poll.go
@ -20,6 +20,10 @@ const (
|
||||
updateCheckInterval = 10 * time.Second
|
||||
)
|
||||
|
||||
type contextKey string
|
||||
|
||||
const machineNameContextKey = contextKey("machineName")
|
||||
|
||||
// PollNetMapHandler takes care of /machine/:id/map
|
||||
//
|
||||
// This is the busiest endpoint, as it keeps the HTTP long poll that updates
|
||||
@ -272,7 +276,7 @@ func (h *Headscale) PollNetMapStream(
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.WithValue(ctx.Request.Context(), "machineName", machine.Name)
|
||||
ctx := context.WithValue(ctx.Request.Context(), machineNameContextKey, machine.Name)
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
@ -576,12 +580,12 @@ func (h *Headscale) scheduledPollWorker(
|
||||
|
||||
defer closeChanWithLog(
|
||||
updateChan,
|
||||
fmt.Sprint(ctx.Value("machineName")),
|
||||
fmt.Sprint(ctx.Value(machineNameContextKey)),
|
||||
"updateChan",
|
||||
)
|
||||
defer closeChanWithLog(
|
||||
keepAliveChan,
|
||||
fmt.Sprint(ctx.Value("machineName")),
|
||||
fmt.Sprint(ctx.Value(machineNameContextKey)),
|
||||
"updateChan",
|
||||
)
|
||||
|
||||
|
13
utils.go
13
utils.go
@ -136,26 +136,29 @@ func encode(
|
||||
return privKey.SealTo(*pubKey, b), nil
|
||||
}
|
||||
|
||||
func (h *Headscale) getAvailableIPs() (ips MachineAddresses, err error) {
|
||||
func (h *Headscale) getAvailableIPs() (MachineAddresses, error) {
|
||||
var ips MachineAddresses
|
||||
var err error
|
||||
ipPrefixes := h.cfg.IPPrefixes
|
||||
for _, ipPrefix := range ipPrefixes {
|
||||
var ip *netaddr.IP
|
||||
ip, err = h.getAvailableIP(ipPrefix)
|
||||
if err != nil {
|
||||
return
|
||||
return ips, err
|
||||
}
|
||||
ips = append(ips, *ip)
|
||||
}
|
||||
|
||||
return
|
||||
return ips, err
|
||||
}
|
||||
|
||||
func GetIPPrefixEndpoints(na netaddr.IPPrefix) (network, broadcast netaddr.IP) {
|
||||
func GetIPPrefixEndpoints(na netaddr.IPPrefix) (netaddr.IP, netaddr.IP) {
|
||||
var network, broadcast netaddr.IP
|
||||
ipRange := na.Range()
|
||||
network = ipRange.From()
|
||||
broadcast = ipRange.To()
|
||||
|
||||
return
|
||||
return network, broadcast
|
||||
}
|
||||
|
||||
func (h *Headscale) getAvailableIP(ipPrefix netaddr.IPPrefix) (*netaddr.IP, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user