Skip to content

Commit

Permalink
Add linters (#556)
Browse files Browse the repository at this point in the history
* feat: add linters.
* fix: lint.
  • Loading branch information
ldez authored and wyattjoh committed May 30, 2018
1 parent 517f442 commit 1b12c25
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 21 deletions.
25 changes: 25 additions & 0 deletions .gometalinter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"Vendor": true,
"Test": true,
"Sort": [
"path",
"line",
"column",
"linter",
"severity"
],
"Cyclo": 12,
"Enable": [
"gotypex",
"varcheck",
"gotype",
"interfacer",
"misspell",
"ineffassign",
"golint",
"vet",
"gosimple"
],
"Exclude": [],
"Deadline": "2m"
}
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ env:

before_install:
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && openssl aes-256-cbc -K $encrypted_26c593b079d9_key -iv $encrypted_26c593b079d9_iv -in .gitcookies.enc -out .gitcookies -d || true'
# Install linters and misspell
- go get -u github.com/alecthomas/gometalinter
- gometalinter --install

install:
- go get -t ./...
Expand Down
18 changes: 12 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
.PHONY: all

default: clean checks test build
GOFILES := $(shell go list -f '{{range $$index, $$element := .GoFiles}}{{$$.Dir}}/{{$$element}}{{"\n"}}{{end}}' ./... | grep -v '/vendor/')

test: clean
go test -v -cover ./...
default: clean checks test build

clean:
rm -rf dist/ builds/ cover.out

checks:
go vet ./...

build: clean
go build

test: clean
go test -v -cover ./...

checks: check-fmt
gometalinter ./...

check-fmt: SHELL := /bin/bash
check-fmt:
diff -u <(echo -n) <(gofmt -d $(GOFILES))
2 changes: 1 addition & 1 deletion acme/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (c *Client) Register(tosAgreed bool) (*RegistrationResource, error) {
return reg, nil
}

// Register the current account to the ACME server.
// RegisterWithExternalAccountBinding Register the current account to the ACME server.
func (c *Client) RegisterWithExternalAccountBinding(tosAgreed bool, kid string, hmacEncoded string) (*RegistrationResource, error) {
if c == nil || c.user == nil {
return nil, errors.New("acme: cannot register a nil client or user")
Expand Down
9 changes: 4 additions & 5 deletions cli_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,20 +322,19 @@ func run(c *cli.Context) error {
cert, err = client.ObtainCertificate(c.GlobalStringSlice("domains"), !c.Bool("no-bundle"), nil, c.Bool("must-staple"))
} else {
// read the CSR
csr, err := readCSRFile(c.GlobalString("csr"))
var csr *x509.CertificateRequest
csr, err = readCSRFile(c.GlobalString("csr"))
if err == nil {
// obtain a certificate for this CSR
cert, err = client.ObtainCertificateForCSR(*csr, !c.Bool("no-bundle"))
}
}

if err != nil {
log.Printf("Could not obtain certificates\n\t%v", err)

// Make sure to return a non-zero exit code if ObtainSANCertificate
// returned at least one error. Due to us not returning partial
// certificate we can just exit here instead of at the end.
os.Exit(1)
log.Fatalf("Could not obtain certificates\n\t%v", err)
}

if err = checkFolder(conf.CertPath()); err != nil {
Expand Down Expand Up @@ -408,7 +407,7 @@ func renew(c *cli.Context) error {
log.Printf("Could not get Certification expiration for domain %s", domain)
}

if int(expTime.Sub(time.Now()).Hours()/24.0) > c.Int("days") {
if int(time.Until(expTime).Hours()/24.0) > c.Int("days") {
return nil
}
}
Expand Down
4 changes: 2 additions & 2 deletions providers/dns/cloudflare/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ func (c *DNSProvider) makeRequest(method, uri string, body io.Reader) (json.RawM
}
strBody := "Unreadable body"
if body, err := ioutil.ReadAll(resp.Body); err == nil {
strBody= string(body)
strBody = string(body)
}
return nil, fmt.Errorf("Cloudflare API error. The request %s sent a response with a body which is not in JSON format : %s\n", req.URL.String(), strBody)
return nil, fmt.Errorf("Cloudflare API error: the request %s sent a response with a body which is not in JSON format: %s", req.URL.String(), strBody)
}

return r.Result, nil
Expand Down
8 changes: 2 additions & 6 deletions providers/dns/pdns/pdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (c *DNSProvider) Present(domain, token, keyAuth string) error {

rrsets := rrSets{
RRSets: []rrSet{
rrSet{
{
Name: name,
ChangeType: "REPLACE",
Type: "TXT",
Expand Down Expand Up @@ -139,11 +139,7 @@ func (c *DNSProvider) CleanUp(domain, token, keyAuth string) error {
}

_, err = c.makeRequest("PATCH", zone.URL, bytes.NewReader(body))
if err != nil {
return err
}

return nil
return err
}

func (c *DNSProvider) getHostedZone(fqdn string) (*hostedZone, error) {
Expand Down
1 change: 0 additions & 1 deletion providers/dns/rackspace/rackspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func dnsMux() *http.ServeMux {
return
}
w.WriteHeader(http.StatusBadRequest)
return
})

mux.HandleFunc("/123456/domains/112233/records", func(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit 1b12c25

Please sign in to comment.