Browse Source

leasehttp: move lease/http.go to its own pkg

Xiang Li 10 years ago
parent
commit
5e2dbadbc0
3 changed files with 10 additions and 8 deletions
  1. 2 2
      etcdserver/etcdhttp/peer.go
  2. 2 1
      etcdserver/v3demo_server.go
  3. 6 5
      lease/leasehttp/http.go

+ 2 - 2
etcdserver/etcdhttp/peer.go

@@ -19,7 +19,7 @@ import (
 	"net/http"
 
 	"github.com/coreos/etcd/etcdserver"
-	"github.com/coreos/etcd/lease"
+	"github.com/coreos/etcd/lease/leasehttp"
 	"github.com/coreos/etcd/rafthttp"
 )
 
@@ -32,7 +32,7 @@ const (
 func NewPeerHandler(s *etcdserver.EtcdServer) http.Handler {
 	var lh http.Handler
 	if l := s.Lessor(); l != nil {
-		lh = lease.NewHandler(l)
+		lh = leasehttp.NewHandler(l)
 	}
 	return newPeerHandler(s.Cluster(), s.RaftHandler(), lh)
 }

+ 2 - 1
etcdserver/v3demo_server.go

@@ -24,6 +24,7 @@ import (
 	"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
 	pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
 	"github.com/coreos/etcd/lease"
+	"github.com/coreos/etcd/lease/leasehttp"
 	dstorage "github.com/coreos/etcd/storage"
 	"github.com/coreos/etcd/storage/storagepb"
 )
@@ -139,7 +140,7 @@ func (s *EtcdServer) LeaseRenew(id lease.LeaseID) (int64, error) {
 
 	for _, url := range leader.PeerURLs {
 		lurl := url + "/leases"
-		ttl, err = lease.RenewHTTP(id, lurl, s.cfg.PeerTLSInfo, s.cfg.peerDialTimeout())
+		ttl, err = leasehttp.RenewHTTP(id, lurl, s.cfg.PeerTLSInfo, s.cfg.peerDialTimeout())
 		if err == nil {
 			break
 		}

+ 6 - 5
lease/http.go → lease/leasehttp/http.go

@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package lease
+package leasehttp
 
 import (
 	"bytes"
@@ -22,15 +22,16 @@ import (
 	"time"
 
 	pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
+	"github.com/coreos/etcd/lease"
 	"github.com/coreos/etcd/pkg/transport"
 )
 
 // NewHandler returns an http Handler for lease renewals
-func NewHandler(l Lessor) http.Handler {
+func NewHandler(l lease.Lessor) http.Handler {
 	return &leaseHandler{l}
 }
 
-type leaseHandler struct{ l Lessor }
+type leaseHandler struct{ l lease.Lessor }
 
 func (h *leaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 	if r.Method != "POST" {
@@ -50,7 +51,7 @@ func (h *leaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	ttl, err := h.l.Renew(LeaseID(lreq.ID))
+	ttl, err := h.l.Renew(lease.LeaseID(lreq.ID))
 	if err != nil {
 		http.Error(w, err.Error(), http.StatusBadRequest)
 		return
@@ -69,7 +70,7 @@ func (h *leaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 }
 
 // RenewHTTP renews a lease at a given primary server.
-func RenewHTTP(id LeaseID, url string, tlsInfo transport.TLSInfo, timeout time.Duration) (int64, error) {
+func RenewHTTP(id lease.LeaseID, url string, tlsInfo transport.TLSInfo, timeout time.Duration) (int64, error) {
 	// will post lreq protobuf to leader
 	lreq, err := (&pb.LeaseKeepAliveRequest{ID: int64(id)}).Marshal()
 	if err != nil {