Skip to content

Commit

Permalink
fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Meihm committed Jun 10, 2019
1 parent 2c97365 commit cf2290d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion exception.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

var activeTree *iptree.IPTree
var treeLock sync.Mutex
var isExceptionUpdate bool = false
var isExceptionUpdate = false

type awsIPRanges struct {
Prefixes []struct {
Expand Down
12 changes: 6 additions & 6 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ func newRouter() *mux.Router {
// To maintain compatibility with previous API versions, wrap legacy API
// calls to add the type field and route to the correct handler
r.HandleFunc("/{value:(?:[0-9]{1,3}\\.){3}[0-9]{1,3}}",
auth(wrapLegacyIpRequest(httpGetReputation))).Methods("GET")
auth(wrapLegacyIPRequest(httpGetReputation))).Methods("GET")
r.HandleFunc("/{value:(?:[0-9]{1,3}\\.){3}[0-9]{1,3}}",
auth(wrapLegacyIpRequest(httpPutReputation))).Methods("PUT")
auth(wrapLegacyIPRequest(httpPutReputation))).Methods("PUT")
r.HandleFunc("/{value:(?:[0-9]{1,3}\\.){3}[0-9]{1,3}}",
auth(wrapLegacyIpRequest(httpDeleteReputation))).Methods("DELETE")
auth(wrapLegacyIPRequest(httpDeleteReputation))).Methods("DELETE")
r.HandleFunc("/violations/{value:(?:[0-9]{1,3}\\.){3}[0-9]{1,3}}",
auth(wrapLegacyIpRequest(httpPutViolation))).Methods("PUT")
r.HandleFunc("/violations", auth(wrapLegacyIpRequest(httpPutViolations))).Methods("PUT")
auth(wrapLegacyIPRequest(httpPutViolation))).Methods("PUT")
r.HandleFunc("/violations", auth(wrapLegacyIPRequest(httpPutViolations))).Methods("PUT")

r.HandleFunc("/violations", auth(httpGetViolations)).Methods("GET")
r.HandleFunc("/dump", auth(httpGetAllReputation)).Methods("GET")
Expand All @@ -122,7 +122,7 @@ func startAPI() error {
return http.ListenAndServe(sruntime.cfg.Listen, mwHandler(newRouter()))
}

func wrapLegacyIpRequest(rf func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) {
func wrapLegacyIPRequest(rf func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
m := mux.Vars(r)
m["type"] = "ip"
Expand Down
8 changes: 4 additions & 4 deletions http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,25 +198,25 @@ func TestHandlers(t *testing.T) {
c := 0
for _, rep := range reputations {
if rep.Object == "192.168.2.20" {
c += 1
c++
assert.Equal(t, "192.168.2.20", rep.Object)
assert.Equal(t, "ip", rep.Type)
assert.Equal(t, 25, rep.Reputation)
}
if rep.Object == "192.168.0.1" {
c += 1
c++
assert.Equal(t, "192.168.0.1", rep.Object)
assert.Equal(t, "ip", rep.Type)
assert.Equal(t, 50, rep.Reputation)
}
if rep.Object == "[email protected]" {
c += 1
c++
assert.Equal(t, "[email protected]", rep.Object)
assert.Equal(t, "email", rep.Type)
assert.Equal(t, 50, rep.Reputation)
}
if rep.IP == "254.254.254.254" {
c += 1
c++
assert.Equal(t, "254.254.254.254", rep.IP)
assert.Equal(t, "", rep.Object)
assert.Equal(t, "", rep.Type)
Expand Down
4 changes: 2 additions & 2 deletions validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
)

var validators = map[string]func(string) error{
"ip": validateTypeIp,
"ip": validateTypeIP,
"email": validateTypeEmail,
}

func validateTypeIp(val string) error {
func validateTypeIP(val string) error {
if net.ParseIP(val) == nil {
return fmt.Errorf("invalid ip format %v", val)
}
Expand Down

0 comments on commit cf2290d

Please sign in to comment.