mirror of
https://github.com/AdguardTeam/AdGuardDNS.git
synced 2025-02-20 11:23:36 +08:00
44 lines
982 B
Go
44 lines
982 B
Go
package cmd
|
|
|
|
import (
|
|
"github.com/AdguardTeam/AdGuardDNS/internal/agd"
|
|
"github.com/AdguardTeam/AdGuardDNS/internal/dnsdb"
|
|
)
|
|
|
|
// DNSDB Configuration.
|
|
|
|
// dnsDBConfig is the configuration of the DNSDB module.
|
|
type dnsDBConfig struct {
|
|
// MaxSize is the maximum amount of records in the memory buffer.
|
|
MaxSize int `yaml:"max_size"`
|
|
|
|
// Enabled describes if the DNSDB memory buffer is enabled.
|
|
Enabled bool `yaml:"enabled"`
|
|
}
|
|
|
|
// validate returns an error if the configuration is invalid.
|
|
func (c *dnsDBConfig) validate() (err error) {
|
|
switch {
|
|
case c == nil:
|
|
return errNilConfig
|
|
case c.MaxSize <= 0:
|
|
return newMustBePositiveError("size", c.MaxSize)
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// toInternal builds and returns an anonymous statistics collector.
|
|
func (c *dnsDBConfig) toInternal(errColl agd.ErrorCollector) (d dnsdb.Interface) {
|
|
if !c.Enabled {
|
|
return dnsdb.Empty{}
|
|
}
|
|
|
|
db := dnsdb.New(&dnsdb.DefaultConfig{
|
|
ErrColl: errColl,
|
|
MaxSize: c.MaxSize,
|
|
})
|
|
|
|
return db
|
|
}
|