func addPlan(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	cpuShare, _ := strconv.Atoi(InputValue(r, "cpushare"))
	isDefault, _ := strconv.ParseBool(InputValue(r, "default"))
	memory := getSize(InputValue(r, "memory"))
	swap := getSize(InputValue(r, "swap"))
	plan := appTypes.Plan{
		Name:     InputValue(r, "name"),
		Memory:   memory,
		Swap:     swap,
		CpuShare: cpuShare,
		Default:  isDefault,
	}
	allowed := permission.Check(t, permission.PermPlanCreate)
	if !allowed {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypePlan, Value: plan.Name},
		Kind:       permission.PermPlanCreate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermPlanReadEvents),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	err = servicemanager.Plan.Create(plan)
	if err == appTypes.ErrPlanAlreadyExists {
		return &errors.HTTP{
			Code:    http.StatusConflict,
			Message: err.Error(),
		}
	}
	if err == appTypes.ErrLimitOfMemory || err == appTypes.ErrLimitOfCpuShare {
		return &errors.HTTP{
			Code:    http.StatusBadRequest,
			Message: err.Error(),
		}
	}
	if err == nil {
		w.WriteHeader(http.StatusCreated)
	}
	return err
}
func addPlan(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	cpuShare, _ := strconv.Atoi(InputValue(r, "cpushare"))
	isDefault, _ := strconv.ParseBool(InputValue(r, "default"))
	memory := getSize(InputValue(r, "memory"))
	swap := getSize(InputValue(r, "swap"))
	plan := appTypes.Plan{
		Name:     InputValue(r, "name"),
		Memory:   memory,
		Swap:     swap,
		CpuShare: cpuShare,
		Default:  isDefault,
	}
	allowed := permission.Check(t, permission.PermPlanCreate)
	if !allowed {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypePlan, Value: plan.Name},
		Kind:       permission.PermPlanCreate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermPlanReadEvents),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	err = servicemanager.Plan.Create(plan)
	if err == appTypes.ErrPlanAlreadyExists {
		return &errors.HTTP{
			Code:    http.StatusConflict,
			Message: err.Error(),
		}
	}
	if err == appTypes.ErrLimitOfMemory || err == appTypes.ErrLimitOfCpuShare {
		return &errors.HTTP{
			Code:    http.StatusBadRequest,
			Message: err.Error(),
		}
	}
	if err == nil {
		w.WriteHeader(http.StatusCreated)
	}
	return err
}
func addPlan ( w http . ResponseWriter , r * http . Request , t auth . Token ) ( err error ) { cpuShare , _ := strconv . Atoi ( InputValue ( r , " " ) ) isDefault , _ := strconv . ParseBool ( InputValue ( r , " " ) ) memory := getSize ( InputValue ( r , " " ) ) swap := getSize ( InputValue ( r , " " ) ) plan := appTypes . Plan { Name : InputValue ( r , " " ) , Memory : memory , Swap : swap , CpuShare : cpuShare , Default : isDefault , } allowed := permission . Check ( t , permission . PermPlanCreate ) if ! allowed { return permission . ErrUnauthorized } evt , err := event . New ( & event . Opts { Target : event . Target { Type : event . TargetTypePlan , Value : plan . Name } , Kind : permission . PermPlanCreate , Owner : t , CustomData : event . FormToCustomData ( InputFields ( r ) ) , Allowed : event . Allowed ( permission . PermPlanReadEvents ) , } ) if err != nil { return err } defer func ( ) { evt . Done ( err ) } ( ) err = servicemanager . Plan . Create ( plan ) if err == appTypes . ErrPlanAlreadyExists { return & errors . HTTP { Code : http . StatusConflict , Message : err . Error ( ) , } } if err == appTypes . ErrLimitOfMemory || err == appTypes . ErrLimitOfCpuShare { return & errors . HTTP { Code : http . StatusBadRequest , Message : err . Error ( ) , } } if err == nil { w . WriteHeader ( http . StatusCreated ) } return err }
// title: plan create
// path: /plans
// method: POST
// consume: application/x-www-form-urlencoded
// responses:
//   201: Plan created
//   400: Invalid data
//   401: Unauthorized
//   409: Plan already exists
title : plan create path : / plans method : POST consume : application / x - www - form - urlencoded responses : 201 : Plan created 400 : Invalid data 401 : Unauthorized 409 : Plan already exists