DEVELOPMENT ENVIRONMENT

~liljamo/felu

ref: 326c993612df33f8ae796d652157bf49281a1596 felu/internal/dns/misc.go -rw-r--r-- 675 bytes
326c9936Jonni Liljamo feat: zoneOf function 21 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
 * Copyright (C) 2024 Jonni Liljamo <jonni@liljamo.com>
 *
 * This file is licensed under AGPL-3.0-or-later, see NOTICE and LICENSE for
 * more information.
 */

package dns

import (
	"log/slog"
	"strings"
)

func zoneOf(fqdn string, zone string) bool {
	// Get the index of the first '.', and compare everything after that to zone.
	if index := strings.IndexByte(fqdn, '.'); index >= 0 {
		index++
		return fqdn[index:] == zone
	}

	// Probably both fqdn and zone were just '.'. Crossing my fingers and hoping
	// this can't be reached in correct configuration.
	slog.Error("Invalid use of zone_of", slog.String("fqdn", fqdn), slog.String("zone", zone))
	return false
}