github.com/cloudwego/kitex@v0.9.0/tool/internal_pkg/generator/feature.go (about) 1 // Copyright 2021 CloudWeGo 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 generator 16 17 type feature int 18 19 const ( 20 placeHolder feature = iota 21 ) 22 23 var ( 24 featureMap = make(map[string]feature) 25 maxFeature = placeHolder 26 ) 27 28 // HasFeature check whether a feature in the list 29 func HasFeature(list []feature, key string) bool { 30 target, ok := getFeature(key) 31 if !ok { 32 return false 33 } 34 for _, f := range list { 35 if f == target { 36 return true 37 } 38 } 39 return false 40 } 41 42 // RegisterFeature register a feature 43 func RegisterFeature(key string) { 44 if _, ok := featureMap[key]; !ok { 45 maxFeature++ 46 featureMap[key] = maxFeature 47 } 48 } 49 50 func getFeature(key string) (feature, bool) { 51 f, ok := featureMap[key] 52 return f, ok 53 }