summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/binder.go36
-rw-r--r--tests/binder.go13
2 files changed, 25 insertions, 24 deletions
diff --git a/src/binder.go b/src/binder.go
index fc198e1..b115c52 100644
--- a/src/binder.go
+++ b/src/binder.go
@@ -14,18 +14,18 @@ import (
-type CLIArgs struct {
- FromAddr string
- ToAddr string
+type _CLIArgs struct {
+ fromAddr string
+ toAddr string
}
-const USER = "nobody"
+const _USER = "nobody"
-var EmitActiveConnection = g.MakeGauge("active-connections")
+var emitActiveConnection = g.MakeGauge("active-connections")
@@ -57,7 +57,7 @@ func isRunningAsRoot() bool {
return os.Geteuid() == 0
}
-func ParseArgs(args []string) CLIArgs {
+func parseArgs(args []string) _CLIArgs {
if len(args) != 3 {
fmt.Fprintf(
os.Stderr,
@@ -66,22 +66,22 @@ func ParseArgs(args []string) CLIArgs {
)
os.Exit(2)
}
- return CLIArgs {
- FromAddr: args[1],
- ToAddr: args[2],
+ return _CLIArgs {
+ fromAddr: args[1],
+ toAddr: args[2],
}
}
-func Listen(fromAddr string) net.Listener {
+func listen(fromAddr string) net.Listener {
listener, err := net.Listen("tcp", fromAddr)
g.FatalIf(err)
g.Info("Started listening", "listen-start", "from-address", fromAddr)
return listener
}
-func DropRoot() {
+func dropRoot() {
if isRunningAsRoot() {
- dropPrivileges(USER)
+ dropPrivileges(_USER)
if isRunningAsRoot() {
panic("Failed to drop privileges")
}
@@ -105,7 +105,7 @@ func Start(toAddr string, listener net.Listener) {
continue
}
defer connFrom.Close()
- EmitActiveConnection.Inc()
+ emitActiveConnection.Inc()
connTo, err := net.Dial("unix", toAddr)
if err != nil {
@@ -124,7 +124,7 @@ func Start(toAddr string, listener net.Listener) {
go copyData(c, connTo, connFrom)
go func() {
<- c
- EmitActiveConnection.Dec()
+ emitActiveConnection.Dec()
}()
}
}
@@ -132,8 +132,8 @@ func Start(toAddr string, listener net.Listener) {
func Main() {
g.Init()
- args := ParseArgs(os.Args)
- listener := Listen(args.FromAddr)
- DropRoot()
- Start(args.ToAddr, listener)
+ args := parseArgs(os.Args)
+ listener := listen(args.fromAddr)
+ dropRoot()
+ Start(args.toAddr, listener)
}
diff --git a/tests/binder.go b/tests/binder.go
index 0a1c3b7..451852c 100644
--- a/tests/binder.go
+++ b/tests/binder.go
@@ -6,16 +6,17 @@ import (
-func test_ParseArgs() {
- given := ParseArgs([]string { "a", "b", "c" })
- expected := CLIArgs {
- FromAddr: "b",
- ToAddr: "c",
+func test_parseArgs() {
+ given := parseArgs([]string { "a", "b", "c" })
+ expected := _CLIArgs {
+ fromAddr: "b",
+ toAddr: "c",
}
g.AssertEqual(given, expected)
}
+
func MainTest() {
- test_ParseArgs()
+ test_parseArgs()
}