Compare commits

..

11 Commits

Author SHA1 Message Date
Tyler ba0bffed6d We need gcc I guess...
continuous-integration/drone/push Build is passing Details
2021-04-15 01:10:13 -04:00
Tyler 30de693795 Fix go test line
continuous-integration/drone/push Build is failing Details
2021-04-15 01:09:34 -04:00
Tyler d8079551c9 Add testing, cleanup, rework suffix tree to use nameservers. Parse nameservers from yaml.
continuous-integration/drone/push Build is failing Details
2021-04-15 01:04:58 -04:00
Tyler b6efd0df0c API Implementation, patches
continuous-integration/drone/push Build is passing Details
2021-04-15 00:41:06 -04:00
Tyler e3958febc7 Resolve issue with Redis provider
continuous-integration/drone/push Build is passing Details
2021-04-15 00:00:36 -04:00
Tyler 2e0458ced5 Remove unnecessary manifest
continuous-integration/drone/push Build is failing Details
2021-04-14 23:44:56 -04:00
Tyler f38586dcb0 Add bolt provider, rewrite hosts, start of api, start of update via nsupdate 2021-04-14 23:42:24 -04:00
Tyler 3383c5e4f9 Changes to allow host "Set" to be standard, providers being able to use other query types, cache all responses, etc.
continuous-integration/drone/push Build is passing Details
2020-02-07 22:38:22 -05:00
Tyler f726a5d5ae Redo settings a bit, move a lot of init logic to main.go
continuous-integration/drone/push Build is passing Details
2020-01-25 13:48:26 -05:00
Tyler 991ae3ecb5 Resolve error, only trigger build on master
continuous-integration/drone/push Build is passing Details
2020-01-25 12:51:20 -05:00
Tyler 3122096982 Initial restructure of server
continuous-integration/drone/push Build is failing Details
2020-01-25 12:43:02 -05:00
36 changed files with 1889 additions and 1372 deletions

View File

@ -1,13 +1,29 @@
kind: pipeline
name: amd64
platform:
os: linux
arch: amd64
type: docker
steps:
- name: test
image: golang:alpine
volumes:
- name: build
path: /build
commands:
- apk --no-cache add git gcc musl-dev
- go test ./...
- name: build
image: golang:alpine
volumes:
- name: build
path: /build
commands:
- apk --no-cache add git gcc musl-dev
- go build -o /build/godns
- name: docker
image: plugins/docker
volumes:
- name: build
path: /build
settings:
username:
from_secret: docker_username
@ -17,27 +33,10 @@ steps:
registry: registry.meow.tf
tags:
- amd64-latest
when:
branch:
- master
---
kind: pipeline
name: manifest
steps:
- name: manifest
image: registry.meow.tf/docker/tools/manifest-tool:amd64-latest
environment:
DOCKER_USERNAME:
from_secret: docker_username
DOCKER_PASSWORD:
from_secret: docker_password
DOCKER_REGISTRY:
from_secret: docker_registry
commands:
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY
- /usr/bin/manifest-tool push from-spec manifest.yml
depends_on:
- amd64
image_pull_secrets:
- dockerconfigjson
volumes:
- name: build
temp: {}

View File

@ -1,9 +1,3 @@
FROM golang:alpine AS build-env
ADD . /src
RUN apk --no-cache add git gcc musl-dev
RUN cd /src && go get -d && go build -o godns
FROM alpine
MAINTAINER Tyler Stuyfzand <tyler@tystuyfzand.com>
@ -11,9 +5,10 @@ MAINTAINER Tyler Stuyfzand <tyler@tystuyfzand.com>
EXPOSE 53
RUN apk --no-cache add tini
ENTRYPOINT ["/sbin/tini", "-g", "--"]
CMD ["godns"]
COPY etc/godns.example.conf /etc/godns.conf
COPY --from=build-env /src/godns /usr/local/bin/godns
COPY /build/godns /usr/local/bin/godns
RUN chmod +x /usr/local/bin/godns
ENTRYPOINT ["/sbin/tini", "-g", "--"]
CMD ["godns"]

27
api/api.go Normal file
View File

@ -0,0 +1,27 @@
package api
import (
"github.com/go-chi/chi"
"github.com/go-chi/render"
"net/http"
)
func New() *API {
r := chi.NewRouter()
r.Use(render.SetContentType(render.ContentTypeJSON))
return &API{router: r}
}
type API struct {
router chi.Router
}
func (a *API) Router() chi.Router {
return a.router
}
func (a *API) Start() error {
return http.ListenAndServe(":8080", a.router)
}

View File

@ -1,10 +1,8 @@
package main
package cache
import (
"fmt"
"time"
"crypto/md5"
"github.com/miekg/dns"
)
@ -39,23 +37,11 @@ func (e SerializerError) Error() string {
return fmt.Sprintf("Serializer error: got %v", e.err)
}
type Mesg struct {
Msg *dns.Msg
Expire time.Time
}
type Cache interface {
Get(key string) (Msg *dns.Msg, err error)
Set(key string, Msg *dns.Msg) error
Exists(key string) bool
Remove(key string) error
Full() bool
}
func KeyGen(q Question) string {
h := md5.New()
h.Write([]byte(q.String()))
x := h.Sum(nil)
key := fmt.Sprintf("%x", x)
return key
Purge() error
}

View File

@ -1,4 +1,4 @@
package main
package cache
import (
"github.com/bradfitz/gomemcache/memcache"
@ -64,3 +64,7 @@ func (m *MemcachedCache) Full() bool {
// memcache is never full (LRU)
return false
}
func (m *MemcachedCache) Purge() error {
return m.backend.DeleteAll()
}

View File

@ -1,4 +1,4 @@
package main
package cache
import (
"github.com/miekg/dns"
@ -6,18 +6,35 @@ import (
"time"
)
func NewMemoryCache(expire time.Duration, maxCount int) *MemoryCache {
return &MemoryCache{
backend: make(map[string]Mesg),
Expire: expire,
Maxcount: maxCount,
}
}
type Mesg struct {
Msg *dns.Msg
Expire time.Time
}
type MemoryCache struct {
Cache
Backend map[string]Mesg
backend map[string]Mesg
Expire time.Duration
Maxcount int
mu sync.RWMutex
}
func (c *MemoryCache) initialize() {
c.backend = make(map[string]Mesg)
}
func (c *MemoryCache) Get(key string) (*dns.Msg, error) {
c.mu.RLock()
mesg, ok := c.Backend[key]
mesg, ok := c.backend[key]
c.mu.RUnlock()
if !ok {
return nil, KeyNotFound{key}
@ -40,21 +57,21 @@ func (c *MemoryCache) Set(key string, msg *dns.Msg) error {
expire := time.Now().Add(c.Expire)
mesg := Mesg{msg, expire}
c.mu.Lock()
c.Backend[key] = mesg
c.backend[key] = mesg
c.mu.Unlock()
return nil
}
func (c *MemoryCache) Remove(key string) error {
c.mu.Lock()
delete(c.Backend, key)
delete(c.backend, key)
c.mu.Unlock()
return nil
}
func (c *MemoryCache) Exists(key string) bool {
c.mu.RLock()
_, ok := c.Backend[key]
_, ok := c.backend[key]
c.mu.RUnlock()
return ok
}
@ -62,7 +79,7 @@ func (c *MemoryCache) Exists(key string) bool {
func (c *MemoryCache) Length() int {
c.mu.RLock()
defer c.mu.RUnlock()
return len(c.Backend)
return len(c.backend)
}
func (c *MemoryCache) Full() bool {
@ -72,3 +89,12 @@ func (c *MemoryCache) Full() bool {
}
return c.Length() >= c.Maxcount
}
func (c *MemoryCache) Purge() error {
c.mu.Lock()
defer c.mu.Unlock()
c.initialize()
return nil
}

View File

@ -1,12 +1,14 @@
package main
package cache
import (
"github.com/hoisie/redis"
"github.com/go-redis/redis/v7"
"github.com/miekg/dns"
"meow.tf/joker/godns/settings"
"time"
)
func NewRedisCache(c RedisSettings, expire int32) *RedisCache {
rc := &redis.Client{Addr: c.Addr(), Db: c.DB, Password: c.Password}
func NewRedisCache(c settings.RedisSettings, expire time.Duration) *RedisCache {
rc := redis.NewClient(&redis.Options{Addr: c.Addr(), DB: c.DB, Password: c.Password})
return &RedisCache{
backend: rc,
@ -18,13 +20,15 @@ type RedisCache struct {
Cache
backend *redis.Client
expire int32
expire time.Duration
}
func (m *RedisCache) Set(key string, msg *dns.Msg) error {
var val []byte
var err error
key = "cache:" + key
// handle cases for negacache where it sets nil values
if msg == nil {
val = []byte("nil")
@ -34,16 +38,21 @@ func (m *RedisCache) Set(key string, msg *dns.Msg) error {
if err != nil {
err = SerializerError{err}
}
return m.backend.Setex(key, int64(m.expire), val)
return m.backend.Set(key, val, m.expire).Err()
}
func (m *RedisCache) Get(key string) (*dns.Msg, error) {
var msg dns.Msg
item, err := m.backend.Get(key)
var err error
key = "cache:" + key
item, err := m.backend.Get(key).Bytes()
if err != nil {
err = KeyNotFound{key}
return &msg, err
}
err = msg.Unpack(item)
if err != nil {
err = SerializerError{err}
@ -52,19 +61,40 @@ func (m *RedisCache) Get(key string) (*dns.Msg, error) {
}
func (m *RedisCache) Exists(key string) bool {
exists, err := m.backend.Exists(key)
res, err := m.backend.Exists(key).Result()
if err != nil {
return true
}
return exists
return res == 1
}
func (m *RedisCache) Remove(key string) error {
_, err := m.backend.Del(key)
return err
return m.backend.Del(key).Err()
}
func (m *RedisCache) Full() bool {
// redis is never full (LRU)
return false
}
func (m *RedisCache) Purge() error {
iter := m.backend.Scan(0, "cache:*", 0).Iterator()
if iter.Err() != nil {
return iter.Err()
}
var err error
for iter.Next() {
err = m.backend.Del(iter.Val()).Err()
if err != nil {
return err
}
}
return nil
}

View File

@ -1,46 +0,0 @@
server=/adcdownload.apple.com/114.114.114.114
server=/appldnld.apple.com/114.114.114.114
server=/cdn-cn1.apple-mapkit.com/114.114.114.114
server=/cdn-cn2.apple-mapkit.com/114.114.114.114
server=/cdn-cn3.apple-mapkit.com/114.114.114.114
server=/cdn-cn4.apple-mapkit.com/114.114.114.114
server=/cdn.apple-mapkit.com/114.114.114.114
server=/cdn1.apple-mapkit.com/114.114.114.114
server=/cdn2.apple-mapkit.com/114.114.114.114
server=/cdn3.apple-mapkit.com/114.114.114.114
server=/cdn4.apple-mapkit.com/114.114.114.114
server=/cds.apple.com/114.114.114.114
server=/cl1.apple.com/114.114.114.114
server=/cl2.apple.com.edgekey.net.globalredir.akadns.net/114.114.114.114
server=/cl2.apple.com.edgekey.net/114.114.114.114
server=/cl2.apple.com/114.114.114.114
server=/cl3.apple.com/114.114.114.114
server=/cl4.apple.com/114.114.114.114
server=/cl5.apple.com/114.114.114.114
server=/gsp11-cn.ls.apple.com/114.114.114.114
server=/gsp12-cn.ls.apple.com/114.114.114.114
server=/gsp13-cn.ls.apple.com/114.114.114.114
server=/gsp4-cn.ls.apple.com.edgekey.net.globalredir.akadns.net/114.114.114.114
server=/gsp4-cn.ls.apple.com.edgekey.net/114.114.114.114
server=/gsp4-cn.ls.apple.com/114.114.114.114
server=/gsp5-cn.ls.apple.com/114.114.114.114
server=/gspe19-cn.ls-apple.com.akadns.net/114.114.114.114
server=/gspe19-cn.ls.apple.com/114.114.114.114
server=/gspe21.ls.apple.com/114.114.114.114
server=/gspe21-ssl.ls.apple.com/114.114.114.114
server=/gspe35-ssl.ls.apple.com/114.114.114.114
server=/icloud.cdn-apple.com/114.114.114.114
server=/images.apple.com/114.114.114.114
server=/itunes-apple.com.akadns.net/114.114.114.114
server=/itunes.apple.com/114.114.114.114
server=/itunesconnect.apple.com/114.114.114.114
server=/mesu.apple.com/114.114.114.114
server=/mesu-china.apple.com.akadns.net/114.114.114.114
server=/phobos-apple.com.akadns.net/114.114.114.114
server=/phobos.apple.com/114.114.114.114
server=/store.apple.com/114.114.114.114
server=/store.storeimages.cdn-apple.com/114.114.114.114
server=/support.apple.com/114.114.114.114
server=/swcdn.apple.com/114.114.114.114
server=/swdist.apple.com/114.114.114.114
server=/www.apple.com/114.114.114.114

View File

@ -1,58 +1,48 @@
#Toml config file
Title = "GODNS"
Version = "0.2.0"
Author = "kenshin, tystuyfzand"
Debug = false
debug = false
[server]
host = "0.0.0.0"
port = 53
nets = ["tcp:53", "udp:53"]
[resolv]
# Domain-specific nameservers configuration, formatting keep compatible with Dnsmasq
# Semicolon separate multiple files.
resolv-file = ""
file = ""
timeout = 5 # 5 seconds
# The concurrency interval request upstream recursive server
# Match the PR15, https://github.com/kenshinx/godns/pull/15
interval = 200 # 200 milliseconds
setedns0 = false #Support for larger UDP DNS responses
server-list-file = "etc/serverlist.conf"
[redis]
enable = true
host = "192.168.1.71"
port = 6379
db = 0
password =""
[memcache]
servers = ["127.0.0.1:11211"]
edns0 = false #Support for larger UDP DNS responses
# Domain-specific nameservers configuration, formatting keep compatible with Dnsmasq
server-list = "etc/serverlist.conf"
[log]
stdout = true
file = "./godns.log"
level = "DEBUG" #DEBUG | INFO |NOTICE | WARN | ERROR
[cache]
# backend option [memory|memcache|redis]
# redis backend not implemented yet
backend = "memory"
expire = 600 # 10 minutes
maxcount = 0 #If set zero. The Sum of cache itmes will be unlimit.
[cache.memcached]
servers = ["127.0.0.1:11211"]
# Redis cache backend config
[cache.redis]
host = "127.0.0.1"
port = 6379
db = 0
password =""
[hosts]
#If set false, will not query hosts file and redis hosts record
enable = true
host-file = "/etc/hosts"
redis-enable = true
redis-key = "godns:hosts"
ttl = 600
refresh-interval = 60 # 5 seconds
# File provider, supports inotify hot-reload
[hosts.file]
enable = true
file = "/etc/hosts"
ttl = 600
# Redis provider
[hosts.redis]
enable = true
key = "godns:hosts"
ttl = 600

View File

@ -1,56 +0,0 @@
#Toml config file
title = "GODNS"
Version = "0.2.3"
Author = "kenshin, tystuyfzand"
debug = false
[server]
host = ""
port = 53
[resolv]
# Domain-specific nameservers configuration, formatting keep compatible with Dnsmasq
# Semicolon separate multiple files.
resolv-file = "/etc/resolv.conf"
timeout = 5 # 5 seconds
# The concurrency interval request upstream recursive server
# Match the PR15, https://github.com/kenshinx/godns/pull/15
interval = 200 # 200 milliseconds
# When defined, this is preferred over regular DNS. This requires a resolver to be active besides this, only for the initial lookup.
# A hosts file entry will suffice as well.
# dns-over-https = "https://cloudflare-dns.com/dns-query"
setedns0 = false #Support for larger UDP DNS responses
[redis]
enable = true
host = "127.0.0.1"
port = 6379
db = 0
password =""
[memcache]
servers = ["127.0.0.1:11211"]
[log]
stdout = true
file = "./godns.log"
level = "INFO" #DEBUG | INFO |NOTICE | WARN | ERROR
[cache]
# backend option [memory|memcache|redis]
backend = "memory"
expire = 600 # 10 minutes
maxcount = 0 #If set zero. The Sum of cache items will be unlimit.
[hosts]
#If set false, will not query hosts file and redis hosts record
enable = true
host-file = "/etc/hosts"
redis-enable = false
redis-key = "godns:hosts"
ttl = 600
# Refresh interval can be high since we have automatic updating via push and fsnotify
refresh-interval = 300

View File

@ -1,42 +0,0 @@
server=/265.com/114.114.114.114
server=/2mdn.net/114.114.114.114
server=/app-measurement.com/114.114.114.114
server=/beacons.gcp.gvt2.com/114.114.114.114
server=/beacons.gvt2.com/114.114.114.114
server=/beacons3.gvt2.com/114.114.114.114
server=/c.admob.com/114.114.114.114
server=/c.android.clients.google.com/114.114.114.114
server=/cache.pack.google.com/114.114.114.114
server=/clientservices.googleapis.com/114.114.114.114
server=/connectivitycheck.gstatic.com/114.114.114.114
server=/csi.gstatic.com/114.114.114.114
server=/dl.google.com/114.114.114.114
server=/doubleclick.net/114.114.114.114
server=/e.admob.com/114.114.114.114
server=/fonts.googleapis.com/114.114.114.114
server=/fonts.gstatic.com/114.114.114.114
server=/google-analytics.com/114.114.114.114
server=/googleadservices.com/114.114.114.114
server=/googleanalytics.com/114.114.114.114
server=/googlesyndication.com/114.114.114.114
server=/googletagmanager.com/114.114.114.114
server=/googletagservices.com/114.114.114.114
server=/imasdk.googleapis.com/114.114.114.114
server=/kh.google.com/114.114.114.114
server=/khm.google.com/114.114.114.114
server=/khm.googleapis.com/114.114.114.114
server=/khm0.google.com/114.114.114.114
server=/khm0.googleapis.com/114.114.114.114
server=/khm1.google.com/114.114.114.114
server=/khm1.googleapis.com/114.114.114.114
server=/khm2.google.com/114.114.114.114
server=/khm2.googleapis.com/114.114.114.114
server=/khm3.google.com/114.114.114.114
server=/khm3.googleapis.com/114.114.114.114
server=/khmdb.google.com/114.114.114.114
server=/khmdb.googleapis.com/114.114.114.114
server=/media.admob.com/114.114.114.114
server=/mediavisor.doubleclick.com/114.114.114.114
server=/redirector.gvt1.com/114.114.114.114
server=/toolbarqueries.google.com/114.114.114.114
server=/update.googleapis.com/114.114.114.114

28
go.mod
View File

@ -1,24 +1,18 @@
module godns
module meow.tf/joker/godns
go 1.12
go 1.16
require (
github.com/BurntSushi/toml v0.3.1
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b
github.com/caarlos0/env v3.5.0+incompatible
github.com/fsnotify/fsnotify v1.4.7
github.com/gopherjs/gopherjs v0.0.0-20190915194858-d3ddacdb130f // indirect
github.com/hoisie/redis v0.0.0-20160730154456-b5c6e81454e0
github.com/miekg/dns v1.1.18
github.com/go-chi/chi v1.5.4
github.com/go-chi/render v1.0.1
github.com/go-redis/redis/v7 v7.0.0-beta.5
github.com/miekg/dns v1.1.41
github.com/ryanuber/go-glob v1.0.0
github.com/smartystreets/assertions v1.0.1 // indirect
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.4.0 // indirect
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 // indirect
golang.org/x/net v0.0.0-20190926025831-c00fd9afed17 // indirect
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe // indirect
golang.org/x/tools v0.0.0-20190925230517-ea99b82c7b93 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
github.com/sirupsen/logrus v1.2.0
github.com/smartystreets/goconvey v1.6.4
github.com/spf13/viper v1.7.1
go.etcd.io/bbolt v1.3.5
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
)

344
go.sum Normal file
View File

@ -0,0 +1,344 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY=
cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc=
cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0=
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk=
cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b h1:L/QXpzIa3pOvUGt1D1lA5KjYhPBAN/3iWdP7xeFS9F0=
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-chi/chi v1.5.4 h1:QHdzF2szwjqVV4wmByUnTcsbIg7UGaQ0tPF2t5GcAIs=
github.com/go-chi/chi v1.5.4/go.mod h1:uaf8YgoFazUOkPBG7fxPftUylNumIev9awIWOENIuEg=
github.com/go-chi/render v1.0.1 h1:4/5tis2cKaNdnv9zFLfXzcquC9HbeZgCnxGnKrltBS8=
github.com/go-chi/render v1.0.1/go.mod h1:pq4Rr7HbnsdaeHagklXub+p6Wd16Af5l9koip1OvJns=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-redis/redis/v7 v7.0.0-beta.5 h1:7bdbDkv2nKZm6Tydrvmay3xOvVaxpAT4ZsNTrSDMZUE=
github.com/go-redis/redis/v7 v7.0.0-beta.5/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY=
github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.1 h1:q/mM8GF/n0shIN8SaAZ0V+jnLPzen6WIVZdiwrRlMlo=
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk=
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.7.1 h1:pM5oEahlgWv/WnHXpgbKz7iLIxRf65tye2Ci+XFK5sk=
github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek=
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04 h1:cEhElsAv9LUt9ZUUocxzWe05oFLVd+AA2nstydTeI8g=
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8=
google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=

View File

@ -1,209 +1,252 @@
package main
import (
"crypto/md5"
"fmt"
"github.com/miekg/dns"
log "github.com/sirupsen/logrus"
"meow.tf/joker/godns/cache"
"meow.tf/joker/godns/hosts"
"meow.tf/joker/godns/resolver"
"meow.tf/joker/godns/utils"
"net"
"time"
"github.com/miekg/dns"
)
const (
notIPQuery = 0
_IP4Query = 4
_IP6Query = 6
)
type Question struct {
qname string
qtype string
qclass string
type Handler struct {
resolver *resolver.Resolver
middleware []MiddlewareFunc
cache, negCache cache.Cache
hosts *hosts.ProviderList
}
func (q *Question) String() string {
return q.qname + " " + q.qclass + " " + q.qtype
}
type MiddlewareFunc func(w dns.ResponseWriter, r *dns.Msg, m *dns.Msg) *dns.Msg
type GODNSHandler struct {
resolver *Resolver
cache, negCache Cache
hosts Hosts
}
func NewHandler() *GODNSHandler {
var (
cacheConfig CacheSettings
resolver *Resolver
cache, negCache Cache
)
resolver = NewResolver(settings.ResolvConfig)
cacheConfig = settings.Cache
switch cacheConfig.Backend {
case "memory":
cache = &MemoryCache{
Backend: make(map[string]Mesg, cacheConfig.Maxcount),
Expire: time.Duration(cacheConfig.Expire) * time.Second,
Maxcount: cacheConfig.Maxcount,
func TsigMiddleware(secretKey string) MiddlewareFunc {
return func(w dns.ResponseWriter, r *dns.Msg, m *dns.Msg) *dns.Msg {
if r.IsTsig() != nil {
if w.TsigStatus() == nil {
m.SetTsig(r.Extra[len(r.Extra)-1].(*dns.TSIG).Hdr.Name, dns.HmacSHA256, 300, time.Now().Unix())
}
}
negCache = &MemoryCache{
Backend: make(map[string]Mesg),
Expire: time.Duration(cacheConfig.Expire) * time.Second / 2,
Maxcount: cacheConfig.Maxcount,
return m
}
}
func NewHandler(r *resolver.Resolver, resolverCache, negCache cache.Cache, h *hosts.ProviderList) *Handler {
return &Handler{r, make([]MiddlewareFunc, 0), resolverCache, negCache, h}
}
func (h *Handler) Use(f MiddlewareFunc) *Handler {
h.middleware = append(h.middleware, f)
return h
}
// do handles a dns request.
// network will decide which network type it is (udp, tcp, https, etc)
func (h *Handler) do(network string, w dns.ResponseWriter, req *dns.Msg) {
switch req.Opcode {
case dns.OpcodeQuery:
h.query(network, w, req)
case dns.OpcodeUpdate:
if req.IsTsig() == nil {
m := new(dns.Msg)
m.SetRcode(req, dns.RcodeBadSig)
w.WriteMsg(m)
return
}
case "memcache":
cache = NewMemcachedCache(
settings.Memcache.Servers,
int32(cacheConfig.Expire))
negCache = NewMemcachedCache(
settings.Memcache.Servers,
int32(cacheConfig.Expire/2))
case "redis":
cache = NewRedisCache(
settings.Redis,
int32(cacheConfig.Expire))
negCache = NewRedisCache(
settings.Redis,
int32(cacheConfig.Expire/2))
default:
logger.Error("Invalid cache backend %s", cacheConfig.Backend)
panic("Invalid cache backend")
packed, err := req.Pack()
if err != nil {
m := new(dns.Msg)
m.SetRcode(req, dns.RcodeBadSig)
w.WriteMsg(m)
return
}
if err := dns.TsigVerify(packed, "", "", false); err != nil {
m := new(dns.Msg)
m.SetRcode(req, dns.RcodeBadSig)
w.WriteMsg(m)
return
}
h.update(network, w, req)
}
}
// writeMsg writes a *dns.Msg after passing it through middleware.
func (h *Handler) writeMsg(w dns.ResponseWriter, r *dns.Msg, m *dns.Msg) {
for _, f := range h.middleware {
m = f(w, r, m)
}
var hosts Hosts
if settings.Hosts.Enable {
hosts = NewHosts(settings.Hosts, settings.Redis)
}
return &GODNSHandler{resolver, cache, negCache, hosts}
w.WriteMsg(m)
}
func (h *GODNSHandler) do(Net string, w dns.ResponseWriter, req *dns.Msg) {
// query handles dns queries.
func (h *Handler) query(network string, w dns.ResponseWriter, req *dns.Msg) {
q := req.Question[0]
Q := Question{UnFqdn(q.Name), dns.TypeToString[q.Qtype], dns.ClassToString[q.Qclass]}
question := resolver.Question{Name: utils.UnFqdn(q.Name), Type: q.Qtype, Class: dns.ClassToString[q.Qclass]}
var remote net.IP
if Net == "tcp" {
remote = w.RemoteAddr().(*net.TCPAddr).IP
} else {
remote = w.RemoteAddr().(*net.UDPAddr).IP
}
logger.Info("%s lookup %s", remote, Q.String())
IPQuery := h.isIPQuery(q)
switch t := w.RemoteAddr().(type) {
case *net.TCPAddr:
remote = t.IP
case *net.UDPAddr:
remote = t.IP
default:
return
}
log.WithFields(log.Fields{
"remote": remote,
"question": question.String(),
}).Debug("Lookup question")
key := KeyGen(question)
// Check cache first
mesg, err := h.cache.Get(key)
if err != nil {
if mesg, err = h.negCache.Get(key); err != nil {
log.WithField("question", question.String()).Debug("no negative cache hit")
} else {
log.WithField("question", question.String()).Debug("negative cache hit")
m := new(dns.Msg)
m.SetRcode(req, dns.RcodeServerFailure)
w.WriteMsg(m)
return
}
} else {
log.WithField("question", question.String()).Debug("hit cache")
// we need this copy against concurrent modification of Id
msg := *mesg
msg.Id = req.Id
h.writeMsg(w, req, &msg)
return
}
// Query hosts
if settings.Hosts.Enable && IPQuery > 0 {
if ips, ok := h.hosts.Get(Q.qname, IPQuery); ok {
if h.hosts != nil {
if host, err := h.hosts.Get(question.Type, question.Name); err == nil {
m := new(dns.Msg)
m.SetReply(req)
switch IPQuery {
case _IP4Query:
rr_header := dns.RR_Header{
Name: q.Name,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: settings.Hosts.TTL,
}
for _, ip := range ips {
a := &dns.A{rr_header, ip}
m.Answer = append(m.Answer, a)
}
case _IP6Query:
rr_header := dns.RR_Header{
Name: q.Name,
Rrtype: dns.TypeAAAA,
Class: dns.ClassINET,
Ttl: settings.Hosts.TTL,
}
for _, ip := range ips {
aaaa := &dns.AAAA{rr_header, ip}
m.Answer = append(m.Answer, aaaa)
}
hdr := dns.RR_Header{
Name: q.Name,
Rrtype: question.Type,
Class: dns.ClassINET,
Ttl: uint32(host.TTL / time.Second),
}
w.WriteMsg(m)
logger.Debug("%s found in hosts file", Q.qname)
switch question.Type {
case dns.TypeA:
for _, val := range host.Values {
m.Answer = append(m.Answer, &dns.A{Hdr: hdr, A: net.ParseIP(val).To4()})
}
case dns.TypeAAAA:
for _, val := range host.Values {
m.Answer = append(m.Answer, &dns.AAAA{Hdr: hdr, AAAA: net.ParseIP(val).To16()})
}
case dns.TypeCNAME:
for _, val := range host.Values {
m.Answer = append(m.Answer, &dns.CNAME{Hdr: hdr, Target: val})
}
case dns.TypeTXT:
m.Answer = append(m.Answer, &dns.TXT{Hdr: hdr, Txt: host.Values})
}
// Insert into cache before using any middleware
err = h.cache.Set(key, m)
if err != nil {
log.WithError(err).Error("Unable to insert hosts entry into cache")
}
// Write the message
h.writeMsg(w, req, m)
log.WithField("question", question.Name).Debug("Found entry in hosts file")
return
} else {
logger.Debug("%s didn't found in hosts file", Q.qname)
log.WithField("question", question.Name).Debug("No entry found in hosts file")
}
}
// Only query cache when qtype == 'A'|'AAAA' , qclass == 'IN'
key := KeyGen(Q)
if IPQuery > 0 {
mesg, err := h.cache.Get(key)
if err != nil {
if mesg, err = h.negCache.Get(key); err != nil {
logger.Debug("%s didn't hit cache", Q.String())
} else {
logger.Debug("%s hit negative cache", Q.String())
dns.HandleFailed(w, req)
return
}
} else {
logger.Debug("%s hit cache", Q.String())
// we need this copy against concurrent modification of Id
msg := *mesg
msg.Id = req.Id
w.WriteMsg(&msg)
return
}
}
mesg, err := h.resolver.Lookup(Net, req)
mesg, err = h.resolver.Lookup(network, req)
if err != nil {
logger.Warn("Resolve query error %s", err)
dns.HandleFailed(w, req)
log.WithError(err).Warn("Query resolution error")
m := new(dns.Msg)
m.SetRcode(req, dns.RcodeServerFailure)
w.WriteMsg(m)
// cache the failure, too!
if err = h.negCache.Set(key, nil); err != nil {
logger.Warn("Set %s negative cache failed: %v", Q.String(), err)
log.WithError(err).Warn("Negative cache save failed")
}
return
}
w.WriteMsg(mesg)
if IPQuery > 0 && len(mesg.Answer) > 0 {
// Cache if mesg.Answer length > 0
// This is done BEFORE sending it so we don't modify the request first
if len(mesg.Answer) > 0 {
err = h.cache.Set(key, mesg)
if err != nil {
logger.Warn("Set %s cache failed: %s", Q.String(), err.Error())
fields := log.Fields{
"question": question.String(),
}
log.WithFields(fields).Debug("Insert record into cache")
if err != nil {
fields["error"] = err
log.WithFields(fields).Warn("Unable to add to cache")
}
}
// Write message
h.writeMsg(w, req, mesg)
}
func (h *Handler) update(network string, w dns.ResponseWriter, req *dns.Msg) {
for _, question := range req.Question {
if _, ok := dns.IsDomainName(question.Name); !ok {
continue
}
for _, rr := range req.Ns {
hdr := rr.Header()
if hdr.Class == dns.ClassANY && hdr.Rdlength == 0 {
// Delete record
continue
}
}
logger.Debug("Insert %s into cache", Q.String())
}
}
func (h *GODNSHandler) DoTCP(w dns.ResponseWriter, req *dns.Msg) {
h.do("tcp", w, req)
}
func (h *GODNSHandler) DoUDP(w dns.ResponseWriter, req *dns.Msg) {
h.do("udp", w, req)
}
func (h *GODNSHandler) isIPQuery(q dns.Question) int {
if q.Qclass != dns.ClassINET {
return notIPQuery
}
switch q.Qtype {
case dns.TypeA:
return _IP4Query
case dns.TypeAAAA:
return _IP6Query
default:
return notIPQuery
func (h *Handler) Bind(net string) func(w dns.ResponseWriter, req *dns.Msg) {
return func(w dns.ResponseWriter, req *dns.Msg) {
h.do(net, w, req)
}
}
func UnFqdn(s string) string {
if dns.IsFqdn(s) {
return s[:len(s)-1]
}
return s
func KeyGen(q resolver.Question) string {
h := md5.New()
h.Write([]byte(q.String()))
x := h.Sum(nil)
key := fmt.Sprintf("%x", x)
return key
}

View File

@ -1,93 +0,0 @@
package main
import (
"net"
"time"
"github.com/hoisie/redis"
)
type Hosts struct {
providers []HostProvider
refreshInterval time.Duration
}
type HostProvider interface {
Get(domain string) ([]string, bool)
Refresh()
}
func NewHosts(hs HostsSettings, rs RedisSettings) Hosts {
providers := []HostProvider{
NewFileProvider(hs.HostsFile),
}
if hs.RedisEnable {
logger.Info("Redis is enabled: %s", rs.Addr())
rc := &redis.Client{Addr: rs.Addr(), Db: rs.DB, Password: rs.Password}
providers = append(providers, NewRedisProvider(rc, hs.RedisKey))
}
h := Hosts{providers, time.Second * time.Duration(hs.RefreshInterval)}
if h.refreshInterval > 0 {
h.refresh()
}
return h
}
func (h *Hosts) refresh() {
ticker := time.NewTicker(h.refreshInterval)
go func() {
for {
// Force a refresh every refreshInterval
for _, provider := range h.providers {
provider.Refresh()
}
<-ticker.C
}
}()
}
/*
Match local /etc/hosts file first, remote redis records second
*/
func (h *Hosts) Get(domain string, family int) ([]net.IP, bool) {
var sips []string
var ok bool
var ip net.IP
var ips []net.IP
for _, provider := range h.providers {
sips, ok = provider.Get(domain)
if ok {
break
}
}
if sips == nil {
return nil, false
}
for _, sip := range sips {
switch family {
case _IP4Query:
ip = net.ParseIP(sip).To4()
case _IP6Query:
ip = net.ParseIP(sip).To16()
default:
continue
}
if ip != nil {
ips = append(ips, ip)
}
}
return ips, ips != nil
}

118
hosts/hosts.go Normal file
View File

@ -0,0 +1,118 @@
package hosts
import (
"github.com/miekg/dns"
"time"
)
type HostMap map[string][]Host
type Host struct {
Type uint16 `json:"type"`
TTL time.Duration `json:"ttl"`
Values []string `json:"values"`
}
func (h *Host) TypeString() string {
return dns.TypeToString[h.Type]
}
type ProviderList struct {
providers []Provider
}
// Provider is an interface specifying a host source
// Each source should support AT LEAST List and Get, but can support Writer as well
type Provider interface {
List() (HostMap, error)
Get(queryType uint16, domain string) (*Host, error)
}
// Writer is an interface to modify hosts.
// Examples of this include Redis, Bolt, MySQL, etc.
type Writer interface {
Set(domain string, host *Host) error
Delete(domain string) error
}
type ProviderWriter interface {
Provider
Writer
}
func NewHosts(providers []Provider) *ProviderList {
return &ProviderList{providers}
}
// List returns all results, merged into one HostMap
func (h *ProviderList) List() (HostMap, error) {
hostMap := make(HostMap)
for _, provider := range h.providers {
hosts, err := provider.List()
if err != nil {
continue
}
for k, v := range hosts {
if existing, ok := hostMap[k]; ok {
existing = append(existing, v...)
hostMap[k] = existing
} else {
hostMap[k] = v
}
}
}
return hostMap, nil
}
// Get Matches values to providers, loping each in order
func (h *ProviderList) Get(queryType uint16, domain string) (*Host, error) {
var host *Host
var err error
for _, provider := range h.providers {
host, err = provider.Get(queryType, domain)
if host != nil {
break
}
}
return host, err
}
// Set invokes each provider, setting the host on the first one to return a nil error
func (h *ProviderList) Set(domain string, host *Host) (err error) {
for _, provider := range h.providers {
if writer, ok := provider.(Writer); ok {
err = writer.Set(domain, host)
if err == nil {
return
}
}
}
err = errUnsupportedOperation
return
}
// Delete invokes each provider, removing the host on the first one to return a nil error
func (h *ProviderList) Delete(domain string) (err error) {
for _, provider := range h.providers {
if writer, ok := provider.(Writer); ok {
err = writer.Delete(domain)
if err == nil {
return
}
}
}
err = errUnsupportedOperation
return
}

140
hosts/hosts_api.go Normal file
View File

@ -0,0 +1,140 @@
package hosts
import (
"github.com/go-chi/chi"
"github.com/go-chi/render"
"github.com/miekg/dns"
"net/http"
"time"
)
const (
defaultDuration = 600 * time.Second
)
func EnableAPI(h Provider, r chi.Router) {
a := &api{hosts: h}
r.Route("/hosts", func(sub chi.Router) {
sub.Get("/", a.hostsGet)
sub.Post("/", a.hostsCreate)
sub.Patch("/{domain}", a.hostsUpdate)
sub.Delete("/{domain}", a.hostsDelete)
})
}
type api struct {
hosts Provider
}
// hostsGet handles GET requests on /hosts (list records)
func (a *api) hostsGet(w http.ResponseWriter, r *http.Request) {
hosts, err := a.hosts.List()
if err != nil {
return
}
render.JSON(w, r, hosts)
}
type requestBody struct {
Domain string `json:"domain"`
Type string `json:"type"`
Values []string `json:"values"`
TTL int `json:"ttl"`
}
func (b requestBody) TTLDuration() time.Duration {
if b.TTL > 0 {
return time.Duration(b.TTL) * time.Second
}
return defaultDuration
}
// hostsUpdate handles POST requests on /hosts
func (a *api) hostsCreate(w http.ResponseWriter, r *http.Request) {
var writer Writer
var ok bool
if writer, ok = a.hosts.(Writer); !ok {
w.WriteHeader(http.StatusNotImplemented)
return
}
var request requestBody
err := render.DefaultDecoder(r, &request)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
var recordType uint16
if recordType, ok = dns.StringToType[request.Type]; !ok {
w.WriteHeader(http.StatusBadRequest)
return
}
err = writer.Set(request.Domain, &Host{
Type: recordType,
Values: request.Values,
TTL: request.TTLDuration(),
})
if err != nil {
}
}
// hostsUpdate handles PATCH requests on /hosts/:domain
func (a *api) hostsUpdate(w http.ResponseWriter, r *http.Request) {
domain := chi.URLParam(r, "domain")
if domain == "" {
w.WriteHeader(http.StatusBadRequest)
return
}
var writer Writer
var ok bool
if writer, ok = a.hosts.(Writer); !ok {
w.WriteHeader(http.StatusNotImplemented)
return
}
// TODO: Read record from provider, update data from body, save
err := writer.Set(domain, nil)
if err != nil {
}
}
// hostsDelete handles DELETE requests on /hosts/:domain
func (a *api) hostsDelete(w http.ResponseWriter, r *http.Request) {
domain := chi.URLParam(r, "domain")
if domain == "" {
w.WriteHeader(http.StatusBadRequest)
return
}
var writer Writer
var ok bool
if writer, ok = a.hosts.(Writer); !ok {
w.WriteHeader(http.StatusNotImplemented)
return
}
err := writer.Delete(domain)
if err != nil {
}
}

153
hosts/hosts_bolt.go Normal file
View File

@ -0,0 +1,153 @@
package hosts
import (
"encoding/json"
"github.com/miekg/dns"
log "github.com/sirupsen/logrus"
bolt "go.etcd.io/bbolt"
"strings"
)
const (
recordBucket = "records"
)
type BoltHosts struct {
Provider
db *bolt.DB
}
func NewBoltProvider(file string) Provider {
db, err := bolt.Open(file, 0600, &bolt.Options{})
if err != nil {
log.WithError(err).Fatalln("Unable to open database")
}
err = db.Update(func(tx *bolt.Tx) error {
_, err := tx.CreateBucketIfNotExists([]byte(recordBucket))
if err != nil {
return err
}
return nil
})
return &BoltHosts{
db: db,
}
}
func (b *BoltHosts) List() (HostMap, error) {
hosts := make(HostMap)
err := b.db.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("records"))
c := b.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
var domainRecords []Host
if err := json.Unmarshal(v, &domainRecords); err != nil {
continue
}
hosts[string(k)] = domainRecords
}
return nil
})
if err != nil {
return nil, err
}
return hosts, nil
}
func (b *BoltHosts) Get(queryType uint16, domain string) (*Host, error) {
log.WithFields(log.Fields{
"queryType": dns.TypeToString[queryType],
"question": domain,
}).Debug("Checking bolt provider")
domain = strings.ToLower(domain)
var err error
var v []byte
err = b.db.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("records"))
v = b.Get([]byte(domain))
if string(v) != "" {
return nil
}
v = b.Get([]byte("*." + domain))
if string(v) != "" {
return nil
}
return errRecordNotFound
})
if err != nil {
return nil, err
}
var h []Host
if err = json.Unmarshal(v, &h); err != nil {
return nil, err
}
for _, host := range h {
if host.Type == queryType {
return &host, nil
}
}
return nil, errRecordNotFound
}
func (b *BoltHosts) Set(domain string, host *Host) error {
err := b.db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(recordBucket))
hosts := []*Host{host}
existing := b.Get([]byte(domain))
if existing != nil {
err := json.Unmarshal(existing, &hosts)
if err != nil {
return err
}
hosts = append(hosts, host)
}
hostBytes, err := json.Marshal(hosts)
if err != nil {
return err
}
err = b.Put([]byte(domain), hostBytes)
if err != nil {
return err
}
return nil
})
return err
}

View File

@ -1,27 +1,40 @@
package main
package hosts
import (
"bufio"
"errors"
"github.com/fsnotify/fsnotify"
"github.com/miekg/dns"
"github.com/ryanuber/go-glob"
log "github.com/sirupsen/logrus"
"meow.tf/joker/godns/utils"
"os"
"regexp"
"strings"
"sync"
"time"
)
var (
errUnsupportedType = errors.New("unsupported type")
errRecordNotFound = errors.New("record not found")
errUnsupportedOperation = errors.New("unsupported operation")
)
type FileHosts struct {
HostProvider
Provider
file string
hosts map[string]string
hosts map[string]Host
mu sync.RWMutex
ttl time.Duration
}
func NewFileProvider(file string) HostProvider {
func NewFileProvider(file string, ttl time.Duration) Provider {
fp := &FileHosts{
file: file,
hosts: make(map[string]string),
hosts: make(map[string]Host),
ttl: ttl,
}
watcher, err := fsnotify.NewWatcher()
@ -44,32 +57,44 @@ func NewFileProvider(file string) HostProvider {
return fp
}
func (f *FileHosts) Get(domain string) ([]string, bool) {
logger.Debug("Checking file provider for %s", domain)
func (f *FileHosts) List() (HostMap, error) {
return nil, errUnsupportedOperation
}
func (f *FileHosts) Get(queryType uint16, domain string) (*Host, error) {
log.WithFields(log.Fields{
"queryType": dns.TypeToString[queryType],
"question": domain,
}).Debug("Checking file provider")
// Does not support CNAME/TXT/etc
if queryType != dns.TypeA && queryType != dns.TypeAAAA {
return nil, errUnsupportedType
}
f.mu.RLock()
defer f.mu.RUnlock()
domain = strings.ToLower(domain)
if ip, ok := f.hosts[domain]; ok {
return strings.Split(ip, ","), true
if host, ok := f.hosts[domain]; ok {
return &host, nil
}
if idx := strings.Index(domain, "."); idx != -1 {
wildcard := "*." + domain[strings.Index(domain, ".") + 1:]
if ip, ok := f.hosts[wildcard]; ok {
return strings.Split(ip, ","), true
if host, ok := f.hosts[wildcard]; ok {
return &host, nil
}
}
for host, ip := range f.hosts {
if glob.Glob(host, domain) {
return strings.Split(ip, ","), true
for hostname, host := range f.hosts {
if glob.Glob(hostname, domain) {
return &host, nil
}
}
return nil, false
return nil, errRecordNotFound
}
var (
@ -80,7 +105,10 @@ func (f *FileHosts) Refresh() {
buf, err := os.Open(f.file)
if err != nil {
logger.Warn("Update hosts records from file failed %s", err)
log.WithFields(log.Fields{
"file": f.file,
"error": err,
}).Warn("Hosts update from file failed")
return
}
@ -96,7 +124,7 @@ func (f *FileHosts) Refresh() {
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
if strings.HasPrefix(line, "#") || line == "" {
if line == "" || line[0] == '#' {
continue
}
@ -108,7 +136,7 @@ func (f *FileHosts) Refresh() {
ip := m[1]
if !isIP(ip) {
if !utils.IsIP(ip) {
continue
}
@ -124,12 +152,16 @@ func (f *FileHosts) Refresh() {
continue
}
f.hosts[strings.ToLower(domain)] = ip
f.hosts[strings.ToLower(domain)] = Host{Values: []string{ip}}
}
}
logger.Debug("update hosts records from %s, total %d records.", f.file, len(f.hosts))
log.WithFields(log.Fields{
"file": f.file,
"count": len(f.hosts),
}).Debug("Updated hosts records")
}
func (f *FileHosts) clear() {
f.hosts = make(map[string]string)
f.hosts = make(map[string]Host)
}

112
hosts/hosts_redis.go Normal file
View File

@ -0,0 +1,112 @@
package hosts
import (
"encoding/json"
"github.com/go-redis/redis/v7"
"github.com/miekg/dns"
log "github.com/sirupsen/logrus"
"strings"
)
type RedisHosts struct {
Provider
redis *redis.Client
key string
}
func NewRedisProvider(rc *redis.Client, key string) Provider {
rh := &RedisHosts{
redis: rc,
key: key,
}
return rh
}
func (r *RedisHosts) List() (HostMap, error) {
res, err := r.redis.HGetAll(r.key).Result()
if err != nil {
return nil, err
}
hosts := make(HostMap)
for k, v := range res {
var domainRecords []Host
if err = json.Unmarshal([]byte(v), &domainRecords); err != nil {
continue
}
hosts[k] = domainRecords
}
return nil, errUnsupportedOperation
}
func (r *RedisHosts) Get(queryType uint16, domain string) (*Host, error) {
log.WithFields(log.Fields{
"queryType": dns.TypeToString[queryType],
"question": domain,
}).Debug("Checking redis provider")
domain = strings.ToLower(domain)
if res, err := r.redis.HGet(r.key, domain).Result(); res != "" && err == nil {
var h []Host
if err = json.Unmarshal([]byte(res), &h); err != nil {
return nil, err
}
for _, host := range h {
if host.Type == queryType {
return &host, nil
}
}
}
if idx := strings.Index(domain, "."); idx != -1 {
wildcard := "*." + domain[strings.Index(domain, ".")+1:]
if res, err := r.redis.HGet(r.key, wildcard).Result(); res != "" && err == nil {
var h []Host
if err = json.Unmarshal([]byte(res), &h); err != nil {
return nil, err
}
for _, host := range h {
if host.Type == queryType {
return &host, nil
}
}
}
}
return nil, errRecordNotFound
}
func (r *RedisHosts) Set(domain string, host *Host) error {
hosts := []*Host{host}
if res, err := r.redis.HGet(r.key, domain).Result(); res != "" && err == nil {
if err = json.Unmarshal([]byte(res), &hosts); err != nil {
return err
}
hosts = append(hosts, host)
}
b, err := json.Marshal(hosts)
if err != nil {
return err
}
_, err = r.redis.HSet(r.key, strings.ToLower(domain), b).Result()
return err
}

View File

@ -1,128 +0,0 @@
package main
import (
"github.com/hoisie/redis"
"github.com/ryanuber/go-glob"
"strings"
"sync"
)
type RedisHosts struct {
HostProvider
redis *redis.Client
key string
hosts map[string]string
mu sync.RWMutex
}
func NewRedisProvider(rc *redis.Client, key string) HostProvider {
rh := &RedisHosts{
redis: rc,
key: key,
hosts: make(map[string]string),
}
// Force an initial refresh
rh.Refresh()
// Use pubsub to listen for key update events
go func() {
keyspaceEvent := "__keyspace@0__:" + key
sub := make(chan string, 3)
sub <- keyspaceEvent
sub <- "godns:update"
sub <- "godns:update_record"
messages := make(chan redis.Message, 0)
go rc.Subscribe(sub, nil, nil, nil, messages)
for {
msg := <-messages
if msg.Channel == "godns:update" {
logger.Debug("Refreshing redis records due to update")
rh.Refresh()
} else if msg.Channel == "godns:update_record" {
recordName := string(msg.Message)
b, err := rc.Hget(key, recordName)
if err != nil {
logger.Warn("Record %s does not exist, but was updated", recordName)
continue
}
logger.Debug("Record %s was updated to %s", recordName, string(b))
rh.mu.Lock()
rh.hosts[recordName] = string(b)
rh.mu.Unlock()
} else if msg.Channel == "godns:remove_record" {
logger.Debug("Record %s was removed", msg.Message)
recordName := string(msg.Message)
rh.mu.Lock()
delete(rh.hosts, recordName)
rh.mu.Unlock()
} else if msg.Channel == keyspaceEvent {
logger.Debug("Refreshing redis records due to update")
rh.Refresh()
}
}
}()
return rh
}
func (r *RedisHosts) Get(domain string) ([]string, bool) {
logger.Debug("Checking redis provider for %s", domain)
r.mu.RLock()
defer r.mu.RUnlock()
domain = strings.ToLower(domain)
if ip, ok := r.hosts[domain]; ok {
return strings.Split(ip, ","), true
}
if idx := strings.Index(domain, "."); idx != -1 {
wildcard := "*." + domain[strings.Index(domain, ".")+1:]
if ip, ok := r.hosts[wildcard]; ok {
return strings.Split(ip, ","), true
}
}
for host, ip := range r.hosts {
if glob.Glob(host, domain) {
return strings.Split(ip, ","), true
}
}
return nil, false
}
func (r *RedisHosts) Set(domain, ip string) (bool, error) {
r.mu.Lock()
defer r.mu.Unlock()
return r.redis.Hset(r.key, strings.ToLower(domain), []byte(ip))
}
func (r *RedisHosts) Refresh() {
r.mu.Lock()
defer r.mu.Unlock()
r.clear()
err := r.redis.Hgetall(r.key, r.hosts)
if err != nil {
logger.Warn("Update hosts records from redis failed %s", err)
} else {
logger.Debug("Update hosts records from redis")
}
}
func (r *RedisHosts) clear() {
r.hosts = make(map[string]string)
}

173
log.go
View File

@ -1,173 +0,0 @@
package main
import (
"fmt"
"log"
"os"
)
const LOG_OUTPUT_BUFFER = 1024
const (
LevelDebug = iota
LevelInfo
LevelNotice
LevelWarn
LevelError
)
type logMesg struct {
Level int
Mesg string
}
type LoggerHandler interface {
Setup(config map[string]interface{}) error
Write(mesg *logMesg)
}
type GoDNSLogger struct {
level int
mesgs chan *logMesg
outputs map[string]LoggerHandler
}
func NewLogger() *GoDNSLogger {
logger := &GoDNSLogger{
mesgs: make(chan *logMesg, LOG_OUTPUT_BUFFER),
outputs: make(map[string]LoggerHandler),
}
go logger.Run()
return logger
}
func (l *GoDNSLogger) SetLogger(handlerType string, config map[string]interface{}) {
var handler LoggerHandler
switch handlerType {
case "console":
handler = NewConsoleHandler()
case "file":
handler = NewFileHandler()
default:
panic("Unknown log handler.")
}
handler.Setup(config)
l.outputs[handlerType] = handler
}
func (l *GoDNSLogger) SetLevel(level int) {
l.level = level
}
func (l *GoDNSLogger) Run() {
for {
select {
case mesg := <-l.mesgs:
for _, handler := range l.outputs {
handler.Write(mesg)
}
}
}
}
func (l *GoDNSLogger) writeMesg(mesg string, level int) {
if l.level > level {
return
}
lm := &logMesg{
Level: level,
Mesg: mesg,
}
l.mesgs <- lm
}
func (l *GoDNSLogger) Debug(format string, v ...interface{}) {
mesg := fmt.Sprintf("[DEBUG] "+format, v...)
l.writeMesg(mesg, LevelDebug)
}
func (l *GoDNSLogger) Info(format string, v ...interface{}) {
mesg := fmt.Sprintf("[INFO] "+format, v...)
l.writeMesg(mesg, LevelInfo)
}
func (l *GoDNSLogger) Notice(format string, v ...interface{}) {
mesg := fmt.Sprintf("[NOTICE] "+format, v...)
l.writeMesg(mesg, LevelNotice)
}
func (l *GoDNSLogger) Warn(format string, v ...interface{}) {
mesg := fmt.Sprintf("[WARN] "+format, v...)
l.writeMesg(mesg, LevelWarn)
}
func (l *GoDNSLogger) Error(format string, v ...interface{}) {
mesg := fmt.Sprintf("[ERROR] "+format, v...)
l.writeMesg(mesg, LevelError)
}
type ConsoleHandler struct {
level int
logger *log.Logger
}
func NewConsoleHandler() LoggerHandler {
return new(ConsoleHandler)
}
func (h *ConsoleHandler) Setup(config map[string]interface{}) error {
if _level, ok := config["level"]; ok {
level := _level.(int)
h.level = level
}
h.logger = log.New(os.Stdout, "", log.Ldate|log.Ltime)
return nil
}
func (h *ConsoleHandler) Write(lm *logMesg) {
if h.level <= lm.Level {
h.logger.Println(lm.Mesg)
}
}
type FileHandler struct {
level int
file string
logger *log.Logger
}
func NewFileHandler() LoggerHandler {
return new(FileHandler)
}
func (h *FileHandler) Setup(config map[string]interface{}) error {
if level, ok := config["level"]; ok {
h.level = level.(int)
}
if file, ok := config["file"]; ok {
h.file = file.(string)
output, err := os.Create(h.file)
if err != nil {
return err
}
h.logger = log.New(output, "", log.Ldate|log.Ltime)
}
return nil
}
func (h *FileHandler) Write(lm *logMesg) {
if h.logger == nil {
return
}
if h.level <= lm.Level {
h.logger.Println(lm.Mesg)
}
}

View File

@ -1,60 +0,0 @@
package main
import (
"bufio"
"os"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
func TestConsole(t *testing.T) {
logger := NewLogger()
logger.SetLogger("console", nil)
logger.SetLevel(LevelInfo)
logger.Debug("debug")
logger.Info("info")
logger.Notice("notiece")
logger.Warn("warn")
logger.Error("error")
}
func TestFile(t *testing.T) {
logger := NewLogger()
logger.SetLogger("file", map[string]interface{}{"file": "test.log"})
logger.SetLevel(LevelInfo)
logger.Debug("debug")
logger.Info("info")
logger.Notice("notiece")
logger.Warn("warn")
logger.Error("error")
time.Sleep(time.Second)
f, err := os.Open("test.log")
if err != nil {
t.Fatal(err)
}
b := bufio.NewReader(f)
linenum := 0
for {
line, _, err := b.ReadLine()
if err != nil {
break
}
if len(line) > 0 {
linenum++
}
}
Convey("Test Log File Handler", t, func() {
Convey("file line nums should be 4", func() {
So(linenum, ShouldEqual, 4)
})
})
os.Remove("test.log")
}

164
main.go
View File

@ -1,6 +1,16 @@
package main
import (
"flag"
"github.com/go-redis/redis/v7"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"io"
"meow.tf/joker/godns/api"
"meow.tf/joker/godns/cache"
"meow.tf/joker/godns/hosts"
"meow.tf/joker/godns/resolver"
"meow.tf/joker/godns/settings"
"os"
"os/signal"
"runtime"
@ -8,63 +18,150 @@ import (
"time"
)
var (
logger *GoDNSLogger
const (
Version = "0.3.0"
)
func main() {
var (
cfgFile string
)
func init() {
flag.StringVar(&cfgFile, "config", "/etc/godns/godns.conf", "")
}
func main() {
initLogger()
viper.SetConfigFile(cfgFile)
viper.AutomaticEnv()
if err := viper.ReadInConfig(); err == nil {
log.WithField("file", viper.ConfigFileUsed()).Info("Using configuration from file")
}
server := &Server{
host: settings.Server.Host,
port: settings.Server.Port,
host: viper.GetString("server.host"),
networks: viper.GetStringSlice("server.nets"),
rTimeout: 5 * time.Second,
wTimeout: 5 * time.Second,
}
server.Run()
var resolverSettings resolver.Settings
logger.Info("godns %s start", settings.Version)
/*
resolver.Settings{
Timeout: viper.GetInt("resolv.timeout"),
Interval: viper.GetInt("resolv.interval"),
SetEDNS0: viper.GetBool("resolv.edns0"),
ServerListFile: viper.GetStringSlice("resolv.server-list"),
ResolvFile: viper.GetString("resolv.file"),
}
*/
if settings.Debug {
viper.UnmarshalKey("resolv", &resolverSettings)
var resolverCache, negCache cache.Cache
r := resolver.NewResolver(resolverSettings)
cacheDuration := viper.GetDuration("cache.expire")
backend := viper.GetString("cache.backend")
var redisConfig settings.RedisSettings
viper.UnmarshalKey("cache.redis", &redisConfig)
switch backend {
case "memory":
cacheMaxCount := viper.GetInt("cache.memory.maxCount")
negCache = cache.NewMemoryCache(cacheDuration/2, cacheMaxCount)
resolverCache = cache.NewMemoryCache(cacheDuration, cacheMaxCount)
case "memcached":
servers := viper.GetStringSlice("cache.memcached.servers")
resolverCache = cache.NewMemcachedCache(servers, int32(cacheDuration.Seconds()))
negCache = cache.NewMemcachedCache(servers, int32(cacheDuration.Seconds()/2))
case "redis":
resolverCache = cache.NewRedisCache(redisConfig, cacheDuration)
negCache = cache.NewRedisCache(redisConfig, cacheDuration/2)
default:
log.WithField("backend", backend).Fatalln("Invalid cache backend")
}
providers := make([]hosts.Provider, 0)
if viper.GetBool("hosts.file.enable") {
providers = append(providers, hosts.NewFileProvider(viper.GetString("hosts.file.file"), viper.GetDuration("hosts.file.ttl")))
}
if viper.GetBool("hosts.bolt.enable") {
providers = append(providers, hosts.NewBoltProvider(viper.GetString("hosts.bolt.file")))
}
if viper.GetBool("hosts.redis.enable") {
rc := redis.NewClient(&redis.Options{Addr: redisConfig.Addr(), DB: redisConfig.DB, Password: redisConfig.Password})
providers = append(providers, hosts.NewRedisProvider(rc, viper.GetString("hosts.redis.key")))
}
h := hosts.NewHosts(providers)
a := api.New()
hosts.EnableAPI(h, a.Router())
if viper.GetBool("api.enabled") {
go func() {
err := a.Start()
if err != nil {
log.WithError(err).Fatalln("Unable to bind API")
}
}()
}
handler := NewHandler(r, resolverCache, negCache, h)
server.Run(handler)
log.Infof("joker dns %s (%s)", Version, runtime.Version())
if viper.GetBool("debug") {
go profileCPU()
go profileMEM()
}
sig := make(chan os.Signal)
signal.Notify(sig, os.Interrupt)
<- sig
forever:
for {
select {
case <-sig:
logger.Info("signal received, stopping")
break forever
}
}
log.Info("signal received, stopping")
}
func profileCPU() {
f, err := os.Create("godns.cprof")
if err != nil {
logger.Error("%s", err)
log.WithError(err).Error("Unable to profile cpu due to error")
return
}
pprof.StartCPUProfile(f)
time.AfterFunc(6*time.Minute, func() {
pprof.StopCPUProfile()
f.Close()
})
}
func profileMEM() {
f, err := os.Create("godns.mprof")
if err != nil {
logger.Error("%s", err)
log.WithError(err).Error("Unable to profile memory due to error")
return
}
@ -76,20 +173,25 @@ func profileMEM() {
}
func initLogger() {
logger = NewLogger()
if settings.Log.Stdout {
logger.SetLogger("console", nil)
if viper.GetBool("log.stdout") {
// log.SetLogger("console", nil)
}
if settings.Log.File != "" {
config := map[string]interface{}{"file": settings.Log.File}
logger.SetLogger("file", config)
if file := viper.GetString("log.file"); file != "" {
f, err := os.Create(file)
if err != nil {
return
}
log.SetOutput(io.MultiWriter(f, log.StandardLogger().Out))
}
logger.SetLevel(settings.Log.LogLevel())
}
level, err := log.ParseLevel(viper.GetString("log.level"))
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
if err != nil {
return
}
log.SetLevel(level)
}

View File

@ -1,297 +0,0 @@
package main
import (
"bufio"
"fmt"
"log"
"net"
"os"
"strconv"
"strings"
"sync"
"time"
"github.com/miekg/dns"
"errors"
"crypto/tls"
)
type ResolvError struct {
qname, net string
nameservers []string
}
func (e ResolvError) Error() string {
errmsg := fmt.Sprintf("%s resolv failed on %s (%s)", e.qname, strings.Join(e.nameservers, "; "), e.net)
return errmsg
}
type RResp struct {
msg *dns.Msg
nameserver string
rtt time.Duration
}
type Resolver struct {
servers []string
domain_server *suffixTreeNode
config *ResolvSettings
tcpClient *dns.Client
udpClient *dns.Client
httpsClient *dns.Client
}
func NewResolver(c ResolvSettings) *Resolver {
r := &Resolver{
servers: []string{},
domain_server: newSuffixTreeRoot(),
config: &c,
}
if len(c.ServerListFile) > 0 {
r.ReadServerListFile(c.ServerListFile)
log.Println("Read servers", strings.Join(r.servers, ", "))
}
if len(c.ResolvFile) > 0 {
clientConfig, err := dns.ClientConfigFromFile(c.ResolvFile)
if err != nil {
logger.Error(":%s is not a valid resolv.conf file\n", c.ResolvFile)
logger.Error("%s", err)
panic(err)
}
for _, server := range clientConfig.Servers {
r.servers = append(r.servers, net.JoinHostPort(server, clientConfig.Port))
}
}
if len(c.DOHServer) > 0 {
r.servers = append([]string{c.DOHServer}, r.servers...)
}
timeout := r.Timeout()
r.udpClient = &dns.Client{
Net: "udp",
ReadTimeout: timeout,
WriteTimeout: timeout,
}
r.tcpClient = &dns.Client{
Net: "tcp",
ReadTimeout: timeout,
WriteTimeout: timeout,
}
r.httpsClient = &dns.Client{
Net: "https",
ReadTimeout: timeout,
WriteTimeout: timeout,
}
return r
}
func (r *Resolver) parseServerListFile(buf *os.File) {
scanner := bufio.NewScanner(buf)
var line string
var idx int
for scanner.Scan() {
line = strings.TrimSpace(scanner.Text())
if !strings.HasPrefix(line, "server") {
continue
}
idx = strings.Index(line, "=")
if idx == -1 {
continue
}
line = strings.TrimSpace(line[idx+1:])
if strings.HasPrefix(line, "https://") {
r.servers = append(r.servers, line)
continue
}
tokens := strings.Split(line, "/")
switch len(tokens) {
case 3:
domain := tokens[1]
ip := tokens[2]
if !isDomain(domain) || !isIP(ip) {
continue
}
r.domain_server.sinsert(strings.Split(domain, "."), ip)
case 1:
srv_port := strings.Split(line, "#")
if len(srv_port) > 2 {
continue
}
ip := ""
if ip = srv_port[0]; !isIP(ip) {
continue
}
port := "53"
if len(srv_port) == 2 {
if _, err := strconv.Atoi(srv_port[1]); err != nil {
continue
}
port = srv_port[1]
}
r.servers = append(r.servers, net.JoinHostPort(ip, port))
}
}
}
func (r *Resolver) ReadServerListFile(path string) {
files := strings.Split(path, ";")
for _, file := range files {
buf, err := os.Open(file)
if err != nil {
panic("Can't open " + file)
}
defer buf.Close()
r.parseServerListFile(buf)
}
}
// Lookup will ask each nameserver in top-to-bottom fashion, starting a new request
// in every second, and return as early as possbile (have an answer).
// It returns an error if no request has succeeded.
func (r *Resolver) Lookup(net string, req *dns.Msg) (message *dns.Msg, err error) {
if net == "udp" && settings.ResolvConfig.SetEDNS0 {
req = req.SetEdns0(65535, true)
}
qname := req.Question[0].Name
res := make(chan *RResp, 1)
var wg sync.WaitGroup
L := func(resolver *Resolver, nameserver string) {
defer wg.Done()
c, err := resolver.resolverFor(net, nameserver)
if err != nil {
logger.Warn("error:%s", err.Error())
return
}
r, rtt, err := c.Exchange(req, nameserver)
if err != nil {
logger.Warn("%s socket error on %s", qname, nameserver)
logger.Warn("error:%s", err.Error())
return
}
// If SERVFAIL happen, should return immediately and try another upstream resolver.
// However, other Error code like NXDOMAIN is an clear response stating
// that it has been verified no such domain existas and ask other resolvers
// would make no sense. See more about #20
if r != nil && r.Rcode != dns.RcodeSuccess {
logger.Warn("%s failed to get an valid answer on %s", qname, nameserver)
if r.Rcode == dns.RcodeServerFailure {
return
}
}
re := &RResp{r, nameserver, rtt}
select {
case res <- re:
default:
}
}
ticker := time.NewTicker(time.Duration(settings.ResolvConfig.Interval) * time.Millisecond)
defer ticker.Stop()
// Start lookup on each nameserver top-down, in every second
nameservers := r.Nameservers(qname)
for _, nameserver := range nameservers {
wg.Add(1)
go L(r, nameserver)
// but exit early, if we have an answer
select {
case re := <-res:
logger.Debug("%s resolv on %s rtt: %v", UnFqdn(qname), re.nameserver, re.rtt)
return re.msg, nil
case <-ticker.C:
continue
}
}
// wait for all the namservers to finish
wg.Wait()
select {
case re := <-res:
logger.Debug("%s resolv on %s rtt: %v", UnFqdn(qname), re.nameserver, re.rtt)
return re.msg, nil
default:
return nil, ResolvError{qname, net, nameservers}
}
}
func (r *Resolver) resolverFor(net, nameserver string) (*dns.Client, error) {
if strings.HasPrefix(nameserver, "https") {
return r.httpsClient, nil
} else if strings.HasSuffix(nameserver, ":853") {
// TODO We need to set the server name so we can confirm the TLS connection. This may require a rewrite of storing nameservers.
return &dns.Client{
Net: "tcp-tls",
ReadTimeout: r.Timeout(),
WriteTimeout: r.Timeout(),
TLSConfig: &tls.Config{
ServerName: "",
},
}, nil
} else if net == "udp" {
return r.udpClient, nil
} else if net == "tcp" {
return r.tcpClient, nil
}
return nil, errors.New("no client for nameserver")
}
// Namservers return the array of nameservers, with port number appended.
// '#' in the name is treated as port separator, as with dnsmasq.
func (r *Resolver) Nameservers(qname string) []string {
queryKeys := strings.Split(qname, ".")
queryKeys = queryKeys[:len(queryKeys)-1] // ignore last '.'
ns := []string{}
if v, found := r.domain_server.search(queryKeys); found {
logger.Debug("%s be found in domain server list, upstream: %v", qname, v)
ns = append(ns, net.JoinHostPort(v, "53"))
//Ensure query the specific upstream nameserver in async Lookup() function.
return ns
}
for _, nameserver := range r.servers {
ns = append(ns, nameserver)
}
return ns
}
func (r *Resolver) Timeout() time.Duration {
return time.Duration(r.config.Timeout) * time.Second
}

7
resolver/nameserver.go Normal file
View File

@ -0,0 +1,7 @@
package resolver
type Nameserver struct {
net string
host string
address string
}

13
resolver/question.go Normal file
View File

@ -0,0 +1,13 @@
package resolver
import "github.com/miekg/dns"
type Question struct {
Name string
Type uint16
Class string
}
func (q *Question) String() string {
return q.Name + " " + q.Class + " " + dns.TypeToString[q.Type]
}

328
resolver/resolver.go Normal file
View File

@ -0,0 +1,328 @@
package resolver
import (
"errors"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"io"
"meow.tf/joker/godns/utils"
"net"
"os"
"strings"
"sync"
"time"
"crypto/tls"
"github.com/miekg/dns"
)
type ResolvError struct {
qname, net string
nameservers []*Nameserver
}
func (e ResolvError) Error() string {
nameservers := make([]string, len(e.nameservers))
for i, nameserver := range e.nameservers {
nameservers[i] = nameserver.address
}
return fmt.Sprintf("%s resolv failed on %s (%s)", e.qname, strings.Join(nameservers, "; "), e.net)
}
type RResp struct {
msg *dns.Msg
nameserver *Nameserver
rtt time.Duration
}
// Resolver contains a list of nameservers, domain-specific nameservers, and dns clients
type Resolver struct {
servers []*Nameserver
domainServer *suffixTreeNode
config *Settings
clients map[string]*dns.Client
clientLock sync.RWMutex
}
// NewResolver initializes a resolver from the specified settings
func NewResolver(c Settings) *Resolver {
r := &Resolver{
servers: make([]*Nameserver, 0),
domainServer: newSuffixTreeRoot(),
config: &c,
}
if len(c.ServerListFile) > 0 {
err := r.ReadServerListFile(c.ServerListFile)
if err != nil {
log.WithError(err).Fatalln("Unable to read server list file")
}
}
if len(c.ResolvFile) > 0 {
clientConfig, err := dns.ClientConfigFromFile(c.ResolvFile)
if err != nil {
log.WithError(err).Fatalln("not a valid resolv.conf file")
}
for _, server := range clientConfig.Servers {
r.servers = append(r.servers, &Nameserver{net: "udp", address: net.JoinHostPort(server, clientConfig.Port)})
}
}
return r
}
// server is a configuration struct for server lists
type server struct {
// Type is the nameserver type (https, udp, tcp-tls), optional
Type string
Server string
// Optional host for passing to TLS Config
Host string
Domains []string
}
// parseServerListFile loads a YAML server list file.
func (r *Resolver) parseServerListFile(buf io.Reader) error {
v := viper.New()
var err error
v.SetConfigType("yaml")
if err = v.ReadConfig(buf); err != nil {
return err
}
list := make([]server, 0)
if err = v.UnmarshalKey("servers", &list); err != nil {
return err
}
for _, server := range list {
nameserver := &Nameserver{
net: determineNet(server.Type, server.Server),
address: server.Server,
}
if len(server.Domains) > 0 {
for _, domain := range server.Domains {
r.domainServer.sinsert(strings.Split(domain, "."), nameserver)
}
continue
}
r.servers = append(r.servers, nameserver)
}
return nil
}
// ReadServerListFile loads a list of server list files.
func (r *Resolver) ReadServerListFile(files []string) error {
for _, file := range files {
buf, err := os.Open(file)
if err != nil {
return err
}
err = r.parseServerListFile(buf)
buf.Close()
if err != nil {
return err
}
}
return nil
}
// Lookup will ask each nameserver in top-to-bottom fashion, starting a new request
// in every second, and return as early as possbile (have an answer).
// It returns an error if no request has succeeded.
func (r *Resolver) Lookup(net string, req *dns.Msg) (message *dns.Msg, err error) {
if net == "udp" && r.config.SetEDNS0 {
req = req.SetEdns0(65535, true)
}
qname := req.Question[0].Name
res := make(chan *RResp, 1)
var wg sync.WaitGroup
L := func(resolver *Resolver, nameserver *Nameserver) {
defer wg.Done()
c, err := resolver.resolverFor(net, nameserver)
if err != nil {
log.WithError(err).Warn("resolver failed to resolve")
return
}
r, rtt, err := c.Exchange(req, nameserver.address)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"question": qname,
"nameserver": nameserver.address,
}).Warn("Socket error encountered")
return
}
// If SERVFAIL happen, should return immediately and try another upstream resolver.
// However, other Error code like NXDOMAIN is an clear response stating
// that it has been verified no such domain existas and ask other resolvers
// would make no sense. See more about #20
if r != nil && r.Rcode != dns.RcodeSuccess {
log.WithFields(log.Fields{
"question": qname,
"nameserver": nameserver.address,
}).Warn("Nameserver failed to get a valid answer")
if r.Rcode == dns.RcodeServerFailure {
return
}
}
re := &RResp{r, nameserver, rtt}
select {
case res <- re:
default:
}
}
ticker := time.NewTicker(time.Duration(r.config.Interval) * time.Millisecond)
defer ticker.Stop()
// Start lookup on each nameserver top-down, in every second
nameservers := r.Nameservers(qname)
for _, nameserver := range nameservers {
wg.Add(1)
go L(r, nameserver)
// but exit early, if we have an answer
select {
case re := <-res:
log.WithFields(log.Fields{
"question": utils.UnFqdn(qname),
"nameserver": re.nameserver.address,
"rtt": re.rtt,
}).Debug("Resolve")
return re.msg, nil
case <-ticker.C:
continue
}
}
// wait for all the namservers to finish
wg.Wait()
select {
case re := <-res:
log.WithFields(log.Fields{
"question": utils.UnFqdn(qname),
"nameserver": re.nameserver.address,
"rtt": re.rtt,
}).Debug("Resolve")
return re.msg, nil
default:
return nil, ResolvError{qname, net, nameservers}
}
}
func (r *Resolver) resolverFor(network string, n *Nameserver) (*dns.Client, error) {
key := network
// Use HTTPS if network is https, or TLS to force secure connections
if n.net == "https" {
key = n.net
} else if n.net == "tcp-tls" {
key = n.net + ":" + n.address
}
r.clientLock.RLock()
client, exists := r.clients[key]
r.clientLock.RUnlock()
if exists {
return client, nil
}
if n.net != "tcp" && n.net != "tcp-tls" && n.net != "https" && n.net != "udp" {
return nil, errors.New("unknown network type")
}
timeout := r.Timeout()
client = &dns.Client{
Net: n.net,
ReadTimeout: timeout,
WriteTimeout: timeout,
}
if n.net == "tcp-tls" {
host := n.host
if host == "" {
var err error
host, _, err = net.SplitHostPort(n.address)
if err != nil {
host = n.address
}
}
client.TLSConfig = &tls.Config{
ServerName: host,
}
}
r.clientLock.Lock()
r.clients[key] = client
r.clientLock.Lock()
return client, nil
}
// Nameservers return the array of nameservers, with port number appended.
// '#' in the name is treated as port separator, as with dnsmasq.
func (r *Resolver) Nameservers(qname string) []*Nameserver {
queryKeys := strings.Split(qname, ".")
queryKeys = queryKeys[:len(queryKeys)-1] // ignore last '.'
if v, found := r.domainServer.search(queryKeys); found {
log.WithFields(log.Fields{
"question": qname,
"upstream": v.address,
}).Debug("Found in domain server list")
//Ensure query the specific upstream nameserver in async Lookup() function.
return []*Nameserver{v}
}
return r.servers
}
func (r *Resolver) Timeout() time.Duration {
return time.Duration(r.config.Timeout) * time.Second
}
func determineNet(t, server string) string {
if t != "" {
return t
}
if strings.HasPrefix(server, "https") {
return "https"
}
return "udp"
}

9
resolver/settings.go Normal file
View File

@ -0,0 +1,9 @@
package resolver
type Settings struct {
Timeout int `toml:"timeout" env:"RESOLV_TIMEOUT"`
Interval int `toml:"interval" env:"RESOLV_INTERVAL"`
SetEDNS0 bool `toml:"setedns0" env:"RESOLV_EDNS0"`
ServerListFile []string `toml:"server-list-file" env:"SERVER_LIST_FILE"`
ResolvFile string `toml:"resolv-file" env:"RESOLV_FILE"`
}

View File

@ -1,16 +1,16 @@
package main
package resolver
type suffixTreeNode struct {
key string
value string
value *Nameserver
children map[string]*suffixTreeNode
}
func newSuffixTreeRoot() *suffixTreeNode {
return newSuffixTree("", "")
return newSuffixTree("", nil)
}
func newSuffixTree(key string, value string) *suffixTreeNode {
func newSuffixTree(key string, value *Nameserver) *suffixTreeNode {
root := &suffixTreeNode{
key: key,
value: value,
@ -21,11 +21,11 @@ func newSuffixTree(key string, value string) *suffixTreeNode {
func (node *suffixTreeNode) ensureSubTree(key string) {
if _, ok := node.children[key]; !ok {
node.children[key] = newSuffixTree(key, "")
node.children[key] = newSuffixTree(key, nil)
}
}
func (node *suffixTreeNode) insert(key string, value string) {
func (node *suffixTreeNode) insert(key string, value *Nameserver) {
if c, ok := node.children[key]; ok {
c.value = value
} else {
@ -33,7 +33,7 @@ func (node *suffixTreeNode) insert(key string, value string) {
}
}
func (node *suffixTreeNode) sinsert(keys []string, value string) {
func (node *suffixTreeNode) sinsert(keys []string, value *Nameserver) {
if len(keys) == 0 {
return
}
@ -48,9 +48,9 @@ func (node *suffixTreeNode) sinsert(keys []string, value string) {
node.insert(key, value)
}
func (node *suffixTreeNode) search(keys []string) (string, bool) {
func (node *suffixTreeNode) search(keys []string) (*Nameserver, bool) {
if len(keys) == 0 {
return "", false
return nil, false
}
key := keys[len(keys)-1]
@ -58,8 +58,8 @@ func (node *suffixTreeNode) search(keys []string) (string, bool) {
if nextValue, found := n.search(keys[:len(keys)-1]); found {
return nextValue, found
}
return n.value, (n.value != "")
return n.value, n.value != nil
}
return "", false
return nil, false
}

View File

@ -1,4 +1,4 @@
package main
package resolver
import (
"strings"
@ -11,43 +11,43 @@ func Test_Suffix_Tree(t *testing.T) {
root := newSuffixTreeRoot()
Convey("Google should not be found", t, func() {
root.insert("cn", "114.114.114.114")
root.sinsert([]string{"baidu", "cn"}, "166.111.8.28")
root.sinsert([]string{"sina", "cn"}, "114.114.114.114")
root.insert("cn", &Nameserver{address: "114.114.114.114"})
root.sinsert([]string{"baidu", "cn"}, &Nameserver{address: "166.111.8.28"})
root.sinsert([]string{"sina", "cn"}, &Nameserver{address: "114.114.114.114"})
v, found := root.search(strings.Split("google.com", "."))
So(found, ShouldEqual, false)
v, found = root.search(strings.Split("baidu.cn", "."))
So(found, ShouldEqual, true)
So(v, ShouldEqual, "166.111.8.28")
So(v.address, ShouldEqual, "166.111.8.28")
})
Convey("Google should be found", t, func() {
root.sinsert(strings.Split("com", "."), "")
root.sinsert(strings.Split("google.com", "."), "8.8.8.8")
root.sinsert(strings.Split("twitter.com", "."), "8.8.8.8")
root.sinsert(strings.Split("scholar.google.com", "."), "208.67.222.222")
root.sinsert(strings.Split("com", "."), &Nameserver{address: ""})
root.sinsert(strings.Split("google.com", "."), &Nameserver{address: "8.8.8.8"})
root.sinsert(strings.Split("twitter.com", "."), &Nameserver{address: "8.8.8.8"})
root.sinsert(strings.Split("scholar.google.com", "."), &Nameserver{address: "208.67.222.222"})
v, found := root.search(strings.Split("google.com", "."))
So(found, ShouldEqual, true)
So(v, ShouldEqual, "8.8.8.8")
So(v.address, ShouldEqual, "8.8.8.8")
v, found = root.search(strings.Split("www.google.com", "."))
So(found, ShouldEqual, true)
So(v, ShouldEqual, "8.8.8.8")
So(v.address, ShouldEqual, "8.8.8.8")
v, found = root.search(strings.Split("scholar.google.com", "."))
So(found, ShouldEqual, true)
So(v, ShouldEqual, "208.67.222.222")
So(v.address, ShouldEqual, "208.67.222.222")
v, found = root.search(strings.Split("twitter.com", "."))
So(found, ShouldEqual, true)
So(v, ShouldEqual, "8.8.8.8")
So(v.address, ShouldEqual, "8.8.8.8")
v, found = root.search(strings.Split("baidu.cn", "."))
So(found, ShouldEqual, true)
So(v, ShouldEqual, "166.111.8.28")
So(v.address, ShouldEqual, "166.111.8.28")
})
}

View File

@ -1,8 +1,8 @@
package main
import (
"net"
"strconv"
log "github.com/sirupsen/logrus"
"strings"
"time"
"github.com/miekg/dns"
@ -10,50 +10,50 @@ import (
type Server struct {
host string
port int
networks []string
rTimeout time.Duration
wTimeout time.Duration
}
func (s *Server) Addr() string {
return net.JoinHostPort(s.host, strconv.Itoa(s.port))
}
func (s *Server) Run(handler *Handler) {
var addr string
var split []string
func (s *Server) Run() {
handler := NewHandler()
// Defaults: tcp, udp
for _, net := range s.networks {
split = strings.Split(net, ":")
tcpHandler := dns.NewServeMux()
tcpHandler.HandleFunc(".", handler.DoTCP)
net = split[0]
udpHandler := dns.NewServeMux()
udpHandler.HandleFunc(".", handler.DoUDP)
addr = s.host
tcpServer := &dns.Server{
Addr: s.Addr(),
Net: "tcp",
Handler: tcpHandler,
ReadTimeout: s.rTimeout,
WriteTimeout: s.wTimeout,
if len(split) == 1 {
addr += ":53"
} else {
addr += ":" + split[1]
}
h := dns.NewServeMux()
h.HandleFunc(".", handler.Bind(net))
server := &dns.Server{
Addr: addr,
Net: net,
Handler: h,
ReadTimeout: s.rTimeout,
WriteTimeout: s.wTimeout,
}
go s.start(server)
}
udpServer := &dns.Server{
Addr: s.Addr(),
Net: "udp",
Handler: udpHandler,
UDPSize: 65535,
ReadTimeout: s.rTimeout,
WriteTimeout: s.wTimeout,
}
go s.start(udpServer)
go s.start(tcpServer)
}
func (s *Server) start(ds *dns.Server) {
logger.Info("Start %s listener on %s", ds.Net, s.Addr())
log.Infof("Start %s listener on %s", ds.Net, ds.Addr)
err := ds.ListenAndServe()
if err != nil {
logger.Error("Start %s listener on %s failed:%s", ds.Net, s.Addr(), err.Error())
log.Errorf("Start %s listener on %s failed:%s", ds.Net, ds.Addr, err.Error())
}
}

View File

@ -1,25 +1,15 @@
package main
package settings
import (
"flag"
"fmt"
"os"
"strconv"
"github.com/BurntSushi/toml"
"github.com/caarlos0/env"
)
var (
settings Settings
)
var LogLevelMap = map[string]int{
"DEBUG": LevelDebug,
"INFO": LevelInfo,
"NOTICE": LevelNotice,
"WARN": LevelWarn,
"ERROR": LevelError,
type HostsSettings struct {
HostsFile string `toml:"host-file" env:"HOSTS_FILE"`
RedisEnable bool `toml:"redis-enable" env:"REDIS_HOSTS_ENABLE"`
RedisKey string `toml:"redis-key" env:"REDIS_HOSTS_KEY"`
TTL uint32 `toml:"ttl" env:"HOSTS_TTL"`
RefreshInterval uint32 `toml:"refresh-interval" env:"HOSTS_REFRESH_INTERVAL"`
}
type Settings struct {
@ -38,9 +28,8 @@ type ResolvSettings struct {
Timeout int `toml:"timeout" env:"RESOLV_TIMEOUT"`
Interval int `toml:"interval" env:"RESOLV_INTERVAL"`
SetEDNS0 bool `toml:"setedns0" env:"RESOLV_EDNS0"`
ServerListFile string `toml:"server-list-file" env:"SERVER_LIST_FILE"`
ServerListFile []string `toml:"server-list-file" env:"SERVER_LIST_FILE"`
ResolvFile string `toml:"resolv-file" env:"RESOLV_FILE"`
DOHServer string `toml:"dns-over-https" env:"DNS_HTTPS_SERVER"`
}
type DNSServerSettings struct {
@ -69,45 +58,8 @@ type LogSettings struct {
Level string `toml:"level" env:"LOG_LEVEL"`
}
func (ls LogSettings) LogLevel() int {
l, ok := LogLevelMap[ls.Level]
if !ok {
panic("Config error: invalid log level: " + ls.Level)
}
return l
}
type CacheSettings struct {
Backend string `toml:"backend" env:"CACHE_BACKEND"`
Expire int `toml:"expire" env:"CACHE_EXPIRE"`
Maxcount int `toml:"maxcount" env:"CACHE_MAX_COUNT"`
}
type HostsSettings struct {
Enable bool `toml:"enable" env:"HOSTS_ENABLE"`
HostsFile string `toml:"host-file" env:"HOSTS_FILE"`
RedisEnable bool `toml:"redis-enable" env:"REDIS_HOSTS_ENABLE"`
RedisKey string `toml:"redis-key" env:"REDIS_HOSTS_KEY"`
TTL uint32 `toml:"ttl" env:"HOSTS_TTL"`
RefreshInterval uint32 `toml:"refresh-interval" env:"HOSTS_REFRESH_INTERVAL"`
}
func init() {
var configFile string
flag.StringVar(&configFile, "c", "/etc/godns.conf", "Look for godns toml-formatting config file in this directory")
flag.Parse()
if _, err := toml.DecodeFile(configFile, &settings); err != nil {
fmt.Printf("%s is not a valid toml config file\n", configFile)
fmt.Println(err)
os.Exit(1)
}
env.Parse(&settings.ResolvConfig)
env.Parse(&settings.Redis)
env.Parse(&settings.Memcache)
env.Parse(&settings.Log)
env.Parse(&settings.Cache)
env.Parse(&settings.Hosts)
}

View File

@ -1,18 +0,0 @@
package main
import (
"net"
"regexp"
)
func isDomain(domain string) bool {
if isIP(domain) {
return false
}
match, _ := regexp.MatchString(`^([a-zA-Z0-9\*]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$`, domain)
return match
}
func isIP(ip string) bool {
return net.ParseIP(ip) != nil
}

26
utils/utils.go Normal file
View File

@ -0,0 +1,26 @@
package utils
import (
"github.com/miekg/dns"
"net"
"regexp"
)
func IsDomain(domain string) bool {
if IsIP(domain) {
return false
}
match, _ := regexp.MatchString(`^([a-zA-Z0-9\*]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$`, domain)
return match
}
func IsIP(ip string) bool {
return net.ParseIP(ip) != nil
}
func UnFqdn(s string) string {
if dns.IsFqdn(s) {
return s[:len(s)-1]
}
return s
}

View File

@ -1,4 +1,4 @@
package main
package utils
import (
"testing"
@ -9,23 +9,23 @@ import (
func TestHostDomainAndIP(t *testing.T) {
Convey("Test Host File Domain and IP regex", t, func() {
Convey("1.1.1.1 should be IP and not domain", func() {
So(isIP("1.1.1.1"), ShouldEqual, true)
So(isDomain("1.1.1.1"), ShouldEqual, false)
So(IsIP("1.1.1.1"), ShouldEqual, true)
So(IsDomain("1.1.1.1"), ShouldEqual, false)
})
Convey("2001:470:20::2 should be IP and not domain", func() {
So(isIP("2001:470:20::2"), ShouldEqual, true)
So(isDomain("2001:470:20::2"), ShouldEqual, false)
So(IsIP("2001:470:20::2"), ShouldEqual, true)
So(IsDomain("2001:470:20::2"), ShouldEqual, false)
})
Convey("`host` should not be domain and not IP", func() {
So(isDomain("host"), ShouldEqual, false)
So(isIP("host"), ShouldEqual, false)
So(IsDomain("host"), ShouldEqual, false)
So(IsIP("host"), ShouldEqual, false)
})
Convey("`123.test` should be domain and not IP", func() {
So(isDomain("123.test"), ShouldEqual, true)
So(isIP("123.test"), ShouldEqual, false)
So(IsDomain("123.test"), ShouldEqual, true)
So(IsIP("123.test"), ShouldEqual, false)
})
})