2017-01-11 08:12:37 +00:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"path"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
|
|
|
|
"sunteng/cronsun/conf"
|
|
|
|
)
|
|
|
|
|
|
|
|
func InitRouters() (s *http.Server, err error) {
|
|
|
|
jobHandler := &Job{}
|
|
|
|
nodeHandler := &Node{}
|
|
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
|
subrouter := r.PathPrefix("/v1").Subrouter()
|
|
|
|
|
2017-01-16 06:30:55 +00:00
|
|
|
// get a job group list
|
2017-01-11 08:12:37 +00:00
|
|
|
h := BaseHandler{Handle: jobHandler.GetGroups}
|
|
|
|
subrouter.Handle("/job/groups", h).Methods("GET")
|
2017-01-16 06:30:55 +00:00
|
|
|
// get a job group by group name
|
2017-01-11 08:12:37 +00:00
|
|
|
h = BaseHandler{Handle: jobHandler.GetListByGroupName}
|
|
|
|
subrouter.Handle("/job/group/{name}", h).Methods("GET")
|
2017-01-16 06:30:55 +00:00
|
|
|
// create/update a job
|
|
|
|
h = BaseHandler{Handle: jobHandler.UpdateJob}
|
2017-01-11 08:12:37 +00:00
|
|
|
subrouter.Handle("/job", h).Methods("PUT")
|
2017-01-22 07:18:08 +00:00
|
|
|
// pause/start
|
|
|
|
h = BaseHandler{Handle: jobHandler.ChangeJobStatus}
|
|
|
|
subrouter.Handle("/job/{group}-{id}", h).Methods("POST")
|
2017-01-16 06:30:55 +00:00
|
|
|
// get a job
|
|
|
|
h = BaseHandler{Handle: jobHandler.GetJob}
|
|
|
|
subrouter.Handle("/job/{group}-{id}", h).Methods("GET")
|
|
|
|
// remove a job
|
|
|
|
h = BaseHandler{Handle: jobHandler.DeleteJob}
|
|
|
|
subrouter.Handle("/job/{group}-{id}", h).Methods("DELETE")
|
2017-01-11 08:12:37 +00:00
|
|
|
|
2017-01-18 08:58:47 +00:00
|
|
|
h = BaseHandler{Handle: nodeHandler.GetActivityNodeList}
|
|
|
|
subrouter.Handle("/node/activitys", h).Methods("GET")
|
2017-01-12 08:35:30 +00:00
|
|
|
// get node group list
|
2017-01-11 08:12:37 +00:00
|
|
|
h = BaseHandler{Handle: nodeHandler.GetGroups}
|
|
|
|
subrouter.Handle("/node/groups", h).Methods("GET")
|
2017-01-12 08:35:30 +00:00
|
|
|
// get a node group by group id
|
|
|
|
h = BaseHandler{Handle: nodeHandler.GetGroupByGroupId}
|
|
|
|
subrouter.Handle("/node/group/{id}", h).Methods("GET")
|
|
|
|
// create/update a node group
|
|
|
|
h = BaseHandler{Handle: nodeHandler.UpdateGroup}
|
2017-01-11 08:12:37 +00:00
|
|
|
subrouter.Handle("/node/group", h).Methods("PUT")
|
2017-01-12 08:35:30 +00:00
|
|
|
// delete a node group
|
|
|
|
h = BaseHandler{Handle: nodeHandler.DeleteGroup}
|
2017-01-11 08:12:37 +00:00
|
|
|
subrouter.Handle("/node/group", h).Methods("DELETE")
|
|
|
|
|
|
|
|
uidir := conf.Config.Web.UIDir
|
|
|
|
if len(uidir) == 0 {
|
|
|
|
uidir = path.Join(conf.Config.Root, "web", "ui")
|
|
|
|
}
|
|
|
|
r.PathPrefix("/ui/").Handler(http.StripPrefix("/ui/", http.FileServer(http.Dir(uidir))))
|
|
|
|
|
|
|
|
s = &http.Server{
|
|
|
|
Handler: r,
|
|
|
|
}
|
|
|
|
return s, nil
|
|
|
|
}
|