Skip to content

Commit 548f477

Browse files
committed
fixed gofmted and golint issues
1 parent ffbbafc commit 548f477

File tree

13 files changed

+273
-268
lines changed

13 files changed

+273
-268
lines changed

chain.go

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ package main
22

33
import (
44
"fmt"
5-
"net/http"
65
"github.com/gorilla/mux"
76
"github.com/jeremmfr/go-iptables/iptables"
7+
"net/http"
88
)
99

1010
// PUT /chain/{table}/{name}/
1111
func addChain(w http.ResponseWriter, r *http.Request) {
1212
user, err := auth.SrAuthHttp(r)
13-
if err != nil {
14-
w.WriteHeader(http.StatusUnauthorized)
15-
return
16-
}
13+
if err != nil {
14+
w.WriteHeader(http.StatusUnauthorized)
15+
return
16+
}
1717
if !user.HasRole(iptablesRole) {
18-
w.WriteHeader(http.StatusForbidden)
19-
return
20-
}
21-
18+
w.WriteHeader(http.StatusForbidden)
19+
return
20+
}
21+
2222
vars := mux.Vars(r)
2323
ipt, err := iptables.New()
2424
if err != nil {
@@ -35,15 +35,15 @@ func addChain(w http.ResponseWriter, r *http.Request) {
3535
// DELETE /chain/{table}/{name}/
3636
func delChain(w http.ResponseWriter, r *http.Request) {
3737
user, err := auth.SrAuthHttp(r)
38-
if err != nil {
39-
w.WriteHeader(http.StatusUnauthorized)
40-
return
41-
}
38+
if err != nil {
39+
w.WriteHeader(http.StatusUnauthorized)
40+
return
41+
}
4242
if !user.HasRole(iptablesRole) {
43-
w.WriteHeader(http.StatusForbidden)
44-
return
45-
}
46-
43+
w.WriteHeader(http.StatusForbidden)
44+
return
45+
}
46+
4747
vars := mux.Vars(r)
4848
ipt, err := iptables.New()
4949
if err != nil {
@@ -67,15 +67,15 @@ func delChain(w http.ResponseWriter, r *http.Request) {
6767
// GET /chain/{table}/{name}/
6868
func listChain(w http.ResponseWriter, r *http.Request) {
6969
user, err := auth.SrAuthHttp(r)
70-
if err != nil {
71-
w.WriteHeader(http.StatusUnauthorized)
72-
return
73-
}
70+
if err != nil {
71+
w.WriteHeader(http.StatusUnauthorized)
72+
return
73+
}
7474
if !user.HasRole(iptablesRole) {
75-
w.WriteHeader(http.StatusForbidden)
76-
return
77-
}
78-
75+
w.WriteHeader(http.StatusForbidden)
76+
return
77+
}
78+
7979
vars := mux.Vars(r)
8080
ipt, err := iptables.New()
8181
if err != nil {
@@ -95,15 +95,15 @@ func listChain(w http.ResponseWriter, r *http.Request) {
9595
// PUT /mvchain/{table}/{oldname}/{newname}/
9696
func renameChain(w http.ResponseWriter, r *http.Request) {
9797
user, err := auth.SrAuthHttp(r)
98-
if err != nil {
99-
w.WriteHeader(http.StatusUnauthorized)
100-
return
101-
}
98+
if err != nil {
99+
w.WriteHeader(http.StatusUnauthorized)
100+
return
101+
}
102102
if !user.HasRole(iptablesRole) {
103-
w.WriteHeader(http.StatusForbidden)
104-
return
105-
}
106-
103+
w.WriteHeader(http.StatusForbidden)
104+
return
105+
}
106+
107107
vars := mux.Vars(r)
108108
ipt, err := iptables.New()
109109
if err != nil {

chain_v6.go

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ package main
22

33
import (
44
"fmt"
5-
"net/http"
65
"github.com/gorilla/mux"
76
"github.com/jeremmfr/go-iptables/iptables"
7+
"net/http"
88
)
99

1010
// PUT /chain_v6/{table}/{name}/
1111
func addChainV6(w http.ResponseWriter, r *http.Request) {
1212
user, err := auth.SrAuthHttp(r)
13-
if err != nil {
14-
w.WriteHeader(http.StatusUnauthorized)
15-
return
16-
}
13+
if err != nil {
14+
w.WriteHeader(http.StatusUnauthorized)
15+
return
16+
}
1717
if !user.HasRole(iptablesRole) {
18-
w.WriteHeader(http.StatusForbidden)
19-
return
20-
}
21-
18+
w.WriteHeader(http.StatusForbidden)
19+
return
20+
}
21+
2222
vars := mux.Vars(r)
2323
ipt, err := iptables.NewWithProtocol(v6)
2424
if err != nil {
@@ -35,15 +35,15 @@ func addChainV6(w http.ResponseWriter, r *http.Request) {
3535
// DELETE /chain_v6/{table}/{name}/
3636
func delChainV6(w http.ResponseWriter, r *http.Request) {
3737
user, err := auth.SrAuthHttp(r)
38-
if err != nil {
39-
w.WriteHeader(http.StatusUnauthorized)
40-
return
41-
}
38+
if err != nil {
39+
w.WriteHeader(http.StatusUnauthorized)
40+
return
41+
}
4242
if !user.HasRole(iptablesRole) {
43-
w.WriteHeader(http.StatusForbidden)
44-
return
45-
}
46-
43+
w.WriteHeader(http.StatusForbidden)
44+
return
45+
}
46+
4747
vars := mux.Vars(r)
4848
ipt, err := iptables.NewWithProtocol(v6)
4949
if err != nil {
@@ -68,15 +68,15 @@ func delChainV6(w http.ResponseWriter, r *http.Request) {
6868
// GET /chain_v6/{table}/{name}/
6969
func listChainV6(w http.ResponseWriter, r *http.Request) {
7070
user, err := auth.SrAuthHttp(r)
71-
if err != nil {
72-
w.WriteHeader(http.StatusUnauthorized)
73-
return
74-
}
71+
if err != nil {
72+
w.WriteHeader(http.StatusUnauthorized)
73+
return
74+
}
7575
if !user.HasRole(iptablesRole) {
76-
w.WriteHeader(http.StatusForbidden)
77-
return
78-
}
79-
76+
w.WriteHeader(http.StatusForbidden)
77+
return
78+
}
79+
8080
vars := mux.Vars(r)
8181
ipt, err := iptables.NewWithProtocol(v6)
8282
if err != nil {
@@ -96,15 +96,15 @@ func listChainV6(w http.ResponseWriter, r *http.Request) {
9696
// PUT /mvchain_v6/{table}/{oldname}/{newname}/
9797
func renameChainV6(w http.ResponseWriter, r *http.Request) {
9898
user, err := auth.SrAuthHttp(r)
99-
if err != nil {
100-
w.WriteHeader(http.StatusUnauthorized)
101-
return
102-
}
99+
if err != nil {
100+
w.WriteHeader(http.StatusUnauthorized)
101+
return
102+
}
103103
if !user.HasRole(iptablesRole) {
104-
w.WriteHeader(http.StatusForbidden)
105-
return
106-
}
107-
104+
w.WriteHeader(http.StatusForbidden)
105+
return
106+
}
107+
108108
vars := mux.Vars(r)
109109
ipt, err := iptables.NewWithProtocol(v6)
110110
if err != nil {

config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,26 @@ func relativePath(basedir string, path *string) {
3131
}
3232
}
3333

34+
// Function GetConfig
3435
func GetConfig() *viper.Viper {
3536
return config
3637
}
3738

39+
// Function GetSecretKey
3840
func GetSecretKey() string {
3941
configs := GetConfig()
4042
key := configs.GetString("security.secret_key")
4143
return key
4244
}
4345

46+
// Function GetHost
4447
func GetHost() string {
4548
configs := GetConfig()
4649
host := configs.GetString("server.host")
4750
return host
4851
}
4952

53+
// Function GetPort
5054
func GetPort() string {
5155
configs := GetConfig()
5256
port := configs.GetString("server.port")

iptables-api

10.2 MB
Binary file not shown.

main.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package main
22

33
import (
44
"flag"
5+
"github.com/gorilla/handlers"
6+
"github.com/gorilla/mux"
7+
"github.com/jeremmfr/go-iptables/iptables"
8+
"github.com/spacerouter/sr_auth"
9+
"iptables-api/config"
510
"log"
611
"net/http"
712
"os"
813
"strings"
9-
"iptables-api/config"
10-
"github.com/spacerouter/sr_auth"
11-
"github.com/gorilla/handlers"
12-
"github.com/gorilla/mux"
13-
"github.com/jeremmfr/go-iptables/iptables"
1414
)
1515

1616
const (
@@ -21,19 +21,19 @@ const (
2121
logAct string = "LOG"
2222
trueStr string = "true"
2323
tcpStr string = "tcp"
24-
SYNStr string = "SYN"
24+
SYNStr string = "SYN" //
2525
defaultFlagsMask string = "FIN,SYN,RST,ACK"
2626
defaultFlagsMask2 string = "SYN,RST,ACK,FIN"
2727
)
2828

2929
const (
30-
iptablesRole sr_auth.Role = "iptables"
30+
iptablesRole sr_auth.Role = "iptables"
3131
)
3232

3333
var (
34-
respErr error
35-
savePath *string
36-
auth *sr_auth.Auth
34+
respErr error
35+
savePath *string
36+
auth *sr_auth.Auth
3737
)
3838

3939
func main() {
@@ -48,9 +48,9 @@ func main() {
4848

4949
flag.Parse()
5050
config.Init(*environment)
51-
tmp_auth := sr_auth.CreateAuth(config.GetSecretKey())
52-
auth = &tmp_auth
53-
51+
tmpAuth := sr_auth.CreateAuth(config.GetSecretKey())
52+
auth = &tmpAuth
53+
5454
// accesslog file open
5555
accessLog, err := os.OpenFile(*accessLogFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
5656
if err != nil {

0 commit comments

Comments
 (0)