Skip to content

Commit

Permalink
Make versioning smarter, lint and add badge
Browse files Browse the repository at this point in the history
  • Loading branch information
glinton committed May 13, 2016
1 parent a1e7e78 commit 28de991
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ shaman
dns
*.cover
config.json
build/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ language: go
go: 1.6

install: go get -t -v .
script: go test -v ./...
script: go test -cover -v ./...
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[![shaman logo](http://nano-assets.gopagoda.io/readme-headers/shaman.png)](http://nanobox.io/open-source#shaman)
[![Build Status](https://travis-ci.org/nanopack/shaman.svg)](https://travis-ci.org/nanopack/shaman)
[![GoDoc](https://godoc.org/github.com/nanopack/shaman?status.svg)](https://godoc.org/github.com/nanopack/shaman)
[![Go Report Card](https://goreportcard.com/badge/github.com/nanopack/shaman)](https://goreportcard.com/report/github.com/nanopack/shaman)
<!-- [![GoCover](https://gocover.io/_badge/github.com/nanopack/shaman)](https://gocover.io/github.com/nanopack/shaman) -->

# Shaman

Expand Down Expand Up @@ -210,4 +212,8 @@ Fields:
- Start Server Insecure


## Contributing
Contributions to shaman are welcome and encouraged. Shaman is a [Nanobox](https://nanobox.io) project and contributions should follow the [Nanobox Contribution Process & Guidelines](https://docs.nanobox.io/contributing/).


[![oss logo](http://nano-assets.gopagoda.io/open-src/nanobox-open-src.png)](http://nanobox.io/open-source)
12 changes: 6 additions & 6 deletions api/api.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package "api" provides a restful interface to manage entries in the DNS database.
// Package api provides a restful interface to manage entries in the DNS database.
package api

import (
Expand All @@ -25,9 +25,9 @@ type (
)

var (
auth nanoauth.Auth
badJson = errors.New("Bad JSON syntax received in body")
bodyReadFail = errors.New("Body Read Failed")
auth nanoauth.Auth
errBadJson = errors.New("Bad JSON syntax received in body")
errBodyReadFail = errors.New("Body Read Failed")
)

// Start starts shaman's http api
Expand Down Expand Up @@ -101,14 +101,14 @@ func parseBody(req *http.Request, v interface{}) error {
b, err := ioutil.ReadAll(req.Body)
if err != nil {
config.Log.Error(err.Error())
return bodyReadFail
return errBodyReadFail
}
defer req.Body.Close()

// parse body and store in v
err = json.Unmarshal(b, v)
if err != nil {
return badJson
return errBadJson
}

return nil
Expand Down
22 changes: 21 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
#!/usr/bin/env bash
set -e

# for versioning
getCurrCommit() {
echo `git rev-parse HEAD | tr -d "[ \r\n\']"`
}

# for versioning
getCurrTag() {
echo `git describe --always --tags --abbrev=0 | tr -d "[v\r\n]"`
}

# for versioning
getCurrBranch() {
echo `git rev-parse --abbrev-ref HEAD | tr -d "[\r\n ]"`
}

# for versioning
commit=$(getCurrCommit)
branch=$(getCurrBranch)
tag=$(getCurrTag)

# try and use the correct MD5 lib (depending on user OS darwin/linux)
MD5=$(which md5 || which md5sum)

# build shaman
echo "Building SHAMAN and uploading it to 's3://tools.nanopack.io/shaman'"
gox -osarch "linux/amd64" -output="./build/{{.OS}}/{{.Arch}}/shaman"
gox -ldflags="-X main.version=${tag} -X main.branch=${branch} -X main.commit=${commit}" -osarch "linux/amd64" -output="./build/{{.OS}}/{{.Arch}}/shaman"

# look through each os/arch/file and generate an md5 for each
echo "Generating md5s..."
Expand Down
20 changes: 10 additions & 10 deletions cache/cache.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package "cache" provides a pluggable backend for persistant record storage.
// Package cache provides a pluggable backend for persistent record storage.
package cache

import (
Expand All @@ -11,8 +11,8 @@ import (
)

var (
storage cacher
noRecordError = errors.New("No Record Found")
storage cacher
errNoRecordError = errors.New("No Record Found")
)

// The cacher interface is what all the backends [will] implement
Expand All @@ -26,7 +26,7 @@ type cacher interface {
listRecords() ([]shaman.Resource, error)
}

// Set default cacher and initialize it
// Initialize sets default cacher and initialize it
func Initialize() error {
u, err := url.Parse(config.L2Connect)
if err != nil {
Expand Down Expand Up @@ -54,7 +54,7 @@ func Initialize() error {
return err
}

// AddRecord adds a record to the persistant cache
// AddRecord adds a record to the persistent cache
func AddRecord(resource *shaman.Resource) error {
if storage == nil {
return nil
Expand All @@ -63,7 +63,7 @@ func AddRecord(resource *shaman.Resource) error {
return storage.addRecord(resource)
}

// GetRecord gets a record to the persistant cache
// GetRecord gets a record to the persistent cache
func GetRecord(domain string) (*shaman.Resource, error) {
if storage == nil {
return nil, nil
Expand All @@ -73,7 +73,7 @@ func GetRecord(domain string) (*shaman.Resource, error) {
return storage.getRecord(domain)
}

// UpdateRecord updates a record in the persistant cache
// UpdateRecord updates a record in the persistent cache
func UpdateRecord(domain string, resource *shaman.Resource) error {
if storage == nil {
return nil
Expand All @@ -83,7 +83,7 @@ func UpdateRecord(domain string, resource *shaman.Resource) error {
return storage.updateRecord(domain, resource)
}

// DeleteRecord removes a record from the persistant cache
// DeleteRecord removes a record from the persistent cache
func DeleteRecord(domain string) error {
if storage == nil {
return nil
Expand All @@ -92,7 +92,7 @@ func DeleteRecord(domain string) error {
return storage.deleteRecord(domain)
}

// ResetRecords replaces all records in the persistant cache
// ResetRecords replaces all records in the persistent cache
func ResetRecords(resources *[]shaman.Resource) error {
if storage == nil {
return nil
Expand All @@ -104,7 +104,7 @@ func ResetRecords(resources *[]shaman.Resource) error {
return storage.resetRecords(resources)
}

// ListRecords lists all records in the persistant cache
// ListRecords lists all records in the persistent cache
func ListRecords() ([]shaman.Resource, error) {
if storage == nil {
return make([]shaman.Resource, 0), nil
Expand Down
4 changes: 2 additions & 2 deletions cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
)

var (
nanopack = shaman.Resource{Domain: "nanopack.io.", Records: []shaman.Record{shaman.Record{Address: "127.0.0.1"}}}
nanobox = shaman.Resource{Domain: "nanobox.io.", Records: []shaman.Record{shaman.Record{Address: "127.0.0.2"}}}
nanopack = shaman.Resource{Domain: "nanopack.io.", Records: []shaman.Record{{Address: "127.0.0.1"}}}
nanobox = shaman.Resource{Domain: "nanobox.io.", Records: []shaman.Record{{Address: "127.0.0.2"}}}
nanoBoth = []shaman.Resource{nanopack, nanobox}
)

Expand Down
2 changes: 1 addition & 1 deletion cache/scribble.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (self scribbleDb) getRecord(domain string) (*shaman.Resource, error) {
err := self.db.Read("hosts", domain, &resource)
if err != nil {
if strings.Contains(err.Error(), "no such file or directory") {
err = noRecordError
err = errNoRecordError
}
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion commands/commands.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package "commands" provides the cli functionality.
// Package commands provides the cli functionality.
// Runnable commands are:
// add
// get
Expand Down Expand Up @@ -76,6 +76,7 @@ var (
full bool
)

// ResetVars resets the flag vars (used for testing)
func ResetVars() {
resource = shaman.Resource{}
record = shaman.Record{}
Expand Down
3 changes: 2 additions & 1 deletion core/shaman.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
sham "github.com/nanopack/shaman/core/common"
)

// Answers is the cached collection of dns records
var Answers map[string]sham.Resource

func init() {
Expand Down Expand Up @@ -127,7 +128,7 @@ func AddRecord(resource *sham.Resource) error {
return nil
}

// returns whether or not that domain exists
// Exists returns whether or not that domain exists
func Exists(domain string) bool {
sham.SanitizeDomain(&domain)
_, ok := Answers[domain]
Expand Down
6 changes: 3 additions & 3 deletions core/shaman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
)

var (
nanopack = sham.Resource{Domain: "nanopack.io.", Records: []sham.Record{sham.Record{Address: "127.0.0.1"}}}
nanopack2 = sham.Resource{Domain: "nanopack.io.", Records: []sham.Record{sham.Record{Address: "127.0.0.3"}}}
nanobox = sham.Resource{Domain: "nanobox.io.", Records: []sham.Record{sham.Record{Address: "127.0.0.2"}}}
nanopack = sham.Resource{Domain: "nanopack.io.", Records: []sham.Record{{Address: "127.0.0.1"}}}
nanopack2 = sham.Resource{Domain: "nanopack.io.", Records: []sham.Record{{Address: "127.0.0.3"}}}
nanobox = sham.Resource{Domain: "nanobox.io.", Records: []sham.Record{{Address: "127.0.0.2"}}}
nanoBoth = []sham.Resource{nanopack, nanobox}
)

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func readConfig(ccmd *cobra.Command, args []string) error {

func preFlight(ccmd *cobra.Command, args []string) error {
if config.Version {
fmt.Printf("shaman %s\n", VERSION)
fmt.Printf("shaman %s (git: %s %s)\n", version, branch, commit)
return fmt.Errorf("")
}

Expand Down
3 changes: 1 addition & 2 deletions server/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func stripSubdomain(name string) string {
// prevent searching for just 'com.' (["domain", "com", ""])
if len(names) > words {
return strings.Join(names[1:], ".")
} else {
return ""
}
return ""
}
2 changes: 1 addition & 1 deletion server/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/nanopack/shaman/server"
)

var nanopack = sham.Resource{Domain: "nanopack.io.", Records: []sham.Record{sham.Record{Address: "127.0.0.1"}}}
var nanopack = sham.Resource{Domain: "nanopack.io.", Records: []sham.Record{{Address: "127.0.0.1"}}}

func TestMain(m *testing.M) {
// manually configure
Expand Down
8 changes: 7 additions & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
package main

const VERSION = "0.0.3"
// shaman version information (populated by go linker)
// -ldflags="-X main.version=${tag} -X main.branch=${branch} -X main.commit=${commit}"
var (
version string
branch string
commit string
)

0 comments on commit 28de991

Please sign in to comment.