github.com/kula/etcd@v0.2.1-0.20131226070625-e96234382ac0/mod/lock/v2/handler.go (about)

     1  package v2
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/gorilla/mux"
     7  	"github.com/coreos/go-etcd/etcd"
     8  )
     9  
    10  const prefix = "/_etcd/mod/lock"
    11  
    12  // handler manages the lock HTTP request.
    13  type handler struct {
    14  	*mux.Router
    15  	client *etcd.Client
    16  }
    17  
    18  // NewHandler creates an HTTP handler that can be registered on a router.
    19  func NewHandler(addr string) (http.Handler) {
    20  	h := &handler{
    21  		Router: mux.NewRouter(),
    22  		client: etcd.NewClient([]string{addr}),
    23  	}
    24  	h.StrictSlash(false)
    25  	h.HandleFunc("/{key:.*}", h.getIndexHandler).Methods("GET")
    26  	h.HandleFunc("/{key:.*}", h.acquireHandler).Methods("POST")
    27  	h.HandleFunc("/{key:.*}", h.renewLockHandler).Methods("PUT")
    28  	h.HandleFunc("/{key:.*}", h.releaseLockHandler).Methods("DELETE")
    29  	return h
    30  }