예제 #1
0
파일: app.go 프로젝트: astaxie/tsuru
func createAppHelper(instance *app.App, u *auth.User, units uint) ([]byte, error) {
	teams, err := u.Teams()
	if err != nil {
		return nil, err
	}
	if len(teams) < 1 {
		msg := "In order to create an app, you should be member of at least one team"
		return nil, &errors.Http{Code: http.StatusForbidden, Message: msg}
	}
	instance.SetTeams(teams)
	err = app.CreateApp(instance, units)
	if err != nil {
		log.Printf("Got error while creating app: %s", err)
		if e, ok := err.(*app.ValidationError); ok {
			return nil, &errors.Http{Code: http.StatusPreconditionFailed, Message: e.Message}
		}
		if strings.Contains(err.Error(), "key error") {
			msg := fmt.Sprintf(`There is already an app named "%s".`, instance.Name)
			return nil, &errors.Http{Code: http.StatusConflict, Message: msg}
		}
		return nil, err
	}
	msg := map[string]string{
		"status":         "success",
		"repository_url": repository.GetUrl(instance.Name),
	}
	return json.Marshal(msg)
}