Skip to content

Commit

Permalink
Upgrade golanglinter-ci
Browse files Browse the repository at this point in the history
Remove unmaintained golang-linter plugins.
Fix linter warning messages.
  • Loading branch information
miry committed Aug 28, 2022
1 parent 4c4ca67 commit 57ed090
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@537aa1903e5d359d0b27dbc19ddd22c5087f3fbc
with:
version: v1.43.0
version: v1.49.0

- name: shellcheck
uses: azohra/shell-linter@6bbeaa868df09c34ddc008e6030cfe89c03394a1
Expand Down
5 changes: 1 addition & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
---
run:
go: "1.17"
go: "1.15"
linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- exhaustive
Expand All @@ -22,10 +21,8 @@ linters:
- lll
- misspell
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
- whitespace
fast: false
linters-settings:
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# [Unreleased]

* Support go 1.18, 1.19. (@miry)
* Support go 1.18, 1.19. (#415, @miry)
* `toxiproxy.NewProxy` now accepts `name`, `listen addr` and `upstream addr`. (#418, @miry)
* Replace logrus with zerolog. (#413, @miry)
* Log HTTP requests to API server. (#413, @miry)
* Setup timeout 3 seconds for HTTP API server requests. (#416, @miry)

# [2.4.0] - 2022-03-07

Expand Down
12 changes: 9 additions & 3 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"os"
"strings"
"time"

"github.com/gorilla/mux"
"github.com/rs/zerolog"
Expand Down Expand Up @@ -77,16 +78,21 @@ func (server *ApiServer) Listen(host string, port string) {
r.Handle("/metrics", server.Metrics.handler())
}

http.Handle("/", StopBrowsersMiddleware(r))

server.Logger.
Info().
Str("host", host).
Str("port", port).
Str("version", Version).
Msgf("Starting HTTP server on endpoint %s:%s", host, port)

err := http.ListenAndServe(net.JoinHostPort(host, port), nil)
srv := &http.Server{
Handler: StopBrowsersMiddleware(r),
Addr: net.JoinHostPort(host, port),
WriteTimeout: 10 * time.Second,
ReadTimeout: 10 * time.Second,
}

err := srv.ListenAndServe()
if err != nil {
server.Logger.Fatal().Err(err).Msg("ListenAndServe finished with error")
}
Expand Down
7 changes: 3 additions & 4 deletions link.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import (
// and removed as they are enabled/disabled. New toxics are always added to the end
// of the chain.
//
// NoopToxic LatencyToxic
// v v
// Input > ToxicStub > ToxicStub > Output.
//
// | NoopToxic LatencyToxic
// | v v
// | Input > ToxicStub > ToxicStub > Output.
type ToxicLink struct {
stubs []*toxics.ToxicStub
proxy *Proxy
Expand Down
19 changes: 16 additions & 3 deletions test/e2e/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"fmt"
"log"
"net/http"
"time"

"github.com/gorilla/mux"
)

var (
Expand Down Expand Up @@ -41,9 +44,19 @@ func main() {
stuff[i] = byte(i % 256)
}
hex.Encode(out, stuff)
http.HandleFunc("/test1", handler1)
http.HandleFunc("/test2", handler2)

r := mux.NewRouter()
r.HandleFunc("/test1", handler1)
r.HandleFunc("/test2", handler2)

log.Println("Listening :20002")
log.Fatal(http.ListenAndServe(":20002", nil))

srv := &http.Server{
Handler: r,
Addr: ":20002",
WriteTimeout: 3 * time.Second,
ReadTimeout: 3 * time.Second,
}

log.Fatal(srv.ListenAndServe())
}
3 changes: 1 addition & 2 deletions toxics/limit_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package toxics_test
import (
"bytes"
"crypto/rand"
"fmt"
"testing"

"github.com/Shopify/toxiproxy/v2/stream"
Expand All @@ -26,7 +25,7 @@ func checkOutgoingChunk(t *testing.T, output chan *stream.StreamChunk, expected

func checkRemainingChunks(t *testing.T, output chan *stream.StreamChunk) {
if len(output) != 0 {
t.Error(fmt.Sprintf("There is %d chunks in output channel. 0 is expected.", len(output)))
t.Errorf("There is %d chunks in output channel. 0 is expected.", len(output))
}
}

Expand Down
4 changes: 2 additions & 2 deletions toxics/slicer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type SlicerToxic struct {
// Returns a list of chunk offsets to slice up a packet of the
// given total size. For example, for a size of 100, output might be:
//
// []int{0, 18, 18, 43, 43, 67, 67, 77, 77, 100}
// ^---^ ^----^ ^----^ ^----^ ^-----^
// | []int{0, 18, 18, 43, 43, 67, 67, 77, 77, 100}
// | ^---^ ^----^ ^----^ ^----^ ^-----^
//
// This tries to get fairly evenly-varying chunks (no tendency
// to have a small/large chunk at the start/end).
Expand Down

0 comments on commit 57ed090

Please sign in to comment.