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

Golang httperr.Server函数代码示例

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

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



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

示例1: BuildDelete

// BuildDelete deletes a build. Makes sure not to delete a build that is contained in the active release
func BuildDelete(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	vars := mux.Vars(r)
	appName := vars["app"]
	buildID := vars["build"]

	active, err := isBuildActive(appName, buildID)
	if err != nil {
		return httperr.Errorf(404, err.Error())
	}
	if active {
		return httperr.Errorf(400, "cannot delete build contained in active release")
	}

	err = models.Provider().ReleaseDelete(appName, buildID)
	if err != nil {
		return httperr.Server(err)
	}

	build, err := models.Provider().BuildDelete(appName, buildID)
	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, build)
}
开发者ID:gmelika,项目名称:rack,代码行数:26,代码来源:builds.go


示例2: BuildGet

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

	b, err := models.Provider().BuildGet(app, build)
	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such app: %s", app)
	}
	if err != nil && strings.HasPrefix(err.Error(), "no such build") {
		return httperr.Errorf(404, err.Error())
	}
	if err != nil {
		return httperr.Server(err)
	}

	l, err := models.Provider().BuildLogs(app, build)
	if err != nil {
		return httperr.Server(err)
	}

	b.Logs = l

	return RenderJson(rw, b)
}
开发者ID:gmelika,项目名称:rack,代码行数:25,代码来源:builds.go


示例3: findBuildHost

// try to find the docker host that's running a build
// try a few times with a sleep
func findBuildHost(build string) (string, error) {
	for i := 1; i < 5; i++ {
		pss, err := models.ListProcesses(os.Getenv("RACK"))
		if err != nil {
			return "", httperr.Server(err)
		}

		for _, ps := range pss {
			client, err := ps.Docker()
			if err != nil {
				return "", httperr.Server(err)
			}

			res, err := client.ListContainers(docker.ListContainersOptions{
				All: true,
				Filters: map[string][]string{
					"name": []string{fmt.Sprintf("build-%s", build)},
				},
			})

			if len(res) > 0 {
				return fmt.Sprintf("http://%s:2376", ps.Host), nil
			}
		}

		time.Sleep(2 * time.Second)
	}

	return "", fmt.Errorf("could not find build host")
}
开发者ID:gmelika,项目名称:rack,代码行数:32,代码来源:builds.go


示例4: AppCreate

func AppCreate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	name := r.FormValue("name")

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

	err := app.Create()

	if awsError(err) == "AlreadyExistsException" {
		app, err := models.GetApp(name)

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

		return httperr.Errorf(403, "there is already an app named %s (%s)", name, app.Status)
	}

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

	app, err = models.GetApp(name)

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

	return RenderJson(rw, app)
}
开发者ID:anthonyrisinger,项目名称:rack,代码行数:31,代码来源:apps.go


示例5: EnvironmentDelete

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

	env, err := models.GetEnvironment(app)

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

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

	delete(env, name)

	releaseId, err := models.PutEnvironment(app, env)

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

	rw.Header().Set("Release-Id", releaseId)

	env, err = models.GetEnvironment(app)

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

	return RenderJson(rw, env)
}
开发者ID:cleblanc87,项目名称:rack,代码行数:33,代码来源:environment.go


示例6: IndexUpload

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

	file, _, err := r.FormFile("data")
	if err != nil {
		return httperr.Server(err)
	}

	data, err := ioutil.ReadAll(file)
	if err != nil {
		return httperr.Server(err)
	}

	sum := sha256.Sum256(data)

	if hash != hex.EncodeToString(sum[:]) {
		return httperr.New(403, fmt.Errorf("invalid hash"))
	}

	err = provider.IndexUpload(hash, data)
	if err != nil {
		return httperr.Server(err)
	}

	return RenderSuccess(rw)
}
开发者ID:cleblanc87,项目名称:rack,代码行数:26,代码来源:index.go


示例7: ParametersSet

func ParametersSet(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	app := mux.Vars(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)
	}

	r.ParseMultipartForm(2048)

	params := map[string]string{}

	for key, values := range r.Form {
		params[key] = values[0]
	}

	err = a.UpdateParams(params)

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

	return RenderSuccess(rw)
}
开发者ID:soulware,项目名称:rack,代码行数:29,代码来源:parameters.go


示例8: EnvironmentSet

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

	app := vars["app"]

	_, err := models.GetEnvironment(app)

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

	body, err := ioutil.ReadAll(r.Body)

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

	releaseId, err := models.PutEnvironment(app, models.LoadEnvironment(body))

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

	rw.Header().Set("Release-Id", releaseId)

	env, err := models.GetEnvironment(app)

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

	return RenderJson(rw, env)
}
开发者ID:cleblanc87,项目名称:rack,代码行数:33,代码来源:environment.go


示例9: AppCreate

func AppCreate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	name := r.FormValue("name")
	if name == os.Getenv("RACK") {
		return httperr.Errorf(403, "application name cannot match rack name (%s). Please choose a different name for your app.", name)
	}

	// Early check for unbound app only.
	if app, err := models.GetAppUnbound(name); err == nil {
		return httperr.Errorf(403, "there is already a legacy app named %s (%s). We recommend you delete this app and create it again.", name, app.Status)
	}

	// If unbound check fails this will result in a bound app.
	app := &models.App{Name: name}
	err := app.Create()

	if awsError(err) == "AlreadyExistsException" {
		app, err := models.GetApp(name)
		if err != nil {
			return httperr.Server(err)
		}

		return httperr.Errorf(403, "there is already an app named %s (%s)", name, app.Status)
	}

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

	app, err = models.GetApp(name)
	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, app)
}
开发者ID:gmelika,项目名称:rack,代码行数:35,代码来源:apps.go


示例10: AppDelete

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

	app, err := models.GetApp(name)

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

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

	if app.Tags["Type"] != "app" || app.Tags["System"] != "convox" || app.Tags["Rack"] != os.Getenv("RACK") {
		return httperr.Errorf(404, "invalid app: %s", name)
	}

	err = app.Delete()

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

	return RenderSuccess(rw)
}
开发者ID:soulware,项目名称:rack,代码行数:25,代码来源:apps.go


示例11: RegistryDelete

func RegistryDelete(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	// server := mux.Vars(r)["server"]
	server := r.FormValue("server")

	env, acs, err := models.GetPrivateRegistriesAuth()

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

	ac, ok := acs[server]

	if !ok {
		return httperr.Errorf(404, "no such registry: %s", server)
	}

	models.DockerLogout(ac)
	delete(acs, server)

	dat, err := json.Marshal(acs)

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

	env["DOCKER_AUTH_DATA"] = string(dat)

	err = models.PutRackSettings(env)

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

	return RenderJson(rw, ac)
}
开发者ID:soulware,项目名称:rack,代码行数:35,代码来源:registries.go


示例12: 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


示例13: 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


示例14: ProcessShow

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

	_, err := models.GetApp(app)

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

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

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

	err = p.FetchStats()

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

	return RenderJson(rw, p)
}
开发者ID:soulware,项目名称:rack,代码行数:25,代码来源:processes.go


示例15: ReleasePromote

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

	_, err := models.GetApp(app)

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

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

	if err != nil && strings.HasPrefix(err.Error(), "no such release") {
		return httperr.Errorf(404, "no such release: %s", release)
	}

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

	err = rr.Promote()

	if awsError(err) == "ValidationError" {
		return httperr.Errorf(403, err.(awserr.Error).Message())
	}

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

	return RenderJson(rw, rr)
}
开发者ID:nicolas-brousse,项目名称:rack,代码行数:33,代码来源:releases.go


示例16: SystemUpdate

func SystemUpdate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	rack, err := models.GetSystem()

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

	notifyData := map[string]string{}

	if count := GetForm(r, "count"); count != "" {
		count, err := strconv.Atoi(count)

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

		rack.Count = count

		notifyData["count"] = strconv.Itoa(count)
	}

	if t := GetForm(r, "type"); t != "" {
		rack.Type = t

		notifyData["type"] = t
	}

	if version := GetForm(r, "version"); version != "" {
		rack.Version = version

		notifyData["version"] = version
	}

	err = rack.Save()

	if awsError(err) == "ValidationError" {
		switch {
		case strings.Index(err.Error(), "No updates are to be performed") > -1:
			return httperr.Errorf(403, "no system updates are to be performed")
		case strings.Index(err.Error(), "can not be updated") > -1:
			return httperr.Errorf(403, "system is already updating")
		}
	}

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

	rack, err = models.GetSystem()

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

	models.NotifySuccess("system:update", notifyData)

	return RenderJson(rw, rack)
}
开发者ID:gisnalbert,项目名称:rack,代码行数:58,代码来源:system.go


示例17: 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


示例18: BuildUpdate

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

	b, err := provider.BuildGet(app, build)
	if err != nil {
		return httperr.Server(err)
	}

	if d := r.FormValue("description"); d != "" {
		b.Description = d
	}

	if m := r.FormValue("manifest"); m != "" {
		b.Manifest = m
	}

	if r := r.FormValue("reason"); r != "" {
		b.Reason = r
	}

	if s := r.FormValue("status"); s != "" {
		b.Status = s
		b.Ended = time.Now()
	}

	// if build was successful create a release
	if b.Status == "complete" && b.Manifest != "" {
		_, err := provider.BuildRelease(b)
		if err != nil {
			return httperr.Server(err)
		}
	}

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

	if b.Status == "failed" {
		provider.EventSend(&structs.Event{
			Action: "build:create",
			Data: map[string]string{
				"app": b.App,
				"id":  b.Id,
			},
		}, fmt.Errorf(b.Reason))
	}

	return RenderJson(rw, b)
}
开发者ID:cleblanc87,项目名称:rack,代码行数:52,代码来源:builds.go


示例19: 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


示例20: SystemUpdate

func SystemUpdate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	rack, err := provider.SystemGet()

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

	notifyData := map[string]string{}

	if count := GetForm(r, "count"); count != "" {
		count, err := strconv.Atoi(count)

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

		rack.Count = count

		notifyData["count"] = strconv.Itoa(count)
	}

	if t := GetForm(r, "type"); t != "" {
		rack.Type = t

		notifyData["type"] = t
	}

	if version := GetForm(r, "version"); version != "" {
		rack.Version = version

		notifyData["version"] = version
	}

	err = provider.SystemSave(*rack)

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

	rack, err = provider.SystemGet()

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

	models.NotifySuccess("rack:update", notifyData)

	return RenderJson(rw, rack)
}
开发者ID:soulware,项目名称:rack,代码行数:49,代码来源:system.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang models.GetApp函数代码示例发布时间:2022-05-23
下一篇:
Golang httperr.Errorf函数代码示例发布时间: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