aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-04-01 17:45:07 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-04-01 17:45:07 +0200
commitc7736d8e94b98c0a4cb9069195cf0e0cfe147283 (patch)
tree71d3405d7702e2cb8dac4c26137ed94b4ff198a0
parente3b305e171e6aae5b12db75674003604d0292c9e (diff)
Readd rpc.List
-rw-r--r--cmd/goxyctl/main.go10
-rw-r--r--route.go8
-rw-r--r--rpc.go29
3 files changed, 24 insertions, 23 deletions
diff --git a/cmd/goxyctl/main.go b/cmd/goxyctl/main.go
index 73b2958..a1e6b39 100644
--- a/cmd/goxyctl/main.go
+++ b/cmd/goxyctl/main.go
@@ -42,19 +42,17 @@ func send(server string, e goxy.Entry, del bool) error {
switch {
case e.Host != "" && e.Upstream != "":
- log.Println("Add", e)
return client.Call("GoXY.Add", e, nil)
case e.Host != "" && del:
- log.Println("Del", e.Host)
return client.Call("GoXY.Del", e.Host, nil)
default:
- var r goxy.Route
- err := client.Call("GoXY.List", struct{}{}, &r)
+ var ret []string
+ err := client.Call("GoXY.List", struct{}{}, &ret)
if err != nil {
return err
}
- for k, v := range r {
- log.Println(k, v)
+ for _, v := range ret {
+ log.Println(v)
}
}
return nil
diff --git a/route.go b/route.go
index 83998fd..47c1ebd 100644
--- a/route.go
+++ b/route.go
@@ -19,6 +19,10 @@ type route struct {
Certificate *tls.Certificate
}
+func (r route) String() string {
+ return fmt.Sprintf("%v → %v", r.ServerName, r.Upstream)
+}
+
// GetCertificate returns certificate for SNI negotiation
func (r Route) GetCertificate(h *tls.ClientHelloInfo) (*tls.Certificate, error) {
host := h.ServerName
@@ -55,7 +59,7 @@ func (r *Route) Load(fname string) error {
}
func (r Route) ServeHTTP(w http.ResponseWriter, _ *http.Request) {
- for k, v := range r {
- fmt.Fprintln(w, k, "→", v)
+ for _, v := range r {
+ fmt.Fprintln(w, v)
}
}
diff --git a/rpc.go b/rpc.go
index 71ef552..db1c296 100644
--- a/rpc.go
+++ b/rpc.go
@@ -3,6 +3,7 @@ package goxy
import (
"crypto/tls"
"errors"
+ "fmt"
"net/rpc"
"net/url"
)
@@ -14,6 +15,14 @@ var (
const RPCPort = ":8000"
+// Entry holds routing settings
+type Entry struct {
+ Host string // URL
+ Upstream string // URL
+ Cert []byte // PEM
+ Key []byte // PEM
+}
+
type GoXY struct {
server *Server
}
@@ -82,22 +91,12 @@ func (s *GoXY) Get(host string, e *Entry) error {
*e = s.server.Route[host]
return nil
}
+*/
// List routes
-func (s GoXY) List(_ struct{}, r *Route) error {
- *r = s.server.Route
+func (s GoXY) List(_ struct{}, ret *[]string) error {
+ for _, v := range s.server.Route {
+ *ret = append(*ret, fmt.Sprint(v))
+ }
return nil
}
-*/
-
-// Entry holds routing settings
-type Entry struct {
- Host string // HostName
- Upstream string // URL
- Cert []byte // PEM
- Key []byte // PEM
-}
-
-func (e Entry) String() string {
- return e.Host + " → " + e.Upstream
-}