Browse Source

Add version to the remote API

Eugene Yakubovich 9 years ago
parent
commit
1cb86b9fca
2 changed files with 7 additions and 7 deletions
  1. 3 3
      remote/client.go
  2. 4 4
      remote/server.go

+ 3 - 3
remote/client.go

@@ -29,11 +29,11 @@ import (
 
 // implements subnet.Manager by sending requests to the server
 type RemoteManager struct {
-	host string // includes scheme, host, and port
+	base string // includes scheme, host, and port, and version
 }
 
 func NewRemoteManager(listenAddr string) subnet.Manager {
-	return &RemoteManager{host: "http://" + listenAddr}
+	return &RemoteManager{base: "http://" + listenAddr + "/v1"}
 }
 
 func (m *RemoteManager) mkurl(network string, parts ...string) string {
@@ -43,7 +43,7 @@ func (m *RemoteManager) mkurl(network string, parts ...string) string {
 	if network[0] != '/' {
 		network = "/" + network
 	}
-	return m.host + path.Join(append([]string{network}, parts...)...)
+	return m.base + path.Join(append([]string{network}, parts...)...)
 }
 
 func (m *RemoteManager) GetNetworkConfig(ctx context.Context, network string) (*subnet.Config, error) {

+ 4 - 4
remote/server.go

@@ -159,10 +159,10 @@ func RunServer(ctx context.Context, sm subnet.Manager, listenAddr string) {
 	// that means "no network"
 
 	r := mux.NewRouter()
-	r.HandleFunc("/{network}/config", bindHandler(handleGetNetworkConfig, ctx, sm)).Methods("GET")
-	r.HandleFunc("/{network}/leases", bindHandler(handleAcquireLease, ctx, sm)).Methods("POST")
-	r.HandleFunc("/{network}/leases/{subnet}", bindHandler(handleRenewLease, ctx, sm)).Methods("PUT")
-	r.HandleFunc("/{network}/leases", bindHandler(handleWatchLeases, ctx, sm)).Methods("GET")
+	r.HandleFunc("/v1/{network}/config", bindHandler(handleGetNetworkConfig, ctx, sm)).Methods("GET")
+	r.HandleFunc("/v1/{network}/leases", bindHandler(handleAcquireLease, ctx, sm)).Methods("POST")
+	r.HandleFunc("/v1/{network}/leases/{subnet}", bindHandler(handleRenewLease, ctx, sm)).Methods("PUT")
+	r.HandleFunc("/v1/{network}/leases", bindHandler(handleWatchLeases, ctx, sm)).Methods("GET")
 
 	l, err := net.Listen("tcp", listenAddr)
 	if err != nil {