Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
move rand to package & fix all lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hollow committed Nov 28, 2015
1 parent 9c48057 commit 4cb3eb3
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 597 deletions.
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
sudo: false
language: go
go:
- 1.4.3
- 1.5.1
env:
- PATH=$HOME/gopath/bin:$PATH
script:

install:
- make dep

script:
- make test

notifications:
email: false
slack:
Expand Down
1 change: 1 addition & 0 deletions Goopfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ github.com/heroku/instruments !https://github.com/remerge/instruments
github.com/juju/loggo
github.com/julienschmidt/httprouter
github.com/remerge/gobi
github.com/remerge/rand
21 changes: 12 additions & 9 deletions Goopfile.lock
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
github.com/Shopify/sarama #5715ebd5b44d4150ce87b60fef2988ed3722cbc3 !https://github.com/remerge/sarama
github.com/Shopify/sarama #09281dde40e5a7a9701719f7737f9d0f259bc0e7 !https://github.com/remerge/sarama
github.com/cheekybits/genny #ed3605f490fb571b5d708aaefc618eaac347fe94
github.com/davecgh/go-spew #5215b55f46b2b919f50a1df0eaa5886afe4e3b3d
github.com/dustin/go-broadcast #3bdf6d4a7164a50bc19d5f230e2981d87d2584f1
github.com/eapache/go-resiliency #ed0319b32e66e3295db52695ba3ee493e823fbfe
github.com/eapache/go-resiliency #f341fb4dca45128e4aa86389fa6a675d55fe25e1
github.com/eapache/queue #ded5959c0d4e360646dc9e9908cff48666781367
github.com/gin-gonic/gin #fd5d4294a5d5223d55fc76d7840f4b0ad91647bb
github.com/gin-gonic/gin #52fcc5dbf6e94df33ad313858fb94b713e9d1b4a
github.com/golang/snappy #723cc1e459b8eea2dea4583200fd60757d40097a
github.com/heroku/instruments #13df4bdd5b2af788a5c68251c7b4fbb3621d6b58 !https://github.com/remerge/instruments
github.com/juju/loggo #8477fc936adf0e382d680310047ca27e128a309a
github.com/julienschmidt/httprouter #6aacfd5ab513e34f7e64ea9627ab9670371b34e7
github.com/julienschmidt/httprouter #77a895ad01ebc98a4dc95d8355bc825ce80a56f6
github.com/klauspost/crc32 #3e5c38b8b170916b332a5ccb25f921314b98ba01
github.com/manucorporat/sse #fe6ea2c8e398672518ef204bf0fbd9af858d0e15
github.com/manucorporat/stats #8f2d6ace262eba462e9beb552382c98be51d807b
github.com/mattn/go-colorable #40e4aedc8fabf8c23e040057540867186712faa5
github.com/remerge/gobi #3de10c67301d6f968927843bdccd1062a1be7a25
golang.org/x/net #b026840ad5cb594d38a2b783be1b6644fe5325fb
golang.org/x/tools #4f50f44d7a3206e9e28b984e023efce2a4a75369
gopkg.in/bluesuncorp/validator.v5 #98121ac23ff3d764f525d18d8de944d150e3c0fe
github.com/mattn/go-colorable #3dac7b4f76f6e17fb39b768b89e3783d16e237fe
github.com/remerge/gobi #7ee0e656fb6cc017dce89e15e5d950dc54664f5c
github.com/remerge/rand #a724adcff176d7a4ed0cfa07bbb9867c7be70400
golang.org/x/net #62ac18b461605b4be188bbc7300e9aa2bc836cd4
golang.org/x/tools #fff8fd7b194011cfedeafda246f0bfc275abb904
gopkg.in/bluesuncorp/validator.v5 #d5acf1dac43705f8bfbb71d878e290e2bed3950b
27 changes: 7 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,31 @@ GO=$(GOOP) exec go
GOFMT=gofmt -w -s

GOFILES=$(shell git ls-files | grep '\.go$$')
MAINGO=$(wildcard main/*.go)
MAIN=$(patsubst main/%.go,%,$(MAINGO))

.PHONY: build run watch clean test fmt dep

all: build

build: fmt
$(GO) build $(MAINGO)

build-log: fmt
$(GO) build -gcflags=-m $(MAINGO) 2>&1 | sort -u | tee build.log
grep escapes build.log > escape.log
$(GO) build

install: build
$(GO) install $(PACKAGE)

run: build
./$(MAIN)

watch:
go get github.com/cespare/reflex
reflex -t10s -r '\.go$$' -s -- sh -c 'make build test && ./$(MAIN)'

clean:
$(GO) clean
rm -f $(MAIN)
rm -rf $(TOP)/.vendor/

lint: install
go get github.com/alecthomas/gometalinter
gometalinter --install
$(GOOP) exec gometalinter -D golint -D gocyclo -D errcheck -D dupl
$(GOOP) exec gometalinter -D golint -D gocyclo -D dupl -D deadcode

test: build lint
go get github.com/smartystreets/goconvey
$(GO) test
$(GO) test -v $(PACKAGE)/rand
$(GO) test -v $(PACKAGE)/rollbar
$(GO) test -v -timeout 60s -race $(PACKAGE)
$(GO) test -v -timeout 60s -race $(PACKAGE)/kafka
$(GO) test -v -timeout 60s -race $(PACKAGE)/publicsuffix
$(GO) test -v -timeout 60s -race $(PACKAGE)/rollbar

bench:
$(GO) test -bench=. -cpu 4
Expand Down
15 changes: 12 additions & 3 deletions crypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ func DecryptHmacXorWithIntegrity(message, encrypt_key, integrity_key []byte) ([]
integrity_signature := message[size-4 : size]

mac := hmac.New(sha1.New, encrypt_key)
mac.Write(initialization_vector)
if _, err := mac.Write(initialization_vector); err != nil {
return nil, err
}

pad := mac.Sum(nil)

unciphered := make([]byte, size-20)
Expand All @@ -22,8 +25,14 @@ func DecryptHmacXorWithIntegrity(message, encrypt_key, integrity_key []byte) ([]
}

mac = hmac.New(sha1.New, integrity_key)
mac.Write(unciphered)
mac.Write(initialization_vector)
if _, err := mac.Write(unciphered); err != nil {
return nil, err
}

if _, err := mac.Write(initialization_vector); err != nil {
return nil, err
}

signature := mac.Sum(nil)[0:4]

// check signature
Expand Down
7 changes: 5 additions & 2 deletions debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/gin-gonic/gin"
"github.com/juju/loggo"
"github.com/remerge/rex/rollbar"
)

func Inspect(v interface{}) string {
Expand Down Expand Up @@ -57,14 +58,16 @@ func setLoggoSpec(c *gin.Context) {

body, err := ioutil.ReadAll(c.Request.Body)
if err != nil {
c.AbortWithError(500, err)
rollbar.Error(rollbar.WARN, err)
c.AbortWithStatus(500)
return
}

log.Infof("setting new loggo spec: %s", string(body))
err = loggo.ConfigureLoggers(string(body))
if err != nil {
c.AbortWithError(400, err)
rollbar.Error(rollbar.WARN, err)
c.AbortWithStatus(400)
return
}

Expand Down
40 changes: 21 additions & 19 deletions diskqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"time"

"github.com/juju/loggo"
"github.com/remerge/rex/rand"
"github.com/remerge/rand"
"github.com/remerge/rex/rollbar"
)

Expand Down Expand Up @@ -148,12 +148,12 @@ func (d *DiskQueue) exit(deleted bool) error {
<-d.exitSyncChan

if d.readFile != nil {
d.readFile.Close()
rollbar.Error(rollbar.WARN, d.readFile.Close())
d.readFile = nil
}

if d.writeFile != nil {
d.writeFile.Close()
rollbar.Error(rollbar.WARN, d.writeFile.Close())
d.writeFile = nil
}

Expand Down Expand Up @@ -191,12 +191,12 @@ func (d *DiskQueue) skipToNextRWFile() error {
var err error

if d.readFile != nil {
d.readFile.Close()
rollbar.Error(rollbar.WARN, d.readFile.Close())
d.readFile = nil
}

if d.writeFile != nil {
d.writeFile.Close()
rollbar.Error(rollbar.WARN, d.writeFile.Close())
d.writeFile = nil
}

Expand Down Expand Up @@ -237,7 +237,7 @@ func (d *DiskQueue) readOne() ([]byte, error) {
if d.readPos > 0 {
_, err = d.readFile.Seek(d.readPos, 0)
if err != nil {
d.readFile.Close()
rollbar.Error(rollbar.WARN, d.readFile.Close())
d.readFile = nil
return nil, err
}
Expand All @@ -248,15 +248,15 @@ func (d *DiskQueue) readOne() ([]byte, error) {

err = binary.Read(d.reader, binary.BigEndian, &msgSize)
if err != nil {
d.readFile.Close()
rollbar.Error(rollbar.WARN, d.readFile.Close())
d.readFile = nil
return nil, err
}

readBuf := make([]byte, msgSize)
_, err = io.ReadFull(d.reader, readBuf)
if err != nil {
d.readFile.Close()
rollbar.Error(rollbar.WARN, d.readFile.Close())
d.readFile = nil
return nil, err
}
Expand All @@ -273,7 +273,7 @@ func (d *DiskQueue) readOne() ([]byte, error) {
// the value can change without affecting runtime
if d.nextReadPos > d.maxBytesPerFile {
if d.readFile != nil {
d.readFile.Close()
rollbar.Error(rollbar.WARN, d.readFile.Close())
d.readFile = nil
}

Expand Down Expand Up @@ -301,7 +301,7 @@ func (d *DiskQueue) writeOne(data []byte) error {
if d.writePos > 0 {
_, err = d.writeFile.Seek(d.writePos, 0)
if err != nil {
d.writeFile.Close()
rollbar.Error(rollbar.WARN, d.writeFile.Close())
d.writeFile = nil
return err
}
Expand All @@ -324,7 +324,7 @@ func (d *DiskQueue) writeOne(data []byte) error {
// only write to the file once
_, err = d.writeFile.Write(d.writeBuf.Bytes())
if err != nil {
d.writeFile.Close()
rollbar.Error(rollbar.WARN, d.writeFile.Close())
d.writeFile = nil
return err
}
Expand All @@ -344,7 +344,7 @@ func (d *DiskQueue) writeOne(data []byte) error {
}

if d.writeFile != nil {
d.writeFile.Close()
rollbar.Error(rollbar.WARN, d.writeFile.Close())
d.writeFile = nil
}
}
Expand All @@ -357,7 +357,7 @@ func (d *DiskQueue) sync() error {
if d.writeFile != nil {
err := d.writeFile.Sync()
if err != nil {
d.writeFile.Close()
rollbar.Error(rollbar.WARN, d.writeFile.Close())
d.writeFile = nil
return err
}
Expand All @@ -382,7 +382,9 @@ func (d *DiskQueue) retrieveMetaData() error {
if err != nil {
return err
}
defer f.Close()
defer func() {
rollbar.Error(rollbar.WARN, f.Close())
}()

var depth int64
_, err = fmt.Fscanf(f, "%d\n%d,%d\n%d,%d\n",
Expand Down Expand Up @@ -418,11 +420,11 @@ func (d *DiskQueue) persistMetaData() error {
d.readFileNum, d.readPos,
d.writeFileNum, d.writePos)
if err != nil {
f.Close()
rollbar.Error(rollbar.WARN, f.Close())
return err
}
f.Sync()
f.Close()
rollbar.Error(rollbar.WARN, f.Sync())
rollbar.Error(rollbar.WARN, f.Close())

// atomically rename
return os.Rename(tmpFileName, fileName)
Expand Down Expand Up @@ -463,7 +465,7 @@ func (d *DiskQueue) checkTailCorruption(depth int64) {
rollbar.Error(rollbar.ERR, fmt.Errorf("readPos > writePos (%d > %d), corruption, skipping to next writeFileNum and resetting 0...", d.readPos, d.writePos))
}

d.skipToNextRWFile()
rollbar.Error(rollbar.WARN, d.skipToNextRWFile())
d.needSync = true
}
}
Expand Down Expand Up @@ -495,7 +497,7 @@ func (d *DiskQueue) handleReadError() {
// if you can't properly read from the current write file it's safe to
// assume that something is fucked and we should skip the current file too
if d.writeFile != nil {
d.writeFile.Close()
rollbar.Error(rollbar.WARN, d.writeFile.Close())
d.writeFile = nil
}
d.writeFileNum++
Expand Down
Loading

0 comments on commit 4cb3eb3

Please sign in to comment.