action.go raw

   1  package api
   2  
   3  import "net/http"
   4  
   5  type Action string
   6  
   7  const (
   8  	ActionCreate Action = "Create"
   9  	ActionRead   Action = "Read"
  10  	ActionList   Action = "List"
  11  	ActionUpdate Action = "Update"
  12  	ActionDelete Action = "Delete"
  13  	ActionCount  Action = "Count"
  14  	ActionCancel Action = "Cancel"
  15  	ActionApply  Action = "Apply"
  16  )
  17  
  18  func Actions() []Action {
  19  	return []Action{
  20  		ActionCreate,
  21  		ActionRead,
  22  		ActionList,
  23  		ActionUpdate,
  24  		ActionDelete,
  25  		ActionCount,
  26  		ActionCancel,
  27  		ActionApply,
  28  	}
  29  }
  30  
  31  func (a Action) ToMethod() string {
  32  	switch a {
  33  	case ActionCreate:
  34  		return http.MethodPost
  35  	case ActionRead:
  36  		return http.MethodGet
  37  	case ActionList:
  38  		return http.MethodGet
  39  	case ActionUpdate:
  40  		return http.MethodPatch
  41  	case ActionDelete:
  42  		return http.MethodDelete
  43  	case ActionCount:
  44  		return http.MethodGet
  45  	case ActionCancel:
  46  		return http.MethodDelete
  47  	case ActionApply:
  48  		return http.MethodPatch
  49  	}
  50  	return ""
  51  }
  52