Skip to content

Commit

Permalink
Applying lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
junghao committed Apr 1, 2019
1 parent bbdd97e commit 88849c7
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 57 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ install:
- go get github.com/golang/protobuf/proto
- go get github.com/golang/groupcache

before_script:
- curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.15.0

script:
- make -C cvendor/libmseed
- make -C cvendor/libslink
- test -z "$(gofmt -s -l `find . -name "*.go" | egrep -v vendor` | tee /dev/stderr)"
- go vet -cgocall=false ./...
- go test -v ./...
- golangci-lint run -E gosec # default linters + gosec
6 changes: 3 additions & 3 deletions map180/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,13 @@ func (m *map3857) nePolySVG(zoom int, layer int) (string, error) {
switch m.crossesCentral {
case true:
// things to the left of 180.
db.QueryRow(svgPolyQuery,
_ = db.QueryRow(svgPolyQuery,
m.llx, m.lly, left3857, m.ury, m.xshift, m.yshift, m.dx, m.dx, zoom, layer, m.region).Scan(&l)
// things to the right of 180 and shift them over.
db.QueryRow(svgPolyQuery,
_ = db.QueryRow(svgPolyQuery,
right3857, m.lly, m.urx, m.ury, width3857-m.llx, m.yshift, m.dx, m.dx, zoom, layer, m.region).Scan(&r)
case false:
db.QueryRow(svgPolyQuery,
_ = db.QueryRow(svgPolyQuery,
m.llx, m.lly, m.urx, m.ury, m.xshift, m.yshift, m.dx, m.dx, zoom, layer, m.region).Scan(&l)
}

Expand Down
3 changes: 0 additions & 3 deletions map180/nzmap/nzmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ func (p *Point) Icon(b *bytes.Buffer) {
p.x = -1000
p.y = -1000
}

return
}

/*
Expand Down Expand Up @@ -277,5 +275,4 @@ func (pts Points) Medium(b *bytes.Buffer) {
}
b.WriteString(nzMedium)
}
return
}
4 changes: 3 additions & 1 deletion map180/nzmap/nzmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (

// these tests also output SVG to svg_test/ for visual inspection.
func init() {
os.Mkdir("svg_test", 0755)
if err := os.Mkdir("svg_test", 0755); err != nil {
fmt.Println("Error creating svg_test directory", err)
}
}

func TestIconWellington(t *testing.T) {
Expand Down
29 changes: 13 additions & 16 deletions metrics/ddog_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,20 @@ func DataDogHttp(apiKey, hostName, appName string, logger Logger) {
ticker := time.NewTicker(time.Second * 60).C
var err error

for {
select {
case <-ticker:
ReadHttpCounters(&c)
runtime.ReadMemStats(&m)

if apiKey != "" {
err = dogHttp(apiKey, hostName, appName, m, ReadTimers(), c)
if err != nil {
logger.Printf("error sending metrics to datadog for %s %s %s", hostName, appName, err.Error())
}
} else {
logger.Printf("%s %s", hostName, appName)
logger.Printf("%+v", m)
logger.Printf("%+v", ReadTimers())
logger.Printf("%+v", c)
for range ticker {
ReadHttpCounters(&c)
runtime.ReadMemStats(&m)

if apiKey != "" {
err = dogHttp(apiKey, hostName, appName, m, ReadTimers(), c)
if err != nil {
logger.Printf("error sending metrics to datadog for %s %s %s", hostName, appName, err.Error())
}
} else {
logger.Printf("%s %s", hostName, appName)
logger.Printf("%+v", m)
logger.Printf("%+v", ReadTimers())
logger.Printf("%+v", c)
}
}
}()
Expand Down
29 changes: 13 additions & 16 deletions metrics/ddog_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,20 @@ func DataDogMsg(apiKey, hostName, appName string, logger Logger) {
ticker := time.NewTicker(time.Second * 60).C
var err error

for {
select {
case <-ticker:
ReadMsgCounters(&c)
runtime.ReadMemStats(&m)

if apiKey != "" {
err = dogMsg(apiKey, hostName, appName, m, ReadTimers(), c)
if err != nil {
logger.Printf("error sending metrics to datadog for %s %s %s", hostName, appName, err.Error())
}
} else {
logger.Printf("%s %s", hostName, appName)
logger.Printf("%+v", m)
logger.Printf("%+v", ReadTimers())
logger.Printf("%+v", c)
for range ticker {
ReadMsgCounters(&c)
runtime.ReadMemStats(&m)

if apiKey != "" {
err = dogMsg(apiKey, hostName, appName, m, ReadTimers(), c)
if err != nil {
logger.Printf("error sending metrics to datadog for %s %s %s", hostName, appName, err.Error())
}
} else {
logger.Printf("%s %s", hostName, appName)
logger.Printf("%+v", m)
logger.Printf("%+v", ReadTimers())
logger.Printf("%+v", c)
}
}
}()
Expand Down
15 changes: 6 additions & 9 deletions metrics/timers.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@ func init() {
timers = make(chan Timer, 300)

go func() {
for {
select {
case m := <-timers:
agg.m.Lock()
agg.count[m.id]++
agg.sum[m.id] += m.taken
agg.taken[m.id] = append(agg.taken[m.id], m.taken)
agg.m.Unlock()
}
for m := range timers {
agg.m.Lock()
agg.count[m.id]++
agg.sum[m.id] += m.taken
agg.taken[m.id] = append(agg.taken[m.id], m.taken)
agg.m.Unlock()
}
}()
}
Expand Down
4 changes: 3 additions & 1 deletion metrics/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ type Processor interface {
func DoProcess(m Processor, b []byte) error {
MsgRx()
t := Start()
defer t.Track("process")
defer func() {
_ = t.Track("process") // we keep this package simple thus not reporting this error
}()

err := m.Process(b)

Expand Down
1 change: 1 addition & 0 deletions slink/msrecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (r *SLMSRecord) DNomSampRate() float64 {
return float64(C.sl_msr_dnomsamprate((*_Ctype_struct_SLMSrecord_s)(r)))
}

//nolint:unused // reserved for future use
func (r *SLMSRecord) sl_DEpochSTime() float64 {
return float64(C.sl_msr_depochstime((*_Ctype_struct_SLMSrecord_s)(r)))
}
11 changes: 8 additions & 3 deletions slink/slconn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func TestReadStreamList(t *testing.T) {
t.Fatal("unable to open temporary file")
}
defer os.Remove(tf.Name())
ioutil.WriteFile(tf.Name(), ([]byte)("# A comment\nGE ISP BH?.D\nNL HGN\nMN AGU BH? HH?\n"), 0644)
if err = ioutil.WriteFile(tf.Name(), ([]byte)("# A comment\nGE ISP BH?.D\nNL HGN\nMN AGU BH? HH?\n"), 0644); err != nil {
t.Errorf("unable to write file: %v", err)
}
count, err := slconn.ReadStreamList(tf.Name(), "")
if err != nil {
t.Error("unable to read stream list, invalid format")
Expand Down Expand Up @@ -153,7 +155,7 @@ func TestParseStreamList(t *testing.T) {
if count != 3 {
t.Error("unable to parse stream list, wrong count")
}
count, err = slconn.ParseStreamList("IU__KONO:BHE BHN,GE_WLF,MN_AQU:HH?.D", "")
_, err = slconn.ParseStreamList("IU__KONO:BHE BHN,GE_WLF,MN_AQU:HH?.D", "")
if err == nil {
t.Error("shouldn't be able to parse stream list, invalid string")
}
Expand All @@ -174,7 +176,10 @@ func TestLogInitErrorMessage(t *testing.T) {
t.Fatal("unable to create new SLCD")
}

slconn.ParseStreamList("IU__KONO:BHE BHN,GE_WLF,MN_AQU:HH?.D", "")
if _, err := slconn.ParseStreamList("IU__KONO:BHE BHN,GE_WLF,MN_AQU:HH?.D", ""); err == nil {
t.Error("shouldn't be able to parse stream list, invalid string")
}

if ans := "not in NET_STA format: IU__KONO"; msg != ans {
t.Errorf("error message: expected \"%s\", received \"%s\"", ans, msg)
}
Expand Down
6 changes: 3 additions & 3 deletions weft/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ func MakeHandler(rh RequestHandler, eh ErrorHandler) http.HandlerFunc {
metrics.Written(n)
name := name(rh)

t.Track(name + "." + r.Method)
if e := t.Track(name + "." + r.Method); e != nil {
logger.Printf("Track error: %s", e.Error())
}

metrics.Request()

Expand Down Expand Up @@ -284,7 +286,6 @@ func TextError(e error, h http.Header, b *bytes.Buffer) error {
h.Set("Surrogate-Control", "max-age=86400")
_, err = b.WriteString("this resource no longer exists")
h.Set("Content-Type", "text/plain; charset=utf-8")
return nil
case http.StatusNotFound:
b.Reset()
h.Set("Surrogate-Control", "max-age=10")
Expand Down Expand Up @@ -367,7 +368,6 @@ func HTMLError(e error, h http.Header, b *bytes.Buffer) error {
h.Set("Surrogate-Control", "max-age=86400")
_, err = b.Write([]byte(ErrGone))
h.Set("Content-Type", "text/html; charset=utf-8")
return nil
case http.StatusNotFound:
b.Reset()
h.Set("Surrogate-Control", "max-age=10")
Expand Down
3 changes: 1 addition & 2 deletions wgs84/wgs84.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func DistanceBearing(lat1, lon1, lat2, lon2 float64) (distance, bearing float64,

var c2a, c, cx, cy, cz, d, del, e, sx, sy, y float64

for true {
for {
sx = math.Sin(x)
cx = math.Cos(x)
tu1 = cu2 * sx
Expand Down Expand Up @@ -100,7 +100,6 @@ func DistanceBearing(lat1, lon1, lat2, lon2 float64) (distance, bearing float64,
}

faz = math.Atan2(tu1, tu2)
baz = math.Atan2(cu1*sx, (baz*cx-su1*cu2)) + pi
x = math.Sqrt(((1.0/(r*r))-1.0)*c2a+1.0) + 1.0
x = (x - 2.0) / x
c = 1.0 - x
Expand Down

0 comments on commit 88849c7

Please sign in to comment.