Initial commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
cover.*
|
||||||
38
.golangci.yaml
Normal file
38
.golangci.yaml
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
linters:
|
||||||
|
enable-all: true
|
||||||
|
disable:
|
||||||
|
# re-enable when working
|
||||||
|
- rowserrcheck
|
||||||
|
- wastedassign
|
||||||
|
# maybe enable these
|
||||||
|
- wrapcheck
|
||||||
|
# leave these disabled
|
||||||
|
- cyclop
|
||||||
|
- deadcode
|
||||||
|
- dupl
|
||||||
|
- exhaustivestruct
|
||||||
|
- exhaustruct
|
||||||
|
- forbidigo
|
||||||
|
- forcetypeassert
|
||||||
|
- funlen
|
||||||
|
- gochecknoglobals
|
||||||
|
- gocognit
|
||||||
|
- goconst
|
||||||
|
- godox
|
||||||
|
- golint
|
||||||
|
- gomnd
|
||||||
|
- ifshort
|
||||||
|
- interfacer
|
||||||
|
- lll
|
||||||
|
- maintidx
|
||||||
|
- maligned
|
||||||
|
- nilnil
|
||||||
|
- nestif
|
||||||
|
- nlreturn
|
||||||
|
- nolintlint
|
||||||
|
- nosnakecase
|
||||||
|
- scopelint
|
||||||
|
- structcheck
|
||||||
|
- thelper
|
||||||
|
- varcheck
|
||||||
|
- varnamelen
|
||||||
23
elect.go
Normal file
23
elect.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package elect
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/dchest/uniuri"
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Elect struct {
|
||||||
|
client *resty.Client
|
||||||
|
instanceID string
|
||||||
|
signingKey string
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(url string, signingKey string) *Elect {
|
||||||
|
e := &Elect{
|
||||||
|
client: resty.New().
|
||||||
|
SetBaseURL(url),
|
||||||
|
instanceID: uniuri.New(),
|
||||||
|
signingKey: signingKey,
|
||||||
|
}
|
||||||
|
|
||||||
|
return e
|
||||||
|
}
|
||||||
15
elect_test.go
Normal file
15
elect_test.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package elect_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gopatchy/elect"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNew(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
c := elect.New("[::1]:1234", "abc123")
|
||||||
|
require.NotNil(t, c)
|
||||||
|
}
|
||||||
16
go.mod
Normal file
16
go.mod
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
module github.com/gopatchy/elect
|
||||||
|
|
||||||
|
go 1.20
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/dchest/uniuri v1.2.0
|
||||||
|
github.com/go-resty/resty/v2 v2.7.0
|
||||||
|
github.com/stretchr/testify v1.8.4
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
golang.org/x/net v0.0.0-20211029224645-99673261e6eb // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
||||||
21
go.sum
Normal file
21
go.sum
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/dchest/uniuri v1.2.0 h1:koIcOUdrTIivZgSLhHQvKgqdWZq5d7KdMEWF1Ud6+5g=
|
||||||
|
github.com/dchest/uniuri v1.2.0/go.mod h1:fSzm4SLHzNZvWLvWJew423PhAzkpNQYq+uNLq4kxhkY=
|
||||||
|
github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
|
||||||
|
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
|
golang.org/x/net v0.0.0-20211029224645-99673261e6eb h1:pirldcYWx7rx7kE5r+9WsOXPXK0+WH5+uZ7uPmJ44uM=
|
||||||
|
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
18
justfile
Normal file
18
justfile
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
go := env_var_or_default('GOCMD', 'go')
|
||||||
|
|
||||||
|
default: tidy test
|
||||||
|
|
||||||
|
tidy:
|
||||||
|
{{go}} mod tidy
|
||||||
|
goimports -l -w .
|
||||||
|
gofumpt -l -w .
|
||||||
|
{{go}} fmt ./...
|
||||||
|
|
||||||
|
test:
|
||||||
|
{{go}} vet ./...
|
||||||
|
golangci-lint run ./...
|
||||||
|
{{go}} test -race -coverprofile=cover.out -timeout=60s ./...
|
||||||
|
{{go}} tool cover -html=cover.out -o=cover.html
|
||||||
|
|
||||||
|
todo:
|
||||||
|
-git grep -e TODO --and --not -e ignoretodo
|
||||||
Reference in New Issue
Block a user