chore: apply linting

This commit is contained in:
Adrien Raffin-Caboisse 2022-04-25 22:27:44 +02:00
parent 3d302441b6
commit 2c448d4a5c
No known key found for this signature in database
GPG key ID: 7FB60532DEBEAD6A
7 changed files with 24 additions and 13 deletions

3
app.go
View file

@ -318,7 +318,8 @@ func (h *Headscale) expireEphemeralNodesWorker() {
func (h *Headscale) grpcAuthenticationInterceptor(ctx context.Context, func (h *Headscale) grpcAuthenticationInterceptor(ctx context.Context,
req interface{}, req interface{},
info *grpc.UnaryServerInfo, info *grpc.UnaryServerInfo,
handler grpc.UnaryHandler) (interface{}, error) { handler grpc.UnaryHandler,
) (interface{}, error) {
// Check if the request is coming from the on-server client. // Check if the request is coming from the on-server client.
// This is not secure, but it is to maintain maintainability // This is not secure, but it is to maintain maintainability
// with the "legacy" database-based client // with the "legacy" database-based client

View file

@ -566,9 +566,9 @@ func GetFileMode(key string) fs.FileMode {
return fs.FileMode(mode) return fs.FileMode(mode)
} }
func contains[T string](ts []T, t T) bool { func contains(ts []T, t T) bool {
for _, v := range ts { for _, v := range ts {
if reflect.DeepEqual(v,t) { if reflect.DeepEqual(v, t) {
return true return true
} }
} }

View file

@ -128,7 +128,7 @@ func (h *Headscale) DERPHandler(ctx *gin.Context) {
if !fastStart { if !fastStart {
pubKey := h.privateKey.Public() pubKey := h.privateKey.Public()
pubKeyStr := pubKey.UntypedHexString() // nolint pubKeyStr := pubKey.UntypedHexString()
fmt.Fprintf(conn, "HTTP/1.1 101 Switching Protocols\r\n"+ fmt.Fprintf(conn, "HTTP/1.1 101 Switching Protocols\r\n"+
"Upgrade: DERP\r\n"+ "Upgrade: DERP\r\n"+
"Connection: Upgrade\r\n"+ "Connection: Upgrade\r\n"+

View file

@ -363,8 +363,7 @@ func (h *Headscale) UpdateMachine(machine *Machine) error {
// SetTags takes a Machine struct pointer and update the forced tags. // SetTags takes a Machine struct pointer and update the forced tags.
func (h *Headscale) SetTags(machine *Machine, tags []string) error { func (h *Headscale) SetTags(machine *Machine, tags []string) error {
machine.ForcedTags = tags machine.ForcedTags = tags
err := h.UpdateACLRules() if err := h.UpdateACLRules(); err != nil {
if err != nil {
return err return err
} }
h.setLastStateChangeToNow(machine.Namespace.Name) h.setLastStateChangeToNow(machine.Namespace.Name)
@ -670,6 +669,7 @@ func getTags(
owners, err := expandTagOwners(aclPolicy, tag, stripEmailDomain) owners, err := expandTagOwners(aclPolicy, tag, stripEmailDomain)
if errors.Is(err, errInvalidTag) { if errors.Is(err, errInvalidTag) {
invalidTagMap[tag] = true invalidTagMap[tag] = true
continue continue
} }
var found bool var found bool

View file

@ -387,13 +387,23 @@ func Test_getTags(t *testing.T) {
) )
for _, valid := range gotValid { for _, valid := range gotValid {
if !contains(test.wantValid, valid) { if !contains(test.wantValid, valid) {
t.Errorf("valids: getTags() = %v, want %v", gotValid, test.wantValid) t.Errorf(
"valids: getTags() = %v, want %v",
gotValid,
test.wantValid,
)
break break
} }
} }
for _, invalid := range gotInvalid { for _, invalid := range gotInvalid {
if !contains(test.wantInvalid, invalid) { if !contains(test.wantInvalid, invalid) {
t.Errorf("invalids: getTags() = %v, want %v", gotInvalid, test.wantInvalid) t.Errorf(
"invalids: getTags() = %v, want %v",
gotInvalid,
test.wantInvalid,
)
break break
} }
} }

View file

@ -619,7 +619,7 @@ func (h *Headscale) scheduledPollWorker(
} }
} }
func closeChanWithLog[C chan []byte | chan struct{}](channel C, machine, name string) { func closeChanWithLog(channel C, machine, name string) {
log.Trace(). log.Trace().
Str("handler", "PollNetMap"). Str("handler", "PollNetMap").
Str("machine", machine). Str("machine", machine).