AdGuardHome/internal/client/client.go
Stanislav Chzhen 905f9615a8 Pull request 1989: AG-24794-client-source
Squashed commit of the following:

commit 5cf83aafc8ddfea15b4f8e9b4061af021727f68c
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Fri Sep 1 14:58:03 2023 +0300

    client: imp code

commit 4325c8f610d1329ad38c800e20275668f1690f51
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Fri Sep 1 14:38:33 2023 +0300

    all: add client source
2023-09-01 15:24:44 +03:00

54 lines
1 KiB
Go

// Package client contains types and logic dealing with AdGuard Home's DNS
// clients.
//
// TODO(a.garipov): Expand.
package client
import (
"encoding"
"fmt"
)
// Source represents the source from which the information about the client has
// been obtained.
type Source uint8
// Clients information sources. The order determines the priority.
const (
SourceNone Source = iota
SourceWHOIS
SourceARP
SourceRDNS
SourceDHCP
SourceHostsFile
SourcePersistent
)
// type check
var _ fmt.Stringer = Source(0)
// String returns a human-readable name of cs.
func (cs Source) String() (s string) {
switch cs {
case SourceWHOIS:
return "WHOIS"
case SourceARP:
return "ARP"
case SourceRDNS:
return "rDNS"
case SourceDHCP:
return "DHCP"
case SourceHostsFile:
return "etc/hosts"
default:
return ""
}
}
// type check
var _ encoding.TextMarshaler = Source(0)
// MarshalText implements encoding.TextMarshaler for the Source.
func (cs Source) MarshalText() (text []byte, err error) {
return []byte(cs.String()), nil
}