示例#1
0
文件: app.go 项目: nemx/tsuru
func setCName(w http.ResponseWriter, r *http.Request, t *auth.Token) error {
	msg := "You must provide the cname."
	if r.Body == nil {
		return &errors.HTTP{Code: http.StatusBadRequest, Message: msg}
	}
	var v map[string]string
	err := json.NewDecoder(r.Body).Decode(&v)
	if err != nil {
		return &errors.HTTP{Code: http.StatusBadRequest, Message: "Invalid JSON in request body."}
	}
	if _, ok := v["cname"]; !ok {
		return &errors.HTTP{Code: http.StatusBadRequest, Message: msg}
	}
	u, err := t.User()
	if err != nil {
		return err
	}
	appName := r.URL.Query().Get(":app")
	rec.Log(u.Email, "set-cname", "app="+appName, "cname="+v["cname"])
	app, err := getApp(appName, u)
	if err != nil {
		return err
	}
	if err = app.SetCName(v["cname"]); err == nil {
		return nil
	}
	if err.Error() == "Invalid cname" {
		return &errors.HTTP{Code: http.StatusBadRequest, Message: err.Error()}
	}
	return err
}
示例#2
0
文件: app.go 项目: bardusco/tsuru
func setCName(w http.ResponseWriter, r *http.Request, u *auth.User) error {
	msg := "You must provide the cname."
	if r.Body == nil {
		return &errors.Http{Code: http.StatusBadRequest, Message: msg}
	}
	var v map[string]string
	err := json.NewDecoder(r.Body).Decode(&v)
	if err != nil {
		return &errors.Http{Code: http.StatusBadRequest, Message: "Invalid JSON in request body."}
	}
	if _, ok := v["cname"]; !ok {
		return &errors.Http{Code: http.StatusBadRequest, Message: msg}
	}
	appName := r.URL.Query().Get(":name")
	app, err := getApp(appName, u)
	if err != nil {
		return err
	}
	if err = app.SetCName(v["cname"]); err == nil {
		return nil
	}
	if err.Error() == "Invalid cname" {
		return &errors.Http{Code: http.StatusPreconditionFailed, Message: err.Error()}
	}
	return err
}