Skip to content

Commit

Permalink
style: run goimports
Browse files Browse the repository at this point in the history
  • Loading branch information
CallumNZ committed May 20, 2024
1 parent e8d847d commit 510ebdf
Show file tree
Hide file tree
Showing 23 changed files with 82 additions and 74 deletions.
3 changes: 2 additions & 1 deletion cfg/cfg_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package cfg_test

import (
"github.com/GeoNet/kit/cfg"
"os"
"strings"
"testing"

"github.com/GeoNet/kit/cfg"
)

func TestPostgresEnv(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions datalogger_pb/datalogger.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions fmp_pb/fmp.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions gloria_pb/gloria.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions haz_pb/haz.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions map180/bbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type bbox struct {

/*
ValidBbox returns a nil error for a valid boundingBox. Valid options are one of:
* an empty string: ""
* a string definition of a bounding box using ',' separated
longitude latitude (float) on EPSG4327. This should be lower
- an empty string: ""
- a string definition of a bounding box using ',' separated
longitude latitude (float) on EPSG4327. This should be lower
left and upper right corners. It may cross 180. Longitude can be -180 to 180
or 0 to 360. Latitude must be <= 85.0 && >= -85.0 Examples:
"165,-48,179,-34" // New Zealand
Expand Down
55 changes: 27 additions & 28 deletions map180/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (
"context"
"database/sql"
"fmt"
"github.com/golang/groupcache"
"log"
"regexp"
"strconv"
"strings"

"github.com/golang/groupcache"
)

const (
Expand Down Expand Up @@ -76,7 +77,7 @@ for land and lake layers. region must be a valid Region.
Example:
wm, err = map180.Init(db, map180.Region(`newzealand`), 256000000)
wm, err = map180.Init(db, map180.Region(`newzealand`), 256000000)
*/
func Init(d *sql.DB, region Region, cacheBytes int64) (*Map180, error) {
w := &Map180{}
Expand Down Expand Up @@ -331,38 +332,36 @@ func (w *Map180) Map(boundingBox string, width int, pts Points, insetBbox string
/*
MapRaw returns a Raw struct which can be used for drawing SVG maps e.g.,
raw, err := wm.MapRaw(bbox, width)
b := bytes.Buffer
b.WriteString(`<?xml version="1.0"?>`)
b.WriteString(fmt.Sprintf("<svg viewBox=\"0 0 %d %d\" xmlns=\"http://www.w3.org/2000/svg\">",
raw.Width, raw.Height))
b.WriteString(fmt.Sprintf("<rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" style=\"fill: azure\"/>", raw.Width, raw.Height))
b.WriteString(fmt.Sprintf("<path style=\"fill: wheat; stroke-width: 1; stroke-linejoin: round; stroke: lightslategrey\" d=\"%s\"/>", raw.Land))
b.WriteString(fmt.Sprintf("<path style=\"fill: azure; stroke-width: 1; stroke-linejoin: round; stroke: lightslategrey\" d=\"%s\"/>", raw.Lakes))
b.WriteString("</svg>")
raw, err := wm.MapRaw(bbox, width)
b := bytes.Buffer
b.WriteString(`<?xml version="1.0"?>`)
b.WriteString(fmt.Sprintf("<svg viewBox=\"0 0 %d %d\" xmlns=\"http://www.w3.org/2000/svg\">",
raw.Width, raw.Height))
b.WriteString(fmt.Sprintf("<rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" style=\"fill: azure\"/>", raw.Width, raw.Height))
b.WriteString(fmt.Sprintf("<path style=\"fill: wheat; stroke-width: 1; stroke-linejoin: round; stroke: lightslategrey\" d=\"%s\"/>", raw.Land))
b.WriteString(fmt.Sprintf("<path style=\"fill: azure; stroke-width: 1; stroke-linejoin: round; stroke: lightslategrey\" d=\"%s\"/>", raw.Lakes))
b.WriteString("</svg>")
The other properties can be used to scale and translate for drawing on the map e.g.,
type point struct {
latitude, longitude float64
x, y float64
}
// create pts []point with x,y, set to EPSG3857 and latitude longitude EPSG4326
// range of pts ...
switch raw.CrossesCentral && p.longitude > -180.0 && p.longitude < 0.0 {
case true:
p.x = (p.x + map180.Width3857 - raw.LLX) * raw.DX
p.y = (p.y - math.Abs(raw.YShift)) * raw.DX
case false:
p.x = (p.x - math.Abs(raw.XShift)) * raw.DX
p.y = (p.y - math.Abs(raw.YShift)) * raw.DX
}
type point struct {
latitude, longitude float64
x, y float64
}
// draw p on SVG.
// create pts []point with x,y, set to EPSG3857 and latitude longitude EPSG4326
// range of pts ...
switch raw.CrossesCentral && p.longitude > -180.0 && p.longitude < 0.0 {
case true:
p.x = (p.x + map180.Width3857 - raw.LLX) * raw.DX
p.y = (p.y - math.Abs(raw.YShift)) * raw.DX
case false:
p.x = (p.x - math.Abs(raw.XShift)) * raw.DX
p.y = (p.y - math.Abs(raw.YShift)) * raw.DX
}
// draw p on SVG.
*/
func (w *Map180) MapRaw(boundingBox string, width int) (mr Raw, err error) {
var b bbox
Expand Down
19 changes: 9 additions & 10 deletions map180/nzmap/nzmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ There are no external dependencies.
Calling code can draw markers on the maps as required. The closing </svg> tag must also be added.
var b bytes.Buffer
var pts nzmap.Points
var b bytes.Buffer
var pts nzmap.Points
pts.Medium(b)
pts.Medium(b)
for _, p := range pts {
if p.Visible() {
b.WriteString(fmt.Sprintf("<path d=\"M%d %d l5 0 l-5 -8 l-5 8 Z\" stroke-width=\"0\" fill=\"blue\" opacity=\"0.7\"></path>",
p.X(), p.Y()))
for _, p := range pts {
if p.Visible() {
b.WriteString(fmt.Sprintf("<path d=\"M%d %d l5 0 l-5 -8 l-5 8 Z\" stroke-width=\"0\" fill=\"blue\" opacity=\"0.7\"></path>",
p.X(), p.Y()))
}
}
}
b.WriteString("</svg>")
b.WriteString("</svg>")
*/
package nzmap

Expand Down
3 changes: 2 additions & 1 deletion metrics/counters_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package metrics_test

import (
"github.com/GeoNet/kit/metrics"
"runtime"
"strconv"
"testing"

"github.com/GeoNet/kit/metrics"
)

func TestMsgCounters(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion metrics/timers_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package metrics_test

import (
"github.com/GeoNet/kit/metrics"
"testing"
"time"

"github.com/GeoNet/kit/metrics"
)

func TestTimers(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion sc3ml/sc3ml_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// under /work/seismcompml07-test and make sure basic quake facts
// are not zero values. Run using:
//
// go test -tags=integration
// go test -tags=integration
func TestUnmarshalIntegration(t *testing.T) {
var s sc3ml.Seiscomp
var err error
Expand Down
1 change: 0 additions & 1 deletion seis/dl/doc.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// The dl module has been writen as a lightweight replacement for the C libdali library.
// It is aimed at clients that need to connect to a datalink server, either requesting inforamtion
// or for uploading most likely miniseed records.
//
package dl
1 change: 0 additions & 1 deletion seis/ms/doc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
// The ms module has been writen as a lightweight replacement for some parts of the libmseed C library.
//
package ms
1 change: 1 addition & 0 deletions seis/ms/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ms
import (
"encoding/binary"
"fmt"

//TODO: needs v 1.15 "hash/maphash"
"strconv"
"strings"
Expand Down
2 changes: 1 addition & 1 deletion seis/ms/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Record struct {
}

// NewMSRecord decodes and unpacks the record samples from a byte slice and returns a Record pointer,
//or an empty pointer and an error if it could not be decoded.
// or an empty pointer and an error if it could not be decoded.
func NewRecord(buf []byte) (*Record, error) {

var r Record
Expand Down
4 changes: 2 additions & 2 deletions seis/ms/steim.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func getNibble(word []byte, index int) uint8 {
return res
}

//value must be 0, 1, 2 or 3, the nibble must not have been previously set
// value must be 0, 1, 2 or 3, the nibble must not have been previously set
func writeNibble(word []byte, index int, value uint8) {
b := word[index/4]
i := index % 4
Expand All @@ -23,7 +23,7 @@ func writeNibble(word []byte, index int, value uint8) {
}

/*
Takes v: an integer where only the first numbits bits are used to represent the number and returns an int32
Takes v: an integer where only the first numbits bits are used to represent the number and returns an int32
*/
func uintVarToInt32(v uint32, numbits uint8) int32 {
neg := (v & (0x1 << (numbits - 1))) != 0 //check positive/negative
Expand Down
1 change: 1 addition & 0 deletions seis/sl/conn_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build link
// +build link

package sl
Expand Down
13 changes: 6 additions & 7 deletions seis/sl/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
//
// An example Seedlink application can be as simple as:
//
// if err := sl.NewSLink().Collect(func(seq string, data []byte) (bool, error) {
// //... process miniseed data
// if err := sl.NewSLink().Collect(func(seq string, data []byte) (bool, error) {
// //... process miniseed data
//
// return false, nil
// }); err != nil {
// log.Fatal(err)
// }
// return false, nil
// }); err != nil {
// log.Fatal(err)
// }
//
// A state mechanism is available for the initial connection, although it is the clients responsibility to
// periodically maintain its content.
//
package sl
1 change: 1 addition & 0 deletions seis/sl/slink_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build link
// +build link

package sl
Expand Down
3 changes: 2 additions & 1 deletion weft/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package weft_test
import (
"bytes"
"errors"
"github.com/GeoNet/kit/weft"
"net/http"
"net/http/httptest"
"testing"

"github.com/GeoNet/kit/weft"
)

func TestMakeHandler(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions weft/weft.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ func (s StatusError) Status() int {

// Status returns the HTTP status code appropriate for err.
// It returns:
// * http.StatusOk if err is nil
// * err.Code if err is a StatusErr and Code is set
// * otherwise http.StatusServiceUnavailable
// - http.StatusOk if err is nil
// - err.Code if err is a StatusErr and Code is set
// - otherwise http.StatusServiceUnavailable
func Status(err error) int {
if err == nil {
return http.StatusOK
Expand Down
3 changes: 2 additions & 1 deletion weft/weft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package weft_test

import (
"errors"
"github.com/GeoNet/kit/weft"
"net/http"
"runtime"
"strconv"
"strings"
"testing"

"github.com/GeoNet/kit/weft"
)

func TestStatus(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions weft/wefttest/wefttest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
maxAge86400 = "max-age=86400"
)

//expected csp header for normal responses
// expected csp header for normal responses
var normalCspHeader = weft.ReturnDefaultCSP()

// test server and handlers for running the tests
Expand Down Expand Up @@ -138,7 +138,8 @@ func TestExtraParameter(t *testing.T) {

// TestFuzzRoutes tests routes with fuzzed query parameters.
// Fuzzing takes a while to run. Fuzz tests can be excluded during other testing with:
// go test -v -run 'Test[^Fuzz]'
//
// go test -v -run 'Test[^Fuzz]'
func TestFuzzQuery(t *testing.T) {
setup()
defer teardown()
Expand Down

0 comments on commit 510ebdf

Please sign in to comment.