Remove IDE-specific noise from source code.

This commit is contained in:
Eugene Bujak 2018-11-27 15:31:38 +03:00
parent 89753c4efb
commit 47e2a1004d
14 changed files with 4 additions and 52 deletions

4
app.go
View File

@ -263,7 +263,6 @@ func askUsernamePasswordIfPossible() error {
// Performs necessary upgrade operations if needed
func upgradeConfig() error {
if config.SchemaVersion == SchemaVersion {
// No upgrade, do nothing
return nil
@ -276,7 +275,6 @@ func upgradeConfig() error {
// Perform upgrade operations for each consecutive version upgrade
for oldVersion, newVersion := config.SchemaVersion, config.SchemaVersion+1; newVersion <= SchemaVersion; {
err := upgradeConfigSchema(oldVersion, newVersion)
if err != nil {
log.Fatal(err)
@ -295,7 +293,6 @@ func upgradeConfig() error {
// Upgrade from oldVersion to newVersion
func upgradeConfigSchema(oldVersion int, newVersion int) error {
if oldVersion == 0 && newVersion == 1 {
log.Printf("Updating schema from %d to %d", oldVersion, newVersion)
@ -303,7 +300,6 @@ func upgradeConfigSchema(oldVersion int, newVersion int) error {
// Added "ID" field to "filter" -- we need to populate this field now
// Added "config.ourDataDir" -- where we will now store filters contents
for i := range config.Filters {
filter := &config.Filters[i] // otherwise we will be operating on a copy
// Set the filter ID

View File

@ -121,7 +121,6 @@ var config = configuration{
// Creates a helper object for working with the user rules
func getUserFilter() filter {
// TODO: This should be calculated when UserRules are set
var contents []byte
for _, rule := range config.UserRules {

View File

@ -63,7 +63,6 @@ func httpUpdateConfigReloadDNSReturnOK(w http.ResponseWriter, r *http.Request) {
returnOK(w, r)
}
//noinspection GoUnusedParameter
func returnOK(w http.ResponseWriter, r *http.Request) {
_, err := fmt.Fprintf(w, "OK\n")
if err != nil {
@ -73,7 +72,6 @@ func returnOK(w http.ResponseWriter, r *http.Request) {
}
}
//noinspection GoUnusedParameter
func handleStatus(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{
"dns_address": config.BindHost,
@ -213,7 +211,6 @@ func handleTestUpstreamDNS(w http.ResponseWriter, r *http.Request) {
}
func checkDNS(input string) error {
u, err := upstream.NewUpstream(input, config.CoreDNS.BootstrapDNS)
if err != nil {
@ -234,7 +231,6 @@ func checkDNS(input string) error {
return nil
}
//noinspection GoUnusedParameter
func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) {
now := time.Now()
if now.Sub(versionCheckLastTime) <= versionCheckPeriod && len(versionCheckJSON) != 0 {
@ -290,7 +286,6 @@ func handleFilteringDisable(w http.ResponseWriter, r *http.Request) {
httpUpdateConfigReloadDNSReturnOK(w, r)
}
//noinspection GoUnusedParameter
func handleFilteringStatus(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{
"enabled": config.CoreDNS.FilteringEnabled,
@ -320,7 +315,6 @@ func handleFilteringStatus(w http.ResponseWriter, r *http.Request) {
}
func handleFilteringAddURL(w http.ResponseWriter, r *http.Request) {
filter := filter{}
err := json.NewDecoder(r.Body).Decode(&filter)
if err != nil {
@ -667,7 +661,6 @@ func (filter *filter) update(force bool) (bool, error) {
// saves filter contents to the file in config.ourDataDir
func (filter *filter) save() error {
filterFilePath := filter.getFilterFilePath()
log.Printf("Saving filter %d contents to: %s", filter.ID, filterFilePath)
@ -681,7 +674,6 @@ func (filter *filter) save() error {
// loads filter contents from the file in config.ourDataDir
func (filter *filter) load() error {
if !filter.Enabled {
// No need to load a filter that is not enabled
return nil
@ -729,7 +721,6 @@ func handleSafeBrowsingDisable(w http.ResponseWriter, r *http.Request) {
httpUpdateConfigReloadDNSReturnOK(w, r)
}
//noinspection GoUnusedParameter
func handleSafeBrowsingStatus(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{
"enabled": config.CoreDNS.SafeBrowsingEnabled,
@ -805,7 +796,6 @@ func handleParentalDisable(w http.ResponseWriter, r *http.Request) {
httpUpdateConfigReloadDNSReturnOK(w, r)
}
//noinspection GoUnusedParameter
func handleParentalStatus(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{
"enabled": config.CoreDNS.ParentalEnabled,
@ -845,7 +835,6 @@ func handleSafeSearchDisable(w http.ResponseWriter, r *http.Request) {
httpUpdateConfigReloadDNSReturnOK(w, r)
}
//noinspection GoUnusedParameter
func handleSafeSearchStatus(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{
"enabled": config.CoreDNS.SafeSearchEnabled,

View File

@ -161,7 +161,6 @@ func setupPlugin(c *caddy.Controller) (*plug, error) {
if err != nil {
return nil, err
}
//noinspection GoDeferInLoop
defer file.Close()
count := 0
@ -271,7 +270,6 @@ func (p *plug) onFinalShutdown() error {
type statsFunc func(ch interface{}, name string, text string, value float64, valueType prometheus.ValueType)
//noinspection GoUnusedParameter
func doDesc(ch interface{}, name string, text string, value float64, valueType prometheus.ValueType) {
realch, ok := ch.(chan<- *prometheus.Desc)
if !ok {

View File

@ -105,7 +105,6 @@ func logRequest(question *dns.Msg, answer *dns.Msg, result dnsfilter.Result, ela
}
}
//noinspection GoUnusedParameter
func HandleQueryLog(w http.ResponseWriter, r *http.Request) {
queryLogLock.RLock()
values := make([]*logEntry, len(queryLogCache))

View File

@ -61,7 +61,6 @@ func (p *plug) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
}
func (p *plug) allowRequest(ip string) (bool, error) {
if len(p.whitelist) > 0 {
i := sort.SearchStrings(p.whitelist, ip)
@ -114,7 +113,6 @@ type plug struct {
}
func setupPlugin(c *caddy.Controller) (*plug, error) {
p := &plug{ratelimit: defaultRatelimit}
for c.Next() {

View File

@ -36,7 +36,6 @@ func TestSetup(t *testing.T) {
}
func TestRatelimiting(t *testing.T) {
// rate limit is 1 per sec
c := caddy.NewTestController("dns", `ratelimit 1`)
p, err := setupPlugin(c)
@ -59,7 +58,6 @@ func TestRatelimiting(t *testing.T) {
}
func TestWhitelist(t *testing.T) {
// rate limit is 1 per sec
c := caddy.NewTestController("dns", `ratelimit 1 { whitelist 127.0.0.2 127.0.0.1 127.0.0.125 }`)
p, err := setupPlugin(c)

View File

@ -225,13 +225,10 @@ func (r *rulesTable) Add(rule *rule) {
if rule.ip != nil {
// Hosts syntax
r.rulesByHost[rule.text] = rule
} else if //noinspection GoBoolExpressions
len(rule.shortcut) == shortcutLength && enableFastLookup {
} else if len(rule.shortcut) == shortcutLength && enableFastLookup {
// Adblock syntax with a shortcut
r.rulesByShortcut[rule.shortcut] = append(r.rulesByShortcut[rule.shortcut], rule)
} else {
// Adblock syntax -- too short to have a shortcut
r.rulesLeftovers = append(r.rulesLeftovers, rule)
}
@ -239,7 +236,6 @@ func (r *rulesTable) Add(rule *rule) {
}
func (r *rulesTable) matchByHost(host string) (Result, error) {
// First: examine the hosts-syntax rules
res, err := r.searchByHost(host)
if err != nil {
@ -271,7 +267,6 @@ func (r *rulesTable) matchByHost(host string) (Result, error) {
}
func (r *rulesTable) searchByHost(host string) (Result, error) {
rule, ok := r.rulesByHost[host]
if ok {
@ -773,7 +768,6 @@ func (d *Dnsfilter) AddRule(input string, filterListID int64) error {
rule.extractShortcut()
//noinspection GoBoolExpressions
if !enableDelayedCompilation {
err := rule.compile()
if err != nil {

View File

@ -20,7 +20,6 @@ import (
// Writes data first to a temporary file and then renames it to what's specified in path
func writeFileSafe(path string, data []byte) error {
dir := filepath.Dir(path)
err := os.MkdirAll(dir, 0755)
if err != nil {

View File

@ -18,7 +18,6 @@ type DnsUpstream struct {
// NewDnsUpstream creates a new DNS upstream
func NewDnsUpstream(endpoint string, proto string, tlsServerName string) (Upstream, error) {
u := &DnsUpstream{
endpoint: endpoint,
timeout: defaultTimeout,
@ -42,7 +41,6 @@ func NewDnsUpstream(endpoint string, proto string, tlsServerName string) (Upstre
// Exchange provides an implementation for the Upstream interface
func (u *DnsUpstream) Exchange(ctx context.Context, query *dns.Msg) (*dns.Msg, error) {
resp, err := u.exchange(u.proto, query)
// Retry over TCP if response is truncated
@ -68,7 +66,6 @@ func (u *DnsUpstream) Exchange(ctx context.Context, query *dns.Msg) (*dns.Msg, e
// Clear resources
func (u *DnsUpstream) Close() error {
// Close active connections
u.transport.Stop()
return nil
@ -77,7 +74,6 @@ func (u *DnsUpstream) Close() error {
// Performs a synchronous query. It sends the message m via the conn
// c and waits for a reply. The conn c is not closed.
func (u *DnsUpstream) exchange(proto string, query *dns.Msg) (r *dns.Msg, err error) {
// Establish a connection if needed (or reuse cached)
conn, err := u.transport.Dial(proto)
if err != nil {

View File

@ -10,7 +10,6 @@ import (
// Detects the upstream type from the specified url and creates a proper Upstream object
func NewUpstream(url string, bootstrap string) (Upstream, error) {
proto := "udp"
prefix := ""
@ -64,7 +63,6 @@ func NewUpstream(url string, bootstrap string) (Upstream, error) {
}
func CreateResolver(bootstrap string) *net.Resolver {
bootstrapResolver := net.DefaultResolver
if bootstrap != "" {
@ -82,7 +80,6 @@ func CreateResolver(bootstrap string) *net.Resolver {
// Performs a simple health-check of the specified upstream
func IsAlive(u Upstream) (bool, error) {
// Using ipv4only.arpa. domain as it is a part of DNS64 RFC and it should exist everywhere
ping := new(dns.Msg)
ping.SetQuestion("ipv4only.arpa.", dns.TypeA)

View File

@ -17,7 +17,6 @@ func init() {
// Read the configuration and initialize upstreams
func setup(c *caddy.Controller) error {
p, err := setupPlugin(c)
if err != nil {
return err
@ -34,7 +33,6 @@ func setup(c *caddy.Controller) error {
// Read the configuration
func setupPlugin(c *caddy.Controller) (*UpstreamPlugin, error) {
p := New()
log.Println("Initializing the Upstream plugin")
@ -72,7 +70,6 @@ func setupPlugin(c *caddy.Controller) (*UpstreamPlugin, error) {
func (p *UpstreamPlugin) onShutdown() error {
for i := range p.Upstreams {
u := p.Upstreams[i]
err := u.Close()
if err != nil {

View File

@ -7,7 +7,6 @@ import (
)
func TestSetup(t *testing.T) {
var tests = []struct {
config string
}{

View File

@ -9,7 +9,6 @@ import (
)
func TestDnsUpstreamIsAlive(t *testing.T) {
var tests = []struct {
url string
bootstrap string
@ -32,7 +31,6 @@ func TestDnsUpstreamIsAlive(t *testing.T) {
}
func TestHttpsUpstreamIsAlive(t *testing.T) {
var tests = []struct {
url string
bootstrap string
@ -54,7 +52,6 @@ func TestHttpsUpstreamIsAlive(t *testing.T) {
}
func TestDnsOverTlsIsAlive(t *testing.T) {
var tests = []struct {
url string
bootstrap string
@ -77,7 +74,6 @@ func TestDnsOverTlsIsAlive(t *testing.T) {
}
func TestDnsUpstream(t *testing.T) {
var tests = []struct {
url string
bootstrap string
@ -100,7 +96,6 @@ func TestDnsUpstream(t *testing.T) {
}
func TestHttpsUpstream(t *testing.T) {
var tests = []struct {
url string
bootstrap string
@ -122,7 +117,6 @@ func TestHttpsUpstream(t *testing.T) {
}
func TestDnsOverTlsUpstream(t *testing.T) {
var tests = []struct {
url string
bootstrap string
@ -154,7 +148,6 @@ func testUpstreamIsAlive(t *testing.T, u Upstream) {
}
func testUpstream(t *testing.T, u Upstream) {
var tests = []struct {
name string
expected net.IP