chore: apply lint recommendations

This commit is contained in:
Adrien Raffin-Caboisse 2022-05-16 14:59:46 +02:00
parent 02ae7a0563
commit 4435a4f19d
No known key found for this signature in database
GPG key ID: 7FB60532DEBEAD6A
6 changed files with 26 additions and 17 deletions

View file

@ -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,
)

View file

@ -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,

View file

@ -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"+

View file

@ -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
View file

@ -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",
)

View file

@ -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) {