Skip to content

Commit

Permalink
chore: use golangci and goreleaser (#22)
Browse files Browse the repository at this point in the history
* chore: improve CI using golangci and CD using goreleaser

* chore: delete go.yaml

* chore: fix typo

* chore: fix golangci lint issues
  • Loading branch information
bschaatsbergen committed Dec 5, 2023
1 parent fc3700f commit d479ebb
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 32 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/ci.yaml
@@ -0,0 +1,27 @@
name: CI

on: pull_request

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
cache: false
- name: Build
run: go build -v ./...
- name: Run linters
uses: golangci/golangci-lint-action@v3
with:
version: latest
skip-pkg-cache: true
skip-build-cache: true
- name: Run tests
run: go test -v ./...
5 changes: 5 additions & 0 deletions .github/workflows/codeql-analysis.yaml
Expand Up @@ -34,6 +34,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
23 changes: 0 additions & 23 deletions .github/workflows/go.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/goreleaser.yaml
Expand Up @@ -14,9 +14,9 @@ jobs:
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: 1.19.x
go-version-file: go.mod
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
Expand Down
38 changes: 38 additions & 0 deletions .golangci.yml
@@ -0,0 +1,38 @@
# Visit https://golangci-lint.run/ for usage documentation and information on other useful linters
issues:
max-per-linter: 0
max-same-issues: 0

exclude-rules:
# disable funlen for test funcs
- source: "^func Test"
linters:
- funlen

linters:
disable-all: true
enable:
- bidichk
- durationcheck
- decorder
- dogsled
- errcheck
- exportloopref
- forcetypeassert
- funlen
- godot
- godox
- gofmt
- gosimple
- goconst
- ineffassign
- makezero
- misspell
- nilerr
- predeclared
- staticcheck
- tenv
- unconvert
- unparam
- unused
- vet
1 change: 1 addition & 0 deletions cmd/root.go
Expand Up @@ -19,6 +19,7 @@ var (
version string
flagStore model.Flagstore

//nolint:goconst
rootCmd = &cobra.Command{
Use: "dnsee",
Short: "dnsee - check DNS configurations quickly",
Expand Down
14 changes: 7 additions & 7 deletions pkg/core/core.go
Expand Up @@ -14,7 +14,7 @@ import (
const windows = "windows"
const resolverPath = "/etc/resolv.conf"

// GetQueryTypes returns a slice of all supported DNS query types
// GetQueryTypes returns a slice of all supported DNS query types.
func GetQueryTypes() []model.QueryType {
return []model.QueryType{
{Type: dns.TypeA, Name: "A"},
Expand All @@ -28,7 +28,7 @@ func GetQueryTypes() []model.QueryType {
}
}

// FilterQueryTypes filters the queryTypes slice to only include the query type specified by the user
// FilterQueryTypes filters the queryTypes slice to only include the query type specified by the user.
func FilterQueryTypes(queryTypes []model.QueryType, userSpecifiedQueryType string) []model.QueryType {
var filteredQueryTypes []model.QueryType
for _, queryType := range queryTypes {
Expand All @@ -40,24 +40,24 @@ func FilterQueryTypes(queryTypes []model.QueryType, userSpecifiedQueryType strin
return filteredQueryTypes
}

// PrepareDNSQuery prepares a DNS query for a given domain name and query type
// PrepareDNSQuery prepares a DNS query for a given domain name and query type.
func PrepareDNSQuery(domainName string, queryType uint16) dns.Msg {
msg := dns.Msg{}
msg.SetQuestion(dns.Fqdn(domainName), queryType)
return msg
}

// SendDNSQuery sends a DNS query to a given DNS server
// SendDNSQuery sends a DNS query to a given DNS server.
func SendDNSQuery(client *dns.Client, msg dns.Msg, dnsServerIP string) (*dns.Msg, time.Duration, error) {
if dnsServerIP == "" {
goOS := runtime.GOOS
if goOS == windows {
logrus.Fatal("error: Unable to retrieve DNS configuration on Windows. \nPlease specify a DNS server IP explicitely with the `--dns-server-ip` flag.")
logrus.Fatal("error: Unable to retrieve DNS configuration on Windows. \nPlease specify a DNS server IP explicitly with the `--dns-server-ip` flag.")
}
conf, err := dns.ClientConfigFromFile(resolverPath)
if err != nil {
logrus.Errorf("error: %s. Unable to retrieve DNS configuration.", err)
logrus.Fatal("Please specify a DNS server IP explicitely with the `--dns-server-ip` flag.")
logrus.Fatal("Please specify a DNS server IP explicitly with the `--dns-server-ip` flag.")
}
dnsServerIP = conf.Servers[0]
}
Expand All @@ -70,7 +70,7 @@ func SendDNSQuery(client *dns.Client, msg dns.Msg, dnsServerIP string) (*dns.Msg
return response, timeDuration, nil
}

// DisplayRecords displays the DNS records returned by the DNS server
// DisplayRecords displays the DNS records returned by the DNS server.
func DisplayRecords(domainName string, queryType struct {
Type uint16
Name string
Expand Down

0 comments on commit d479ebb

Please sign in to comment.