doggo/cmd/hub.go

63 lines
1.6 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"
)
// 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
2020-12-13 17:00:54 +01:00
FreeArgs []string
2020-12-10 17:14:04 +01:00
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 {
2020-12-13 13:19:10 +01:00
QNames []string `koanf:"query"`
QTypes []string `koanf:"type"`
QClasses []string `koanf:"class"`
2020-12-13 17:00:54 +01:00
Nameservers []string `koanf:"nameserver"`
2020-12-13 13:19:10 +01:00
IsDOH bool `koanf:"doh"`
IsDOT bool `koanf:"dot"`
IsUDP bool `koanf:"udp"`
UseTCP bool `koanf:"tcp"`
UseIPv4 bool `koanf:"ipv4"`
UseIPv6 bool `koanf:"ipv6"`
DisplayTimeTaken bool `koanf:"time"`
ShowJSON bool `koanf:"json"`
UseSearchList bool `koanf:"search"`
Ndots int `koanf:"ndots"`
2020-12-13 16:33:44 +01:00
Color bool `koanf:"color"`
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{
2020-12-13 13:19:10 +01:00
QNames: []string{},
QTypes: []string{},
QClasses: []string{},
Nameservers: []string{},
2020-12-10 17:14:04 +01:00
},
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
}