• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang helpers.Error函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/convox/kernel/helpers.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: ServiceStream

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)
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:34,代码来源:services.go


示例2: ServiceCreate

func ServiceCreate(rw http.ResponseWriter, r *http.Request) {
	log := servicesLogger("create").Start()

	name := GetForm(r, "name")
	t := GetForm(r, "type")

	password, err := rand_password(20)

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

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

	err = service.Create()

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

	Redirect(rw, r, "/services")
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:30,代码来源:services.go


示例3: ReleasePromote

func ReleasePromote(rw http.ResponseWriter, r *http.Request) {
	log := releasesLogger("promote").Start()

	vars := mux.Vars(r)
	app := vars["app"]
	release := vars["release"]

	rel, err := models.GetRelease(app, release)

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

	err = rel.Promote()

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

	log.Success("step=release.promote app=%q", app)

	RenderText(rw, "ok")
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:27,代码来源:releases.go


示例4: AppCreate

func AppCreate(rw http.ResponseWriter, r *http.Request) {
	log := appsLogger("create").Start()

	name := GetForm(r, "name")
	repo := GetForm(r, "repo")

	app := &models.App{
		Name:       name,
		Repository: repo,
	}

	err := app.Create()

	if awsError(err) == "AlreadyExistsException" {
		err = fmt.Errorf("There is already an app named %s", name)
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

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

	Redirect(rw, r, fmt.Sprintf("/apps/%s", name))
}
开发者ID:oren,项目名称:kernel,代码行数:28,代码来源:apps.go


示例5: ProcessRunAttached

func ProcessRunAttached(ws *websocket.Conn) {
	defer ws.Close()

	log := processesLogger("run.attached").Start()

	vars := mux.Vars(ws.Request())
	app := vars["app"]
	process := vars["process"]
	command := ws.Request().Header.Get("Command")

	ps, err := models.GetProcess(app, process)

	if err != nil {
		helpers.Error(log, err)
		ws.Write([]byte(fmt.Sprintf("error: %s\n", err)))
		return
	}

	log.Success("step=upgrade app=%q", ps.App)

	defer ws.Close()

	err = ps.RunAttached(command, ws)

	if err != nil {
		helpers.Error(log, err)
		ws.Write([]byte(fmt.Sprintf("error: %s\n", err)))
		return
	}

	log.Success("step=ended app=%q", ps.App)
}
开发者ID:2opremio,项目名称:kernel,代码行数:32,代码来源:processes.go


示例6: EnvironmentDelete

func EnvironmentDelete(rw http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)

	app := vars["app"]
	name := vars["name"]

	env, err := models.GetEnvironment(app)

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

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

	delete(env, name)

	err = models.PutEnvironment(app, env)

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

	RenderText(rw, "ok")
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:31,代码来源:environment.go


示例7: EnvironmentCreate

func EnvironmentCreate(rw http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)

	app := vars["app"]
	name := vars["name"]
	value := GetForm(r, "value")

	env, err := models.GetEnvironment(app)

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

	env[strings.ToUpper(name)] = value

	err = models.PutEnvironment(app, env)

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

	RenderText(rw, "ok")
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:27,代码来源:environment.go


示例8: ServiceDelete

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")
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:28,代码来源:services.go


示例9: AppDelete

func AppDelete(rw http.ResponseWriter, r *http.Request) {
	log := appsLogger("delete").Start()

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

	app, err := models.GetApp(name)

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

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

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

	err = app.Delete()

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

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

	RenderText(rw, "ok")
}
开发者ID:oren,项目名称:kernel,代码行数:33,代码来源:apps.go


示例10: BuildLogs

func BuildLogs(ws *websocket.Conn) {
	defer ws.Close()

	log := buildsLogger("logs").Start()

	vars := mux.Vars(ws.Request())
	id := vars["build"]

	log.Success("step=upgrade build=%q", id)

	defer ws.Close()

	// proxy to docker container logs
	// https://docs.docker.com/reference/api/docker_remote_api_v1.19/#get-container-logs
	client, err := docker.NewClient("unix:///var/run/docker.sock")

	if err != nil {
		helpers.Error(log, err)
		ws.Write([]byte(fmt.Sprintf("error: %s\n", err)))
		return
	}

	r, w := io.Pipe()

	quit := make(chan bool)

	go scanLines(r, ws)
	go keepAlive(ws, quit)

	err = client.Logs(docker.LogsOptions{
		Container:    fmt.Sprintf("build-%s", id),
		Follow:       true,
		Stdout:       true,
		Stderr:       true,
		Tail:         "all",
		RawTerminal:  false,
		OutputStream: w,
		ErrorStream:  w,
	})

	quit <- true

	if err != nil {
		helpers.Error(log, err)
		ws.Write([]byte(fmt.Sprintf("error: %s\n", err)))
		return
	}
}
开发者ID:csquared,项目名称:kernel,代码行数:48,代码来源:builds.go


示例11: SystemShow

func SystemShow(rw http.ResponseWriter, r *http.Request) {
	log := systemLogger("show").Start()

	rack := os.Getenv("RACK")

	a, err := models.GetApp(rack)

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

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

	switch r.Header.Get("Content-Type") {
	case "application/json":
		RenderJson(rw, a)
	default:
		RenderTemplate(rw, "app", a)
	}
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:25,代码来源:system.go


示例12: AppShow

func AppShow(rw http.ResponseWriter, r *http.Request) {
	log := appsLogger("show").Start()

	app := mux.Vars(r)["app"]

	a, err := models.GetApp(app)

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

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

	switch r.Header.Get("Content-Type") {
	case "application/json":
		RenderJson(rw, a)
	default:
		RenderTemplate(rw, "app", a)
	}
}
开发者ID:oren,项目名称:kernel,代码行数:25,代码来源:apps.go


示例13: AppEnvironment

func AppEnvironment(rw http.ResponseWriter, r *http.Request) {
	log := appsLogger("environment").Start()

	app := mux.Vars(r)["app"]

	env, err := models.GetEnvironment(app)

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

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

	params := map[string]interface{}{
		"App":         app,
		"Environment": env,
	}

	switch r.Header.Get("Content-Type") {
	case "application/json":
		RenderJson(rw, params["Environment"])
	default:
		RenderPartial(rw, "app", "environment", params)
	}
}
开发者ID:oren,项目名称:kernel,代码行数:30,代码来源:apps.go


示例14: AppEvents

func AppEvents(rw http.ResponseWriter, r *http.Request) {
	log := appsLogger("events").Start()

	app := mux.Vars(r)["app"]

	events, err := models.ListECSEvents(app)

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

	for i, _ := range events {
		match := regexServiceCleaner.FindStringSubmatch(events[i].Message)

		if len(match) == 3 {
			events[i].Message = fmt.Sprintf("[ECS] (%s) %s", match[1], match[2])
		}
	}

	es, err := models.ListEvents(app)

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

	for _, e := range es {
		events = append(events, models.ServiceEvent{
			Message:   fmt.Sprintf("[CFM] (%s) %s %s", e.Name, e.Status, e.Reason),
			CreatedAt: e.Time,
		})
	}

	sort.Sort(sort.Reverse(events))

	data := ""

	for _, e := range events {
		data += fmt.Sprintf("%s: %s\n", e.CreatedAt.Format(time.RFC3339), e.Message)
	}

	RenderText(rw, data)
}
开发者ID:oren,项目名称:kernel,代码行数:46,代码来源:apps.go


示例15: AppReleases

func AppReleases(rw http.ResponseWriter, r *http.Request) {
	log := appsLogger("releases").Start()

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

	l := map[string]string{
		"id":      r.URL.Query().Get("id"),
		"created": r.URL.Query().Get("created"),
	}

	a, err := models.GetApp(app)

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

	releases, err := models.ListReleases(app, l)

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

	params := map[string]interface{}{
		"App":      a,
		"Releases": releases,
	}

	if len(releases) > 0 {
		params["Last"] = releases[len(releases)-1]
	}

	switch r.Header.Get("Content-Type") {
	case "application/json":
		RenderJson(rw, releases)
	default:
		RenderPartial(rw, "app", "releases", params)
	}
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:43,代码来源:apps.go


示例16: SettingsUpdate

func SettingsUpdate(rw http.ResponseWriter, r *http.Request) {
	err := models.SettingSet("github", GetForm(r, "github"))

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

	err = models.SettingSet("heroku", GetForm(r, "heroku"))

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

	Redirect(rw, r, "/settings")
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:19,代码来源:settings.go


示例17: AppStream

func AppStream(rw http.ResponseWriter, r *http.Request) {
	log := appsLogger("stream").Start()

	app := mux.Vars(r)["app"]

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

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

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

	defer ws.Close()

	a, err := models.GetApp(mux.Vars(r)["app"])

	if awsError(err) == "ValidationError" {
		ws.WriteMessage(websocket.TextMessage, []byte(fmt.Sprintf("ERROR: no such app: %s\n", app)))
		return
	}

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

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

	a.SubscribeLogs(logs, done)

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

	log.Success("step=ended app=%q", app)
}
开发者ID:oren,项目名称:kernel,代码行数:41,代码来源:apps.go


示例18: ProcessRun

func ProcessRun(rw http.ResponseWriter, r *http.Request) {
	log := processesLogger("run").Start()

	vars := mux.Vars(r)
	app := vars["app"]
	process := vars["process"]
	command := GetForm(r, "command")

	_, err := models.GetApp(app)

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

	ps, err := models.GetProcess(app, process)

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

	if ps == nil {
		RenderNotFound(rw, fmt.Sprintf("no such process: %s", process))
		return
	}

	err = ps.Run(models.ProcessRunOptions{
		Command: command,
		Process: process,
	})

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

	RenderText(rw, "ok")
}
开发者ID:2opremio,项目名称:kernel,代码行数:41,代码来源:processes.go


示例19: ServiceList

func ServiceList(rw http.ResponseWriter, r *http.Request) {
	log := servicesLogger("list").Start()

	services, err := models.ListServiceStacks()

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

	RenderJson(rw, services)
}
开发者ID:2opremio,项目名称:kernel,代码行数:13,代码来源:services.go


示例20: AppStatus

func AppStatus(rw http.ResponseWriter, r *http.Request) {
	log := appsLogger("status").Start()

	app, err := models.GetApp(mux.Vars(r)["app"])

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

	RenderText(rw, app.Status)
}
开发者ID:oren,项目名称:kernel,代码行数:13,代码来源:apps.go



注:本文中的github.com/convox/kernel/helpers.Error函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang models.GetApp函数代码示例发布时间:2022-05-23
下一篇:
Golang websocket.Conn类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap