github.com/sacloud/libsacloud/v2@v2.32.3/internal/define/names/resource_name.go (about) 1 // Copyright 2016-2022 The Libsacloud Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package names 16 17 import ( 18 "fmt" 19 "strings" 20 21 "github.com/sacloud/libsacloud/v2/internal/dsl" 22 ) 23 24 // ResourceFieldName リソース名がペイロードなどで利用される場合のフィールド名、コード生成時に利用される 25 func ResourceFieldName(resourceName string, form dsl.PayloadForm) string { 26 switch { 27 case form.IsSingular(): 28 return resourceName 29 case form.IsPlural(): 30 switch { 31 case 32 resourceName == "ESME", 33 resourceName == "NFS", 34 resourceName == "DNS", 35 resourceName == "Internet", 36 resourceName == "IPAddress", 37 strings.HasSuffix(resourceName, "Info"): 38 return resourceName 39 case resourceName == "ContainerRegistry": 40 return "ContainerRegistries" 41 case resourceName == "CertificateAuthority": 42 return "CertificateAuthorities" 43 case 44 strings.HasSuffix(resourceName, "ch"), 45 strings.HasSuffix(resourceName, "ss"): 46 return resourceName + "es" 47 default: 48 return resourceName + "s" 49 } 50 default: 51 return "" 52 } 53 } 54 55 // CreateParameterName Create操作に渡すパラメータの名称 56 func CreateParameterName(resourceName string) string { 57 return RequestParameterName(resourceName, "Create") 58 } 59 60 // UpdateParameterName Update操作に渡すパラメータの名称 61 func UpdateParameterName(resourceName string) string { 62 return RequestParameterName(resourceName, "Update") 63 } 64 65 // UpdateSettingsParameterName UpdateSettings操作に渡すパラメータの名称 66 func UpdateSettingsParameterName(resourceName string) string { 67 return RequestParameterName(resourceName, "UpdateSettings") 68 } 69 70 // RequestParameterName 任意の操作に渡すパラメータの名称 71 func RequestParameterName(resourceName, funcName string) string { 72 return fmt.Sprintf("%s%sRequest", resourceName, funcName) 73 }