1 package aipreflect 2 3 import "google.golang.org/protobuf/reflect/protoreflect" 4 5 // MethodType is an AIP method type. 6 type MethodType int 7 8 //go:generate stringer -type MethodType -trimprefix MethodType 9 10 const ( 11 // MethodTypeNone represents no method type. 12 MethodTypeNone MethodType = iota 13 14 // MethodTypeGet is the method type of the AIP standard Get method. 15 // See: https://google.aip.dev/131 (Standard methods: Get). 16 MethodTypeGet 17 18 // MethodTypeList is the method type of the AIP standard List method. 19 // See: https://google.aip.dev/132 (Standard methods: List). 20 MethodTypeList 21 22 // MethodTypeCreate is the method type of the AIP standard Create method. 23 // See: https://google.aip.dev/133 (Standard methods: Create). 24 MethodTypeCreate 25 26 // MethodTypeUpdate is the method type of the AIP standard Update method. 27 // See: https://google.aip.dev/133 (Standard methods: Update). 28 MethodTypeUpdate 29 30 // MethodTypeDelete is the method type of the AIP standard Delete method. 31 // See: https://google.aip.dev/135 (Standard methods: Delete). 32 MethodTypeDelete 33 34 // MethodTypeUndelete is the method type of the AIP Undelete method for soft delete. 35 // See: https://google.aip.dev/164 (Soft delete). 36 MethodTypeUndelete 37 38 // MethodTypeBatchGet is the method type of the AIP standard BatchGet method. 39 // See: https://google.aip.dev/231 (Batch methods: Get). 40 MethodTypeBatchGet 41 42 // MethodTypeBatchCreate is the method type of the AIP standard BatchCreate method. 43 // See: https://google.aip.dev/233 (Batch methods: Create). 44 MethodTypeBatchCreate 45 46 // MethodTypeBatchUpdate is the method type of the AIP standard BatchUpdate method. 47 // See: https://google.aip.dev/234 (Batch methods: Update). 48 MethodTypeBatchUpdate 49 50 // MethodTypeBatchDelete is the method type of the AIP standard BatchDelete method. 51 // See: https://google.aip.dev/235 (Batch methods: Delete). 52 MethodTypeBatchDelete 53 54 // MethodTypeSearch is the method type of the custom AIP method for searching a resource collection. 55 // See: https://google.aip.dev/136 (Custom methods). 56 MethodTypeSearch 57 ) 58 59 // NamePrefix returns the method type's method name prefix. 60 func (s MethodType) NamePrefix() protoreflect.Name { 61 return protoreflect.Name(s.String()) 62 } 63 64 // IsPlural returns true if the method type relates to a plurality of resources. 65 func (s MethodType) IsPlural() bool { 66 switch s { 67 case MethodTypeList, 68 MethodTypeSearch, 69 MethodTypeBatchGet, 70 MethodTypeBatchCreate, 71 MethodTypeBatchUpdate, 72 MethodTypeBatchDelete: 73 return true 74 case MethodTypeNone, 75 MethodTypeGet, 76 MethodTypeCreate, 77 MethodTypeUpdate, 78 MethodTypeDelete, 79 MethodTypeUndelete: 80 return false 81 } 82 return false 83 } 84