本文整理汇总了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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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
}
示例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)
}
示例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
}