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

Golang mux.Vars函数代码示例

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

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



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

示例1: 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:anthonyrisinger,项目名称:rack,代码行数:33,代码来源:environment.go


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


示例3: 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:anthonyrisinger,项目名称:rack,代码行数:33,代码来源:environment.go


示例4: IndexUpload

func IndexUpload(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	err := r.ParseMultipartForm(10 * 1024 * 1024)

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

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

	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 = models.IndexUpload(hash, data)

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

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


示例5: SSLDelete

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

	if process == "" {
		return httperr.Errorf(403, "must specify a process")
	}

	portn, err := strconv.Atoi(port)

	if err != nil {
		return httperr.Errorf(403, "port must be numeric")
	}

	ssl, err := models.DeleteSSL(app, process, portn)

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

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

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


示例6: SSLCreate

func SSLCreate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	a := mux.Vars(r)["app"]
	process := GetForm(r, "process")
	port := GetForm(r, "port")
	body := GetForm(r, "body")
	key := GetForm(r, "key")
	secure := GetForm(r, "secure")

	if process == "" {
		return httperr.Errorf(403, "must specify a process")
	}

	portn, err := strconv.Atoi(port)

	if err != nil {
		return httperr.Errorf(403, "port must be numeric")
	}

	ssl, err := models.CreateSSL(a, process, portn, body, key, (secure == "true"))

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

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

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


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


示例8: FormationSet

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

	_, err := models.GetApp(app)

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

	err = models.SetFormation(app, process, count, memory)

	if ae, ok := err.(awserr.Error); ok {
		if ae.Code() == "ValidationError" {
			switch {
			case strings.Index(ae.Error(), "No updates are to be performed") > -1:
				return httperr.Errorf(403, "no updates are to be performed: %s", app)
			case strings.Index(ae.Error(), "can not be updated") > -1:
				return httperr.Errorf(403, "app is already updating: %s", app)
			}
		}
	}

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

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


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


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


示例11: 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" {
		message := err.(awserr.Error).Message()
		return httperr.Errorf(403, message)
	}

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

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


示例12: ReleaseShow

func ReleaseShow(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)
	}

	fmt.Printf("err %+v\n", err)

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

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


示例13: AppLogs

func AppLogs(ws *websocket.Conn) *httperr.Error {
	app := mux.Vars(ws.Request())["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)
	}

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

	a.SubscribeLogs(logs, done)

	go signalWsClose(ws, done)

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

	return nil
}
开发者ID:soulware,项目名称:rack,代码行数:26,代码来源:apps.go


示例14: AppShow

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

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

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

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

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

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


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


示例16: FormationSet

func FormationSet(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)
	}

	// initialize to invalid values that indicate no change
	var count, memory int64 = -1, -1

	// update based on form input
	if cc := GetForm(r, "count"); cc != "" {
		if c, err := strconv.ParseInt(cc, 10, 64); err != nil {
			return httperr.Errorf(403, "count must be numeric")
		} else {
			count = c
		}
	}

	if mm := GetForm(r, "memory"); mm != "" {
		if m, err := strconv.ParseInt(mm, 10, 64); err != nil {
			return httperr.Errorf(403, "memory must be numeric")
		} else {
			memory = m
		}
	}

	err = models.SetFormation(app, process, count, memory)

	if ae, ok := err.(awserr.Error); ok {
		if ae.Code() == "ValidationError" {
			switch {
			case strings.Index(ae.Error(), "No updates are to be performed") > -1:
				return httperr.Errorf(403, "no updates are to be performed: %s", app)
			case strings.Index(ae.Error(), "can not be updated") > -1:
				return httperr.Errorf(403, "app is already updating: %s", app)
			}
		}
	}

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

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


示例17: EnvironmentList

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

	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)
	}

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


示例18: ParametersList

func ParametersList(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)
	}

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


示例19: SSLList

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

	ssls, err := models.ListSSLs(a)

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

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

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


示例20: ProcessList

func ProcessList(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	app := mux.Vars(r)["app"]
	stats := r.URL.Query().Get("stats") == "true"

	_, err := models.GetApp(app)

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

	processes, err := models.ListProcesses(app)

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

	if stats {
		w := new(sync.WaitGroup)
		erch := make(chan error, len(processes))

		for _, p := range processes {
			w.Add(1)

			go func(p *models.Process, w *sync.WaitGroup, erch chan error) {
				err := p.FetchStats()

				w.Done()

				if err != nil {
					erch <- err
				}
			}(p, w, erch)
		}

		w.Wait()

		select {
		case err := <-erch:
			return httperr.Server(err)
		default:
			// noop
		}
	}

	sort.Sort(models.Processes(processes))

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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang assert.Equal函数代码示例发布时间:2022-05-23
下一篇:
Golang logger.Logger类代码示例发布时间: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