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-13 08:15:45 +01:00
|
|
|
cliContext *cli.Context
|
2020-12-10 17:14:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// QueryFlags is used store the value of CLI flags.
|
|
|
|
type QueryFlags struct {
|
2020-12-13 04:17:07 +01:00
|
|
|
QNames *cli.StringSlice
|
|
|
|
QTypes *cli.StringSlice
|
|
|
|
QClasses *cli.StringSlice
|
|
|
|
Nameservers *cli.StringSlice
|
|
|
|
IsDOH bool
|
|
|
|
IsDOT bool
|
|
|
|
IsUDP bool
|
|
|
|
UseTCP bool
|
|
|
|
UseIPv4 bool
|
|
|
|
UseIPv6 bool
|
|
|
|
DisplayTimeTaken bool
|
2020-12-13 05:04:53 +01:00
|
|
|
ShowJSON bool
|
2020-12-13 08:15:45 +01:00
|
|
|
Verbose bool
|
|
|
|
UseSearchList bool
|
|
|
|
Ndots int
|
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
|
|
|
|
}
|
2020-12-13 04:17:07 +01:00
|
|
|
|
|
|
|
// initLogger initializes logger
|
2020-12-13 08:15:45 +01:00
|
|
|
func initLogger() *logrus.Logger {
|
2020-12-13 04:17:07 +01:00
|
|
|
logger := logrus.New()
|
|
|
|
logger.SetFormatter(&logrus.TextFormatter{
|
|
|
|
DisableTimestamp: true,
|
|
|
|
DisableLevelTruncation: true,
|
|
|
|
})
|
|
|
|
return logger
|
|
|
|
}
|