github.com/yasker/longhorn-engine@v0.0.0-20160621014712-6ed6cfca0729/controller/rest/router.go (about)

     1  package rest
     2  
     3  import (
     4  	"github.com/gorilla/mux"
     5  	"github.com/rancher/go-rancher/api"
     6  	"github.com/rancher/longhorn/replica/rest"
     7  )
     8  
     9  func NewRouter(s *Server) *mux.Router {
    10  	schemas := NewSchema()
    11  	router := mux.NewRouter().StrictSlash(true)
    12  	f := rest.HandleError
    13  
    14  	// API framework routes
    15  	router.Methods("GET").Path("/").Handler(api.VersionsHandler(schemas, "v1"))
    16  	router.Methods("GET").Path("/v1/schemas").Handler(api.SchemasHandler(schemas))
    17  	router.Methods("GET").Path("/v1/schemas/{id}").Handler(api.SchemaHandler(schemas))
    18  	router.Methods("GET").Path("/v1").Handler(api.VersionHandler(schemas, "v1"))
    19  
    20  	// Volumes
    21  	router.Methods("GET").Path("/v1/volumes").Handler(f(schemas, s.ListVolumes))
    22  	router.Methods("GET").Path("/v1/volumes/{id}").Handler(f(schemas, s.GetVolume))
    23  	router.Methods("POST").Path("/v1/volumes/{id}").Queries("action", "start").Handler(f(schemas, s.StartVolume))
    24  	router.Methods("POST").Path("/v1/volumes/{id}").Queries("action", "shutdown").Handler(f(schemas, s.ShutdownVolume))
    25  	router.Methods("POST").Path("/v1/volumes/{id}").Queries("action", "snapshot").Handler(f(schemas, s.SnapshotVolume))
    26  	router.Methods("POST").Path("/v1/volumes/{id}").Queries("action", "revert").Handler(f(schemas, s.RevertVolume))
    27  
    28  	// Replicas
    29  	router.Methods("GET").Path("/v1/replicas").Handler(f(schemas, s.ListReplicas))
    30  	router.Methods("GET").Path("/v1/replicas/{id}").Handler(f(schemas, s.GetReplica))
    31  	router.Methods("POST").Path("/v1/replicas").Handler(f(schemas, s.CreateReplica))
    32  	router.Methods("DELETE").Path("/v1/replicas/{id}").Handler(f(schemas, s.DeleteReplica))
    33  	router.Methods("PUT").Path("/v1/replicas/{id}").Handler(f(schemas, s.UpdateReplica))
    34  
    35  	// Journal
    36  	router.Methods("POST").Path("/v1/journal").Handler(f(schemas, s.ListJournal))
    37  
    38  	return router
    39  }