doggo/cmd/hub.go

48 lines
1.1 KiB
Go
Raw Normal View History

2020-12-09 18:11:09 +01:00
package main
import (
2020-12-10 17:14:04 +01:00
"github.com/miekg/dns"
2020-12-11 12:18:54 +01:00
"github.com/mr-karan/doggo/pkg/resolvers"
2020-12-09 18:11:09 +01:00
"github.com/sirupsen/logrus"
2020-12-10 10:39:05 +01:00
"github.com/urfave/cli/v2"
2020-12-09 18:11:09 +01:00
)
// Hub represents the structure for all app wide functions and structs.
type Hub struct {
2020-12-10 17:14:04 +01:00
Logger *logrus.Logger
Version string
QueryFlags QueryFlags
Questions []dns.Question
2020-12-11 12:18:54 +01:00
Resolver resolvers.Resolver
2020-12-10 17:14:04 +01:00
}
// QueryFlags is used store the value of CLI flags.
type QueryFlags struct {
QNames *cli.StringSlice
QTypes *cli.StringSlice
QClasses *cli.StringSlice
Nameservers *cli.StringSlice
2020-12-11 12:18:54 +01:00
IsDOH bool
IsDOT bool
IsUDP bool
2020-12-12 08:46:45 +01:00
UseTCP bool
2020-12-12 07:46:54 +01:00
UseIPv4 bool
UseIPv6 bool
2020-12-09 18:11:09 +01:00
}
// NewHub initializes an instance of Hub which holds app wide configuration.
func NewHub(logger *logrus.Logger, buildVersion string) *Hub {
2020-12-10 17:14:04 +01:00
// Initialise Resolver
2020-12-09 18:11:09 +01:00
hub := &Hub{
Logger: logger,
Version: buildVersion,
2020-12-10 17:14:04 +01:00
QueryFlags: QueryFlags{
QNames: cli.NewStringSlice(),
QTypes: cli.NewStringSlice(),
QClasses: cli.NewStringSlice(),
Nameservers: cli.NewStringSlice(),
},
2020-12-09 18:11:09 +01:00
}
return hub
}