doggo/cmd/hub.go

42 lines
990 B
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"
"github.com/mr-karan/doggo/pkg/resolve"
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
Resolver *resolve.Resolver
}
// 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-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
}