示例#1
0
func ServiceStream(rw http.ResponseWriter, r *http.Request) {
	log := servicesLogger("stream").Start()

	service, err := models.GetServiceFromName(mux.Vars(r)["service"])

	if err != nil {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	logs := make(chan []byte)
	done := make(chan bool)

	service.SubscribeLogs(logs, done)

	ws, err := upgrader.Upgrade(rw, r, nil)

	if err != nil {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	log.Success("step=upgrade service=%q", service.Name)

	defer ws.Close()

	for data := range logs {
		ws.WriteMessage(websocket.TextMessage, data)
	}

	log.Success("step=ended service=%q", service.Name)
}
示例#2
0
func ServiceDelete(rw http.ResponseWriter, r *http.Request) {
	log := servicesLogger("delete").Start()

	vars := mux.Vars(r)
	name := vars["service"]

	service, err := models.GetServiceFromName(name)

	if err != nil {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	log.Success("step=services.get service=%q", service.Name)

	err = service.Delete()

	if err != nil {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	log.Success("step=service.delete service=%q", service.Name)

	RenderText(rw, "ok")
}
示例#3
0
func ServiceLogs(rw http.ResponseWriter, r *http.Request) {
	name := mux.Vars(r)["service"]

	service, err := models.GetServiceFromName(name)

	if err != nil {
		RenderError(rw, err)
		return
	}

	RenderPartial(rw, "service", "logs", service)
}
示例#4
0
func ServiceStatus(rw http.ResponseWriter, r *http.Request) {
	log := servicesLogger("show").Start()

	name := mux.Vars(r)["service"]
	service, err := models.GetServiceFromName(name)

	if err != nil {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	RenderText(rw, service.Status)
}
示例#5
0
func ServiceShow(rw http.ResponseWriter, r *http.Request) {
	log := servicesLogger("show").Start()

	name := mux.Vars(r)["service"]

	service, err := models.GetServiceFromName(name)

	if err != nil {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	// sort.Sort(services)

	RenderTemplate(rw, "service", service)
}