當前位置: 首頁>>代碼示例>>Golang>>正文


Golang models.GetService函數代碼示例

本文整理匯總了Golang中github.com/convox/rack/api/models.GetService函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetService函數的具體用法?Golang GetService怎麽用?Golang GetService使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了GetService函數的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ServiceDelete

func ServiceDelete(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	service := mux.Vars(r)["service"]

	s, err := models.GetService(service)

	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such service: %s", service)
	}

	if err != nil {
		return httperr.Server(err)
	}

	err = s.Delete()

	if err != nil {
		return httperr.Server(err)
	}

	s, err = models.GetService(service)

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, s)
}
開發者ID:gisnalbert,項目名稱:rack,代碼行數:27,代碼來源:services.go

示例2: ServiceDelete

func ServiceDelete(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	service := mux.Vars(r)["service"]

	s, err := models.GetService(service)
	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such service: %s", service)
	}
	if err != nil {
		return httperr.Server(err)
	}

	// new services should use the provider interfaces
	if s.Type == "syslog" {
		s, err := provider.ServiceDelete(service)
		if err != nil {
			return httperr.Server(err)
		}

		return RenderJson(rw, s)
	}

	err = s.Delete()
	if err != nil {
		return httperr.Server(err)
	}

	s, err = models.GetService(service)
	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, s)
}
開發者ID:cleblanc87,項目名稱:rack,代碼行數:33,代碼來源:services.go

示例3: ServiceDelete

func ServiceDelete(rw http.ResponseWriter, r *http.Request) error {
	service := mux.Vars(r)["service"]

	s, err := models.GetService(service)

	if awsError(err) == "ValidationError" {
		return RenderNotFound(rw, fmt.Sprintf("no such service: %s", service))
	}

	if err != nil {
		return err
	}

	err = s.Delete()

	if err != nil {
		return err
	}

	s, err = models.GetService(service)

	if err != nil {
		return err
	}

	return RenderJson(rw, s)
}
開發者ID:jbuck,項目名稱:rack,代碼行數:27,代碼來源:services.go

示例4: ServiceCreate

func ServiceCreate(rw http.ResponseWriter, r *http.Request) error {
	name := GetForm(r, "name")
	t := GetForm(r, "type")

	service := &models.Service{
		Name: name,
		Type: t,
	}

	err := service.Create()

	if awsError(err) == "ValidationError" {
		return RenderForbidden(rw, fmt.Sprintf("invalid service name: %s", name))
	}

	if err != nil {
		return err
	}

	service, err = models.GetService(name)

	if err != nil {
		return err
	}

	return RenderJson(rw, service)
}
開發者ID:jbuck,項目名稱:rack,代碼行數:27,代碼來源:services.go

示例5: ServiceUpdate

func ServiceUpdate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	service := mux.Vars(r)["service"]

	s, err := models.GetService(service)

	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such service: %s", service)
	}

	if err != nil {
		return httperr.Server(err)
	}

	err = r.ParseForm()
	if err != nil {
		return httperr.Server(err)
	}

	// get the last set value for all form values
	// ie:  foo=1&foo=2  sets foo to "2"
	params := make(map[string]string)
	for key, values := range r.Form {
		val := values[len(values)-1]
		params[key] = val
	}

	err = s.Update(models.CFParams(params))

	if err != nil && awsError(err) == "ValidationError" {
		e := err.(awserr.Error)
		return httperr.Errorf(403, convoxifyCloudformationError(e.Message()))
	}

	if err != nil {
		return httperr.Server(err)
	}

	s, err = models.GetService(service)

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, s)
}
開發者ID:cleblanc87,項目名稱:rack,代碼行數:45,代碼來源:services.go

示例6: ServiceCreate

func ServiceCreate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	err := r.ParseForm()
	if err != nil {
		return httperr.Server(err)
	}

	// get the last set value for all form values
	// ie:  foo=1&foo=2  sets foo to "2"
	params := make(map[string]string)
	for key, values := range r.Form {
		val := values[len(values)-1]
		params[key] = val
	}
	name := params["name"]
	delete(params, "name")
	kind := params["type"]
	delete(params, "type")

	// Early check for unbound service only.
	service, err := models.GetServiceUnbound(name)

	if err == nil {
		return httperr.Errorf(403, "there is already a legacy service named %s (%s). We recommend you delete this service and create it again.", name, service.Status)
	}

	if awsError(err) == "ValidationError" {
		// If unbound check fails this will result in a bound service.
		service = &models.Service{
			Name:       name,
			Type:       kind,
			Parameters: models.CFParams(params),
		}
	}

	err = service.Create()

	if err != nil && strings.HasSuffix(err.Error(), "not found") {
		return httperr.Errorf(403, "invalid service type: %s", kind)
	}

	if err != nil && awsError(err) == "ValidationError" {
		e := err.(awserr.Error)
		return httperr.Errorf(403, convoxifyCloudformationError(e.Message()))
	}

	if err != nil {
		return httperr.Server(err)
	}

	service, err = models.GetService(name)

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, service)
}
開發者ID:soulware,項目名稱:rack,代碼行數:57,代碼來源:services.go

示例7: LinkCreate

func LinkCreate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	service := mux.Vars(r)["service"]

	s, err := models.GetService(service)
	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such service: %s", service)
	}
	if err != nil {
		return httperr.Server(err)
	}

	if s.Status != "running" {
		return httperr.Errorf(403, "can not link service with status: %s", s.Status)
	}

	// new services should use the provider interfaces
	if s.Type == "syslog" {
		s, err := provider.ServiceLink(service, GetForm(r, "app"), GetForm(r, "process"))
		if err != nil {
			return httperr.Server(err)
		}

		return RenderJson(rw, s)
	}

	if s.Type != "papertrail" {
		return httperr.Errorf(403, "linking is not yet implemented for service type: %s", s.Type)
	}

	app := GetForm(r, "app")

	a, err := models.GetApp(app)

	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such app: %s", app)
	}

	if err != nil {
		return httperr.Server(err)
	}

	err = s.LinkPapertrail(*a)

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, s)
}
開發者ID:cleblanc87,項目名稱:rack,代碼行數:49,代碼來源:links.go

示例8: ServiceCreate

func ServiceCreate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	err := r.ParseForm()
	if err != nil {
		return httperr.Server(err)
	}

	// get the last set value for all form values
	// ie:  foo=1&foo=2  sets foo to "2"
	params := make(map[string]string)
	for key, values := range r.Form {
		val := values[len(values)-1]
		params[key] = val
	}
	name := params["name"]
	delete(params, "name")
	kind := params["type"]
	delete(params, "type")

	service := &models.Service{
		Name:       name,
		Type:       kind,
		Parameters: models.CFParams(params),
	}

	err = service.Create()

	if err != nil && strings.HasSuffix(err.Error(), "not found") {
		return httperr.Errorf(403, "invalid service type: %s", kind)
	}

	if err != nil && awsError(err) == "ValidationError" {
		e := err.(awserr.Error)
		return httperr.Errorf(403, convoxifyCloudformationError(e.Message()))
	}

	if err != nil {
		return httperr.Server(err)
	}

	service, err = models.GetService(name)

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, service)
}
開發者ID:anthonyrisinger,項目名稱:rack,代碼行數:47,代碼來源:services.go

示例9: ServiceCreate

func ServiceCreate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	name := GetForm(r, "name")
	t := GetForm(r, "type")
	url := GetForm(r, "url")

	service := &models.Service{
		Name: name,
		Type: t,
		URL:  url,
	}

	var err error

	switch t {
	case "papertrail":
		err = service.CreatePapertrail()
	case "webhook":
		err = service.CreateWebhook()
	default:
		err = service.CreateDatastore()
	}

	if err != nil && strings.HasSuffix(err.Error(), "not found") {
		return httperr.Errorf(403, "invalid service type: %s", t)
	}

	if err != nil && awsError(err) == "ValidationError" {
		return httperr.Errorf(403, "invalid service name: %s", name)
	}

	if err != nil {
		return httperr.Server(err)
	}

	service, err = models.GetService(name)

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, service)
}
開發者ID:gisnalbert,項目名稱:rack,代碼行數:42,代碼來源:services.go

示例10: ServiceLogs

func ServiceLogs(ws *websocket.Conn) error {
	service := mux.Vars(ws.Request())["service"]

	s, err := models.GetService(service)

	if err != nil {
		return err
	}

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

	s.SubscribeLogs(logs, done)

	for data := range logs {
		ws.Write(data)
	}

	return nil
}
開發者ID:harryross,項目名稱:rack,代碼行數:20,代碼來源:services.go

示例11: LinkDelete

func LinkDelete(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	app := mux.Vars(r)["app"]
	service := mux.Vars(r)["service"]

	s, err := models.GetService(service)

	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such service: %s", service)
	}

	if err != nil {
		return httperr.Server(err)
	}

	if s.Status != "running" {
		return httperr.Errorf(403, "can not unlink service with status: %s", s.Status)
	}

	if s.Type != "papertrail" {
		return httperr.Errorf(403, "unlinking is not yet implemented for service type: %s", s.Type)
	}

	a, err := models.GetApp(app)

	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such app: %s", app)
	}

	if err != nil {
		return httperr.Server(err)
	}

	err = s.UnlinkPapertrail(*a)

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, s)
}
開發者ID:anthonyrisinger,項目名稱:rack,代碼行數:40,代碼來源:links.go

示例12: ServiceLogs

func ServiceLogs(ws *websocket.Conn) *httperr.Error {
	service := mux.Vars(ws.Request())["service"]

	s, err := models.GetService(service)

	if err != nil {
		return httperr.Server(err)
	}

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

	s.SubscribeLogs(logs, done)

	go signalWsClose(ws, done)

	for data := range logs {
		ws.Write(data)
	}

	return nil
}
開發者ID:gisnalbert,項目名稱:rack,代碼行數:22,代碼來源:services.go


注:本文中的github.com/convox/rack/api/models.GetService函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。