Use specified port for http listener
This commit is contained in:
1 parent
03cd04249c
commit
50d343e2fb
3 files changed
+9
-9
No files matched your search
+2
-6
@@ -7,11 +7,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
UPDATE_PORT = 6785
|
||||
)
|
||||
|
||||
func ListenHttp(db Zone) {
|
||||
func ListenHttp(db Zone, port int) {
|
||||
http.HandleFunc("/add", func(w http.ResponseWriter, r *http.Request) {
|
||||
name := r.FormValue("name")
|
||||
addr := r.FormValue("ip")
|
||||
@@ -31,7 +27,7 @@ func ListenHttp(db Zone) {
|
||||
log.Printf("Invalid request: %s, %s, %s", name, addr, weave_cidr)
|
||||
}
|
||||
})
|
||||
address := fmt.Sprintf(":%d", UPDATE_PORT)
|
||||
address := fmt.Sprintf(":%d", port)
|
||||
err := http.ListenAndServe(address, nil)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to create http listener: ", err)
|
||||
|
||||
+6
-2
@@ -1,6 +1,8 @@
|
||||
package weavedns
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -16,11 +18,13 @@ func TestHttp(t *testing.T) {
|
||||
)
|
||||
|
||||
var zone = new(ZoneDb)
|
||||
go ListenHttp(zone)
|
||||
port := rand.Intn(10000) + 32768
|
||||
fmt.Println("Http test on port", port)
|
||||
go ListenHttp(zone, port)
|
||||
|
||||
time.Sleep(100 * time.Millisecond) // Allow for http server to get going
|
||||
|
||||
resp, err := http.PostForm("http://localhost:6785/add",
|
||||
resp, err := http.PostForm(fmt.Sprintf("http://localhost:%d/add", port),
|
||||
url.Values{"name": {success_test_name}, "ip": {docker_ip}, "weave_cidr": {test_addr1}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ func notUsHandler() dns.HandlerFunc {
|
||||
func StartServer(ifaceName string, dnsPort int, httpPort int, wait int) error {
|
||||
|
||||
var zone = new(ZoneDb)
|
||||
go ListenHttp(zone)
|
||||
go ListenHttp(zone, httpPort)
|
||||
|
||||
var iface *net.Interface = nil
|
||||
if ifaceName != "" {
|
||||
|
||||
Reference in new issue
Block a user