func addPoolHandler(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	allowed := permission.Check(t, permission.PermPoolCreate)
	if !allowed {
		return permission.ErrUnauthorized
	}
	var addOpts pool.AddPoolOptions
	err = ParseInput(r, &addOpts)
	if err != nil {
		return err
	}
	if addOpts.Name == "" {
		return &terrors.HTTP{
			Code:    http.StatusBadRequest,
			Message: pool.ErrPoolNameIsRequired.Error(),
		}
	}
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypePool, Value: addOpts.Name},
		Kind:       permission.PermPoolCreate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermPoolReadEvents, permission.Context(permTypes.CtxPool, addOpts.Name)),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	err = pool.AddPool(addOpts)
	if err == pool.ErrDefaultPoolAlreadyExists || err == pool.ErrPoolAlreadyExists {
		return &terrors.HTTP{
			Code:    http.StatusConflict,
			Message: err.Error(),
		}
	}
	if err == pool.ErrPoolNameIsRequired {
		return &terrors.HTTP{
			Code:    http.StatusBadRequest,
			Message: err.Error(),
		}
	}
	if err == nil {
		w.WriteHeader(http.StatusCreated)
	}
	return err
}
func addPoolHandler(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	allowed := permission.Check(t, permission.PermPoolCreate)
	if !allowed {
		return permission.ErrUnauthorized
	}
	var addOpts pool.AddPoolOptions
	err = ParseInput(r, &addOpts)
	if err != nil {
		return err
	}
	if addOpts.Name == "" {
		return &terrors.HTTP{
			Code:    http.StatusBadRequest,
			Message: pool.ErrPoolNameIsRequired.Error(),
		}
	}
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypePool, Value: addOpts.Name},
		Kind:       permission.PermPoolCreate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermPoolReadEvents, permission.Context(permTypes.CtxPool, addOpts.Name)),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	err = pool.AddPool(addOpts)
	if err == pool.ErrDefaultPoolAlreadyExists || err == pool.ErrPoolAlreadyExists {
		return &terrors.HTTP{
			Code:    http.StatusConflict,
			Message: err.Error(),
		}
	}
	if err == pool.ErrPoolNameIsRequired {
		return &terrors.HTTP{
			Code:    http.StatusBadRequest,
			Message: err.Error(),
		}
	}
	if err == nil {
		w.WriteHeader(http.StatusCreated)
	}
	return err
}
func addPoolHandler ( w http . ResponseWriter , r * http . Request , t auth . Token ) ( err error ) { allowed := permission . Check ( t , permission . PermPoolCreate ) if ! allowed { return permission . ErrUnauthorized } var addOpts pool . AddPoolOptions err = ParseInput ( r , & addOpts ) if err != nil { return err } if addOpts . Name == " " { return & terrors . HTTP { Code : http . StatusBadRequest , Message : pool . ErrPoolNameIsRequired . Error ( ) , } } evt , err := event . New ( & event . Opts { Target : event . Target { Type : event . TargetTypePool , Value : addOpts . Name } , Kind : permission . PermPoolCreate , Owner : t , CustomData : event . FormToCustomData ( InputFields ( r ) ) , Allowed : event . Allowed ( permission . PermPoolReadEvents , permission . Context ( permTypes . CtxPool , addOpts . Name ) ) , } ) if err != nil { return err } defer func ( ) { evt . Done ( err ) } ( ) err = pool . AddPool ( addOpts ) if err == pool . ErrDefaultPoolAlreadyExists || err == pool . ErrPoolAlreadyExists { return & terrors . HTTP { Code : http . StatusConflict , Message : err . Error ( ) , } } if err == pool . ErrPoolNameIsRequired { return & terrors . HTTP { Code : http . StatusBadRequest , Message : err . Error ( ) , } } if err == nil { w . WriteHeader ( http . StatusCreated ) } return err }
// title: pool create
// path: /pools
// method: POST
// consume: application/x-www-form-urlencoded
// responses:
//   201: Pool created
//   400: Invalid data
//   401: Unauthorized
//   409: Pool already exists
title : pool create path : / pools method : POST consume : application / x - www - form - urlencoded responses : 201 : Pool created 400 : Invalid data 401 : Unauthorized 409 : Pool already exists