From b5af8a2128928b91b9cec3189d3016639800a6a7 Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Mon, 21 Mar 2022 16:19:03 -0400 Subject: [PATCH 1/7] add RPL_CREATIONTIME Signed-off-by: Liam Stanley --- constants.go | 1 + 1 file changed, 1 insertion(+) diff --git a/constants.go b/constants.go index a190ef2..8f5f91b 100644 --- a/constants.go +++ b/constants.go @@ -347,4 +347,5 @@ const ( RPL_LOCALUSERS = "265" // aircd/hybrid/bahamut, used on freenode. RPL_TOPICWHOTIME = "333" // ircu, used on freenode. RPL_WHOSPCRPL = "354" // ircu, used on networks with WHOX support. + RPL_CREATIONTIME = "329" ) From 8487a7de15309fcfb12c352c2d686a9783d6daeb Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Mon, 21 Mar 2022 16:27:51 -0400 Subject: [PATCH 2/7] lint fixes Signed-off-by: Liam Stanley --- builtin.go | 2 +- cap.go | 2 +- cap_sasl.go | 1 - conn.go | 5 ++--- conn_test.go | 6 ------ event.go | 4 +--- format_test.go | 28 ---------------------------- handler.go | 1 - 8 files changed, 5 insertions(+), 44 deletions(-) diff --git a/builtin.go b/builtin.go index 081e946..914b5fa 100644 --- a/builtin.go +++ b/builtin.go @@ -451,7 +451,7 @@ func handleNAMES(c *Client, e Event) { var modes, nick string var ok bool - s := &Source{} + var s *Source c.state.Lock() for i := 0; i < len(parts); i++ { diff --git a/cap.go b/cap.go index 38ff210..dcf53f0 100644 --- a/cap.go +++ b/cap.go @@ -106,7 +106,7 @@ func parseCap(raw string) map[string]map[string]string { if j < 0 { out[parts[i][:val]][option] = "" } else { - out[parts[i][:val]][option[:j]] = option[j+1 : len(option)] + out[parts[i][:val]][option[:j]] = option[j+1:] } } } diff --git a/cap_sasl.go b/cap_sasl.go index 9aecccf..d880316 100644 --- a/cap_sasl.go +++ b/cap_sasl.go @@ -120,7 +120,6 @@ func handleSASL(c *Client, e Event) { break } } - return } func handleSASLError(c *Client, e Event) { diff --git a/conn.go b/conn.go index 441c3e7..9adb17a 100644 --- a/conn.go +++ b/conn.go @@ -43,8 +43,7 @@ type ircConn struct { lastPing time.Time // lastPong is the last successful time that we pinged the server and // received a successful pong back. - lastPong time.Time - pingDelay time.Duration + lastPong time.Time } // Dialer is an interface implementation of net.Dialer. Use this if you would @@ -477,7 +476,7 @@ func (c *Client) write(event *Event) { func (c *ircConn) rate(chars int) time.Duration { _time := time.Second + ((time.Duration(chars) * time.Second) / 100) - if c.writeDelay += _time - time.Now().Sub(c.lastWrite); c.writeDelay < 0 { + if c.writeDelay += _time - time.Since(c.lastWrite); c.writeDelay < 0 { c.writeDelay = 0 } diff --git a/conn_test.go b/conn_test.go index ae7ca80..7414b7d 100644 --- a/conn_test.go +++ b/conn_test.go @@ -46,8 +46,6 @@ func TestDecode(t *testing.T) { if err == nil { t.Fatalf("should have failed to parse decoded event. got: %#v", event) } - - return } func TestEncode(t *testing.T) { @@ -70,8 +68,6 @@ func TestEncode(t *testing.T) { if want != line { t.Fatalf("encoded line wanted: %q, got: %q", want, line) } - - return } func TestRate(t *testing.T) { @@ -88,8 +84,6 @@ func TestRate(t *testing.T) { if delay := c.rate(200); delay > (3 * time.Second) { t.Fatal("rate delay too high") } - - return } func genMockConn() (client *Client, clientConn net.Conn, serverConn net.Conn) { diff --git a/event.go b/event.go index 423e452..3eb187f 100644 --- a/event.go +++ b/event.go @@ -13,7 +13,7 @@ import ( const ( eventSpace byte = ' ' // Separator. - maxLength = 510 // Maximum length is 510 (2 for line endings). + maxLength int = 510 // Maximum length is 510 (2 for line endings). ) // cutCRFunc is used to trim CR characters from prefixes/messages. @@ -636,6 +636,4 @@ func (s *Source) writeTo(buffer *bytes.Buffer) { buffer.WriteByte(prefixHost) buffer.WriteString(s.Host) } - - return } diff --git a/format_test.go b/format_test.go index 3ec4db9..b37f5df 100644 --- a/format_test.go +++ b/format_test.go @@ -13,32 +13,24 @@ func BenchmarkFormat(b *testing.B) { for i := 0; i < b.N; i++ { Fmt("{red}test{c}") } - - return } func BenchmarkFormatLong(b *testing.B) { for i := 0; i < b.N; i++ { Fmt("{red}test {blue}2 {red}3 {brown} {italic}test{c}") } - - return } func BenchmarkStripFormat(b *testing.B) { for i := 0; i < b.N; i++ { TrimFmt("{red}test{c}") } - - return } func BenchmarkStripFormatLong(b *testing.B) { for i := 0; i < b.N; i++ { TrimFmt("{red}test {blue}2 {red}3 {brown} {italic}test{c}") } - - return } func BenchmarkStripRaw(b *testing.B) { @@ -46,8 +38,6 @@ func BenchmarkStripRaw(b *testing.B) { for i := 0; i < b.N; i++ { StripRaw(text) } - - return } func BenchmarkStripRawLong(b *testing.B) { @@ -55,8 +45,6 @@ func BenchmarkStripRawLong(b *testing.B) { for i := 0; i < b.N; i++ { StripRaw(text) } - - return } func TestFormat(t *testing.T) { @@ -249,8 +237,6 @@ func TestToRFC1459(t *testing.T) { t.Errorf("ToRFC1459() = %q, want %q", got, tt.want) } } - - return } func BenchmarkGlob(b *testing.B) { @@ -259,31 +245,23 @@ func BenchmarkGlob(b *testing.B) { b.Fatalf("should match") } } - - return } func testGlobMatch(t *testing.T, subj, pattern string) { if !Glob(subj, pattern) { t.Fatalf("'%s' should match '%s'", pattern, subj) } - - return } func testGlobNoMatch(t *testing.T, subj, pattern string) { if Glob(subj, pattern) { t.Fatalf("'%s' should not match '%s'", pattern, subj) } - - return } func TestEmptyPattern(t *testing.T) { testGlobMatch(t, "", "") testGlobNoMatch(t, "test", "") - - return } func TestEmptySubject(t *testing.T) { @@ -324,14 +302,10 @@ func TestEmptySubject(t *testing.T) { for _, pattern := range cases { testGlobNoMatch(t, pattern, "") } - - return } func TestPatternWithoutGlobs(t *testing.T) { testGlobMatch(t, "test", "test") - - return } func TestGlob(t *testing.T) { @@ -368,6 +342,4 @@ func TestGlob(t *testing.T) { for _, pattern := range cases { testGlobNoMatch(t, "this is a test", pattern) } - - return } diff --git a/handler.go b/handler.go index 4832262..712886b 100644 --- a/handler.go +++ b/handler.go @@ -458,7 +458,6 @@ func recoverHandlerPanic(client *Client, event *Event, id string, skip int) { } client.Config.RecoverFunc(client, err) - return } // HandlerError is the error returned when a panic is intentionally recovered From 887ab30b9028c8c8f178aa73dcac50366a681052 Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Mon, 21 Mar 2022 17:25:26 -0400 Subject: [PATCH 3/7] prevent potential hangup after ping timeout (fixes: #50) Signed-off-by: Liam Stanley --- conn.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/conn.go b/conn.go index 9adb17a..b691403 100644 --- a/conn.go +++ b/conn.go @@ -606,15 +606,16 @@ func (c *Client) pingLoop(ctx context.Context, errs chan error, wg *sync.WaitGro if time.Since(c.conn.lastPong) > c.Config.PingDelay+(60*time.Second) { // It's 60 seconds over what out ping delay is, connection // has probably dropped. - errs <- ErrTimedOut{ + err := ErrTimedOut{ TimeSinceSuccess: time.Since(c.conn.lastPong), LastPong: c.conn.lastPong, LastPing: c.conn.lastPing, Delay: c.Config.PingDelay, } - wg.Done() c.conn.mu.RUnlock() + errs <- err + wg.Done() return } c.conn.mu.RUnlock() From 3a46659a82877b3a44fd471a9d536dc6edc6d27d Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Mon, 21 Mar 2022 17:46:56 -0400 Subject: [PATCH 4/7] move to github actions (porting from split-messages branch) Signed-off-by: Liam Stanley --- .github/workflows/test.yml | 23 +++++++++++++++++++++++ README.md | 16 +++++----------- 2 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..7abc836 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,23 @@ +name: test + +on: + push: {} + pull_request: { branches: [master] } + +jobs: + test: + runs-on: ubuntu-latest + steps: + - id: goversion + run: | + echo ::set-output name=version::$(curl -s https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json | sed -rn 's/.*"version": "([0-9]\.[0-9]+(\.[0-9]+)?)".*/\1/p' | head -1) + - uses: actions/setup-go@v2 + with: { go-version: "${{ steps.goversion.outputs.version }}" } + - uses: actions/checkout@v2 + - run: | + go install golang.org/x/lint/golint + - run: golint -min_confidence 0.9 -set_exit_status + - run: | + GORACE="exitcode=1 halt_on_error=1" go test -v -coverprofile=coverage.txt -race -timeout 3m -count 3 -cpu 1,4 + bash <(curl -s https://codecov.io/bash) + - run: go vet -v . diff --git a/README.md b/README.md index 35f3d81..62f26a7 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,20 @@ -

+

girc, a flexible IRC library for Go

- Build Status + Test Status Coverage Status - GoDoc + GoDoc Go Report Card - IRC Chat + Community Chat

-## Status - -**girc is fairly close to marking the 1.0.0 endpoint, which will be tagged as -necessary, so you will be able to use this with care knowing the specific tag -you're using won't have breaking changes** - ## Features - Focuses on simplicity, yet tries to still be flexible. - Only requires [standard library packages](https://godoc.org/github.com/lrstanley/girc?imports) - Event based triggering/responses ([example](https://godoc.org/github.com/lrstanley/girc#ex-package--Commands), and [CTCP too](https://godoc.org/github.com/lrstanley/girc#Commands.SendCTCP)!) - [Documentation](https://godoc.org/github.com/lrstanley/girc) is _mostly_ complete. -- Support for almost all of the [IRCv3 spec](http://ircv3.net/software/libraries.html). +- Support for a good portion of the [IRCv3 spec](http://ircv3.net/software/libraries.html). - SASL Auth (currently only `PLAIN` and `EXTERNAL` is support by default, however you can simply implement `SASLMech` yourself to support additional mechanisms.) From aaebfc1f098029f99dcdb357b8b63bfd32f1986a Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Mon, 21 Mar 2022 17:48:49 -0400 Subject: [PATCH 5/7] fix golint install Signed-off-by: Liam Stanley --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7abc836..e33a388 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: with: { go-version: "${{ steps.goversion.outputs.version }}" } - uses: actions/checkout@v2 - run: | - go install golang.org/x/lint/golint + go get -u golang.org/x/lint/golint - run: golint -min_confidence 0.9 -set_exit_status - run: | GORACE="exitcode=1 halt_on_error=1" go test -v -coverprofile=coverage.txt -race -timeout 3m -count 3 -cpu 1,4 From 6681863d124f32e51ad6035197526365d82e375a Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Mon, 21 Mar 2022 17:51:44 -0400 Subject: [PATCH 6/7] go 1.18 changes Signed-off-by: Liam Stanley --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e33a388..9309961 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: with: { go-version: "${{ steps.goversion.outputs.version }}" } - uses: actions/checkout@v2 - run: | - go get -u golang.org/x/lint/golint + go install golang.org/x/lint/golint@latest - run: golint -min_confidence 0.9 -set_exit_status - run: | GORACE="exitcode=1 halt_on_error=1" go test -v -coverprofile=coverage.txt -race -timeout 3m -count 3 -cpu 1,4 From 9664730c7858b36e328e313f585789e04a3698d6 Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Mon, 21 Mar 2022 17:55:35 -0400 Subject: [PATCH 7/7] fix golint path Signed-off-by: Liam Stanley --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9309961..be6c1b0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v2 - run: | go install golang.org/x/lint/golint@latest - - run: golint -min_confidence 0.9 -set_exit_status + - run: $(go env GOPATH)/bin/golint -min_confidence 0.9 -set_exit_status - run: | GORACE="exitcode=1 halt_on_error=1" go test -v -coverprofile=coverage.txt -race -timeout 3m -count 3 -cpu 1,4 bash <(curl -s https://codecov.io/bash)