Skip to content

Commit

Permalink
Golint (#386)
Browse files Browse the repository at this point in the history
Lint and vet the curret code add docs about adding a git post-commit
hook that performs these actions after each commit.
  • Loading branch information
miekg committed Nov 7, 2016
1 parent d3dae8d commit fc85754
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 18 deletions.
32 changes: 30 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ covered.

### Proposals, suggestions, ideas, new features

First, please [search](https://github.com/miekg/dns/search?q=&type=Issues&utf8=%E2%9C%93)
First, please [search](https://github.com/miekg/coredns/search?q=&type=Issues&utf8=%E2%9C%93)
with a variety of keywords to ensure your suggestion/proposal is new.

If so, you may open either an issue or a pull request for discussion and
Expand All @@ -51,9 +51,37 @@ a lot of time.

### Vulnerabilities

If you've found a vulnerability that is serious, please email me: miek@miek.nl
If you've found a vulnerability that is serious, please email me: <miek@miek.nl>.
If it's not a big deal, a pull request will probably be faster.

## Thank you

Thanks for your help! CoreDNS would not be what it is today without your contributions.

## Git Hook

We use `golint` and `go vet` as tools to warn use about things (noted golint is obnoxious sometimes,
but still helpful). Add the following script as a git `post-commit` in `.git/hooks/post-commit` and
make it executable.

~~~ sh
#!/bin/bash

# <https://git-scm.com/docs/githooks>:
# The script takes no parameters and its exit status does not affect the commit in any way. You can
# use git # rev-parse HEAD to get the new commit’s SHA1 hash, or you can use git log -l HEAD to get
# all of its # information.

for d in *; do
if [[ "$d" == "vendor" ]]; then
continue
fi
if [[ "$d" == "logo" ]]; then
continue
fi
if [[ ! -d "$d" ]]; then
continue
fi
golint "$d"/...
done
~~~
24 changes: 14 additions & 10 deletions middleware/file/tree/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ func (t *Tree) Print() {
}

func (n *Node) print() {
q := NewQueue()
q.Push(n)
q := newQueue()
q.push(n)

nodesInCurrentLevel := 1
nodesInNextLevel := 0

for !q.Empty() {
do := q.Pop()
for !q.empty() {
do := q.pop()
nodesInCurrentLevel--

if do != nil {
fmt.Print(do.Elem.Name(), " ")
q.Push(do.Left)
q.Push(do.Right)
q.push(do.Left)
q.push(do.Right)
nodesInNextLevel += 2
}
if nodesInCurrentLevel == 0 {
Expand All @@ -38,21 +38,25 @@ func (n *Node) print() {

type queue []*Node

func NewQueue() queue {
// newQueue returns a new queue.
func newQueue() queue {
q := queue([]*Node{})
return q
}

func (q *queue) Push(n *Node) {
// push pushes n to the end of the queue.
func (q *queue) push(n *Node) {
*q = append(*q, n)
}

func (q *queue) Pop() *Node {
// pop pops the first element off the queue.
func (q *queue) pop() *Node {
n := (*q)[0]
*q = (*q)[1:]
return n
}

func (q *queue) Empty() bool {
// empty returns true when the queue containes zero nodes.
func (q *queue) empty() bool {
return len(*q) == 0
}
12 changes: 6 additions & 6 deletions middleware/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ func serviceListFunc(c *kubernetes.Clientset, ns string, s *labels.Selector) fun
if s != nil {
opts.LabelSelector = *s
}
list_v1, err := c.Core().Services(ns).List(opts)
listV1, err := c.Core().Services(ns).List(opts)
if err != nil {
return nil, err
}
var list_api api.ServiceList
err = v1.Convert_v1_ServiceList_To_api_ServiceList(list_v1, &list_api, nil)
var listAPI api.ServiceList
err = v1.Convert_v1_ServiceList_To_api_ServiceList(listV1, &listAPI, nil)
if err != nil {
return nil, err
}
Expand All @@ -110,12 +110,12 @@ func namespaceListFunc(c *kubernetes.Clientset, s *labels.Selector) func(api.Lis
if s != nil {
opts.LabelSelector = *s
}
list_v1, err := c.Core().Namespaces().List(opts)
listV1, err := c.Core().Namespaces().List(opts)
if err != nil {
return nil, err
}
var list_api api.NamespaceList
err = v1.Convert_v1_NamespaceList_To_api_NamespaceList(list_v1, &list_api, nil)
var listAPI api.NamespaceList
err = v1.Convert_v1_NamespaceList_To_api_NamespaceList(listV1, &listAPI, nil)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit fc85754

Please sign in to comment.