Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 1 | // Copyright 2017 Google Inc. All rights reserved. |
| 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 android |
| 16 | |
| 17 | import ( |
| 18 | "path/filepath" |
| 19 | "reflect" |
| 20 | "strconv" |
| 21 | "strings" |
| 22 | |
| 23 | "github.com/google/blueprint/proptools" |
| 24 | ) |
| 25 | |
| 26 | // "neverallow" rules for the build system. |
| 27 | // |
| 28 | // This allows things which aren't related to the build system and are enforced |
| 29 | // for sanity, in progress code refactors, or policy to be expressed in a |
| 30 | // straightforward away disjoint from implementations and tests which should |
| 31 | // work regardless of these restrictions. |
| 32 | // |
| 33 | // A module is disallowed if all of the following are true: |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 34 | // - it is in one of the "In" paths |
| 35 | // - it is not in one of the "NotIn" paths |
| 36 | // - it has all "With" properties matched |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 37 | // - - values are matched in their entirety |
| 38 | // - - nil is interpreted as an empty string |
| 39 | // - - nested properties are separated with a '.' |
| 40 | // - - if the property is a list, any of the values in the list being matches |
| 41 | // counts as a match |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 42 | // - it has none of the "Without" properties matched (same rules as above) |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 43 | |
| 44 | func registerNeverallowMutator(ctx RegisterMutatorsContext) { |
| 45 | ctx.BottomUp("neverallow", neverallowMutator).Parallel() |
| 46 | } |
| 47 | |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 48 | var neverallows = []Rule{} |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 49 | |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 50 | func init() { |
| 51 | AddNeverAllowRules(createTrebleRules()...) |
| 52 | AddNeverAllowRules(createLibcoreRules()...) |
| 53 | AddNeverAllowRules(createMediaRules()...) |
| 54 | AddNeverAllowRules(createJavaDeviceForHostRules()...) |
Neil Fuller | df5f356 | 2018-10-21 17:19:10 +0100 | [diff] [blame] | 55 | } |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 56 | |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 57 | // Add a NeverAllow rule to the set of rules to apply. |
| 58 | func AddNeverAllowRules(rules ...Rule) { |
| 59 | neverallows = append(neverallows, rules...) |
| 60 | } |
| 61 | |
| 62 | func createTrebleRules() []Rule { |
| 63 | return []Rule{ |
| 64 | NeverAllow(). |
| 65 | In("vendor", "device"). |
| 66 | With("vndk.enabled", "true"). |
| 67 | Without("vendor", "true"). |
| 68 | Because("the VNDK can never contain a library that is device dependent."), |
| 69 | NeverAllow(). |
| 70 | With("vndk.enabled", "true"). |
| 71 | Without("vendor", "true"). |
| 72 | Without("owner", ""). |
| 73 | Because("a VNDK module can never have an owner."), |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 74 | |
Neil Fuller | df5f356 | 2018-10-21 17:19:10 +0100 | [diff] [blame] | 75 | // TODO(b/67974785): always enforce the manifest |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 76 | NeverAllow(). |
| 77 | Without("name", "libhidltransport-impl-internal"). |
| 78 | With("product_variables.enforce_vintf_manifest.cflags", "*"). |
| 79 | Because("manifest enforcement should be independent of ."), |
Neil Fuller | df5f356 | 2018-10-21 17:19:10 +0100 | [diff] [blame] | 80 | |
| 81 | // TODO(b/67975799): vendor code should always use /vendor/bin/sh |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 82 | NeverAllow(). |
| 83 | Without("name", "libc_bionic_ndk"). |
| 84 | With("product_variables.treble_linker_namespaces.cflags", "*"). |
| 85 | Because("nothing should care if linker namespaces are enabled or not"), |
Neil Fuller | df5f356 | 2018-10-21 17:19:10 +0100 | [diff] [blame] | 86 | |
| 87 | // Example: |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 88 | // *NeverAllow().with("Srcs", "main.cpp")) |
Neil Fuller | df5f356 | 2018-10-21 17:19:10 +0100 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 92 | func createLibcoreRules() []Rule { |
Neil Fuller | df5f356 | 2018-10-21 17:19:10 +0100 | [diff] [blame] | 93 | var coreLibraryProjects = []string{ |
| 94 | "libcore", |
| 95 | "external/apache-harmony", |
| 96 | "external/apache-xml", |
| 97 | "external/bouncycastle", |
| 98 | "external/conscrypt", |
| 99 | "external/icu", |
| 100 | "external/okhttp", |
| 101 | "external/wycheproof", |
Paul Duffin | b6c6bdd | 2019-06-07 11:43:55 +0100 | [diff] [blame] | 102 | |
| 103 | // Not really a core library but still needs access to same capabilities. |
| 104 | "development", |
Neil Fuller | df5f356 | 2018-10-21 17:19:10 +0100 | [diff] [blame] | 105 | } |
| 106 | |
Paul Duffin | a3d0986 | 2019-06-11 13:40:47 +0100 | [diff] [blame] | 107 | // Core library constraints. The sdk_version: "none" can only be used in core library projects. |
| 108 | // Access to core library targets is restricted using visibility rules. |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 109 | rules := []Rule{ |
| 110 | NeverAllow(). |
| 111 | NotIn(coreLibraryProjects...). |
| 112 | With("sdk_version", "none"), |
Neil Fuller | df5f356 | 2018-10-21 17:19:10 +0100 | [diff] [blame] | 113 | } |
| 114 | |
Neil Fuller | df5f356 | 2018-10-21 17:19:10 +0100 | [diff] [blame] | 115 | return rules |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 118 | func createMediaRules() []Rule { |
| 119 | return []Rule{ |
| 120 | NeverAllow(). |
| 121 | With("libs", "updatable-media"). |
| 122 | Because("updatable-media includes private APIs. Use updatable_media_stubs instead."), |
Dongwon Kang | 50a299f | 2019-02-04 09:00:51 -0800 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 126 | func createJavaDeviceForHostRules() []Rule { |
Colin Cross | fd4f743 | 2019-03-05 15:06:16 -0800 | [diff] [blame] | 127 | javaDeviceForHostProjectsWhitelist := []string{ |
Colin Cross | b5191a5 | 2019-04-11 14:07:38 -0700 | [diff] [blame] | 128 | "external/guava", |
Colin Cross | fd4f743 | 2019-03-05 15:06:16 -0800 | [diff] [blame] | 129 | "external/robolectric-shadows", |
| 130 | "framework/layoutlib", |
| 131 | } |
| 132 | |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 133 | return []Rule{ |
| 134 | NeverAllow(). |
| 135 | NotIn(javaDeviceForHostProjectsWhitelist...). |
| 136 | ModuleType("java_device_for_host", "java_host_for_device"). |
| 137 | Because("java_device_for_host can only be used in whitelisted projects"), |
Colin Cross | fd4f743 | 2019-03-05 15:06:16 -0800 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 141 | func neverallowMutator(ctx BottomUpMutatorContext) { |
| 142 | m, ok := ctx.Module().(Module) |
| 143 | if !ok { |
| 144 | return |
| 145 | } |
| 146 | |
| 147 | dir := ctx.ModuleDir() + "/" |
| 148 | properties := m.GetProperties() |
| 149 | |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 150 | for _, r := range neverallows { |
| 151 | n := r.(*rule) |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 152 | if !n.appliesToPath(dir) { |
| 153 | continue |
| 154 | } |
| 155 | |
Colin Cross | fd4f743 | 2019-03-05 15:06:16 -0800 | [diff] [blame] | 156 | if !n.appliesToModuleType(ctx.ModuleType()) { |
| 157 | continue |
| 158 | } |
| 159 | |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 160 | if !n.appliesToProperties(properties) { |
| 161 | continue |
| 162 | } |
| 163 | |
| 164 | ctx.ModuleErrorf("violates " + n.String()) |
| 165 | } |
| 166 | } |
| 167 | |
Paul Duffin | 73bf054 | 2019-07-12 14:12:49 +0100 | [diff] [blame] | 168 | type ValueMatcher interface { |
| 169 | test(string) bool |
| 170 | String() string |
| 171 | } |
| 172 | |
| 173 | type equalMatcher struct { |
| 174 | expected string |
| 175 | } |
| 176 | |
| 177 | func (m *equalMatcher) test(value string) bool { |
| 178 | return m.expected == value |
| 179 | } |
| 180 | |
| 181 | func (m *equalMatcher) String() string { |
| 182 | return "=" + m.expected |
| 183 | } |
| 184 | |
| 185 | type anyMatcher struct { |
| 186 | } |
| 187 | |
| 188 | func (m *anyMatcher) test(value string) bool { |
| 189 | return true |
| 190 | } |
| 191 | |
| 192 | func (m *anyMatcher) String() string { |
| 193 | return "=*" |
| 194 | } |
| 195 | |
| 196 | var anyMatcherInstance = &anyMatcher{} |
| 197 | |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 198 | type ruleProperty struct { |
Paul Duffin | 73bf054 | 2019-07-12 14:12:49 +0100 | [diff] [blame] | 199 | fields []string // e.x.: Vndk.Enabled |
| 200 | matcher ValueMatcher |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 201 | } |
| 202 | |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 203 | // A NeverAllow rule. |
| 204 | type Rule interface { |
| 205 | In(path ...string) Rule |
| 206 | |
| 207 | NotIn(path ...string) Rule |
| 208 | |
| 209 | ModuleType(types ...string) Rule |
| 210 | |
| 211 | NotModuleType(types ...string) Rule |
| 212 | |
| 213 | With(properties, value string) Rule |
| 214 | |
| 215 | Without(properties, value string) Rule |
| 216 | |
| 217 | Because(reason string) Rule |
| 218 | } |
| 219 | |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 220 | type rule struct { |
| 221 | // User string for why this is a thing. |
| 222 | reason string |
| 223 | |
| 224 | paths []string |
| 225 | unlessPaths []string |
| 226 | |
Colin Cross | fd4f743 | 2019-03-05 15:06:16 -0800 | [diff] [blame] | 227 | moduleTypes []string |
| 228 | unlessModuleTypes []string |
| 229 | |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 230 | props []ruleProperty |
| 231 | unlessProps []ruleProperty |
| 232 | } |
| 233 | |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 234 | // Create a new NeverAllow rule. |
| 235 | func NeverAllow() Rule { |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 236 | return &rule{} |
| 237 | } |
Colin Cross | fd4f743 | 2019-03-05 15:06:16 -0800 | [diff] [blame] | 238 | |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 239 | func (r *rule) In(path ...string) Rule { |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 240 | r.paths = append(r.paths, cleanPaths(path)...) |
| 241 | return r |
| 242 | } |
Colin Cross | fd4f743 | 2019-03-05 15:06:16 -0800 | [diff] [blame] | 243 | |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 244 | func (r *rule) NotIn(path ...string) Rule { |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 245 | r.unlessPaths = append(r.unlessPaths, cleanPaths(path)...) |
| 246 | return r |
| 247 | } |
Colin Cross | fd4f743 | 2019-03-05 15:06:16 -0800 | [diff] [blame] | 248 | |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 249 | func (r *rule) ModuleType(types ...string) Rule { |
Colin Cross | fd4f743 | 2019-03-05 15:06:16 -0800 | [diff] [blame] | 250 | r.moduleTypes = append(r.moduleTypes, types...) |
| 251 | return r |
| 252 | } |
| 253 | |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 254 | func (r *rule) NotModuleType(types ...string) Rule { |
Colin Cross | fd4f743 | 2019-03-05 15:06:16 -0800 | [diff] [blame] | 255 | r.unlessModuleTypes = append(r.unlessModuleTypes, types...) |
| 256 | return r |
| 257 | } |
| 258 | |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 259 | func (r *rule) With(properties, value string) Rule { |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 260 | r.props = append(r.props, ruleProperty{ |
Paul Duffin | 73bf054 | 2019-07-12 14:12:49 +0100 | [diff] [blame] | 261 | fields: fieldNamesForProperties(properties), |
Ming-Shin Lu | ff3d72f | 2019-07-22 06:44:34 +0000 | [diff] [blame] | 262 | matcher: selectMatcher(value), |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 263 | }) |
| 264 | return r |
| 265 | } |
Colin Cross | fd4f743 | 2019-03-05 15:06:16 -0800 | [diff] [blame] | 266 | |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 267 | func (r *rule) Without(properties, value string) Rule { |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 268 | r.unlessProps = append(r.unlessProps, ruleProperty{ |
Paul Duffin | 73bf054 | 2019-07-12 14:12:49 +0100 | [diff] [blame] | 269 | fields: fieldNamesForProperties(properties), |
Ming-Shin Lu | ff3d72f | 2019-07-22 06:44:34 +0000 | [diff] [blame] | 270 | matcher: selectMatcher(value), |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 271 | }) |
| 272 | return r |
| 273 | } |
Colin Cross | fd4f743 | 2019-03-05 15:06:16 -0800 | [diff] [blame] | 274 | |
Paul Duffin | 73bf054 | 2019-07-12 14:12:49 +0100 | [diff] [blame] | 275 | func selectMatcher(expected string) ValueMatcher { |
| 276 | if expected == "*" { |
| 277 | return anyMatcherInstance |
| 278 | } |
| 279 | return &equalMatcher{expected: expected} |
| 280 | } |
| 281 | |
Paul Duffin | 730f2a5 | 2019-06-27 14:08:51 +0100 | [diff] [blame] | 282 | func (r *rule) Because(reason string) Rule { |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 283 | r.reason = reason |
| 284 | return r |
| 285 | } |
| 286 | |
| 287 | func (r *rule) String() string { |
| 288 | s := "neverallow" |
| 289 | for _, v := range r.paths { |
| 290 | s += " dir:" + v + "*" |
| 291 | } |
| 292 | for _, v := range r.unlessPaths { |
| 293 | s += " -dir:" + v + "*" |
| 294 | } |
Colin Cross | fd4f743 | 2019-03-05 15:06:16 -0800 | [diff] [blame] | 295 | for _, v := range r.moduleTypes { |
| 296 | s += " type:" + v |
| 297 | } |
| 298 | for _, v := range r.unlessModuleTypes { |
| 299 | s += " -type:" + v |
| 300 | } |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 301 | for _, v := range r.props { |
Paul Duffin | 73bf054 | 2019-07-12 14:12:49 +0100 | [diff] [blame] | 302 | s += " " + strings.Join(v.fields, ".") + v.matcher.String() |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 303 | } |
| 304 | for _, v := range r.unlessProps { |
Paul Duffin | 73bf054 | 2019-07-12 14:12:49 +0100 | [diff] [blame] | 305 | s += " -" + strings.Join(v.fields, ".") + v.matcher.String() |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 306 | } |
| 307 | if len(r.reason) != 0 { |
| 308 | s += " which is restricted because " + r.reason |
| 309 | } |
| 310 | return s |
| 311 | } |
| 312 | |
| 313 | func (r *rule) appliesToPath(dir string) bool { |
| 314 | includePath := len(r.paths) == 0 || hasAnyPrefix(dir, r.paths) |
| 315 | excludePath := hasAnyPrefix(dir, r.unlessPaths) |
| 316 | return includePath && !excludePath |
| 317 | } |
| 318 | |
Colin Cross | fd4f743 | 2019-03-05 15:06:16 -0800 | [diff] [blame] | 319 | func (r *rule) appliesToModuleType(moduleType string) bool { |
| 320 | return (len(r.moduleTypes) == 0 || InList(moduleType, r.moduleTypes)) && !InList(moduleType, r.unlessModuleTypes) |
| 321 | } |
| 322 | |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 323 | func (r *rule) appliesToProperties(properties []interface{}) bool { |
| 324 | includeProps := hasAllProperties(properties, r.props) |
| 325 | excludeProps := hasAnyProperty(properties, r.unlessProps) |
| 326 | return includeProps && !excludeProps |
| 327 | } |
| 328 | |
| 329 | // assorted utils |
| 330 | |
| 331 | func cleanPaths(paths []string) []string { |
| 332 | res := make([]string, len(paths)) |
| 333 | for i, v := range paths { |
| 334 | res[i] = filepath.Clean(v) + "/" |
| 335 | } |
| 336 | return res |
| 337 | } |
| 338 | |
| 339 | func fieldNamesForProperties(propertyNames string) []string { |
| 340 | names := strings.Split(propertyNames, ".") |
| 341 | for i, v := range names { |
| 342 | names[i] = proptools.FieldNameForProperty(v) |
| 343 | } |
| 344 | return names |
| 345 | } |
| 346 | |
| 347 | func hasAnyPrefix(s string, prefixes []string) bool { |
| 348 | for _, prefix := range prefixes { |
| 349 | if strings.HasPrefix(s, prefix) { |
| 350 | return true |
| 351 | } |
| 352 | } |
| 353 | return false |
| 354 | } |
| 355 | |
| 356 | func hasAnyProperty(properties []interface{}, props []ruleProperty) bool { |
| 357 | for _, v := range props { |
| 358 | if hasProperty(properties, v) { |
| 359 | return true |
| 360 | } |
| 361 | } |
| 362 | return false |
| 363 | } |
| 364 | |
| 365 | func hasAllProperties(properties []interface{}, props []ruleProperty) bool { |
| 366 | for _, v := range props { |
| 367 | if !hasProperty(properties, v) { |
| 368 | return false |
| 369 | } |
| 370 | } |
| 371 | return true |
| 372 | } |
| 373 | |
| 374 | func hasProperty(properties []interface{}, prop ruleProperty) bool { |
| 375 | for _, propertyStruct := range properties { |
| 376 | propertiesValue := reflect.ValueOf(propertyStruct).Elem() |
| 377 | for _, v := range prop.fields { |
| 378 | if !propertiesValue.IsValid() { |
| 379 | break |
| 380 | } |
| 381 | propertiesValue = propertiesValue.FieldByName(v) |
| 382 | } |
| 383 | if !propertiesValue.IsValid() { |
| 384 | continue |
| 385 | } |
| 386 | |
Paul Duffin | 73bf054 | 2019-07-12 14:12:49 +0100 | [diff] [blame] | 387 | check := func(value string) bool { |
| 388 | return prop.matcher.test(value) |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | if matchValue(propertiesValue, check) { |
| 392 | return true |
| 393 | } |
| 394 | } |
| 395 | return false |
| 396 | } |
| 397 | |
| 398 | func matchValue(value reflect.Value, check func(string) bool) bool { |
| 399 | if !value.IsValid() { |
| 400 | return false |
| 401 | } |
| 402 | |
| 403 | if value.Kind() == reflect.Ptr { |
| 404 | if value.IsNil() { |
| 405 | return check("") |
| 406 | } |
| 407 | value = value.Elem() |
| 408 | } |
| 409 | |
| 410 | switch value.Kind() { |
| 411 | case reflect.String: |
| 412 | return check(value.String()) |
| 413 | case reflect.Bool: |
| 414 | return check(strconv.FormatBool(value.Bool())) |
| 415 | case reflect.Int: |
| 416 | return check(strconv.FormatInt(value.Int(), 10)) |
| 417 | case reflect.Slice: |
| 418 | slice, ok := value.Interface().([]string) |
| 419 | if !ok { |
| 420 | panic("Can only handle slice of string") |
| 421 | } |
| 422 | for _, v := range slice { |
| 423 | if check(v) { |
| 424 | return true |
| 425 | } |
| 426 | } |
| 427 | return false |
| 428 | } |
| 429 | |
| 430 | panic("Can't handle type: " + value.Kind().String()) |
| 431 | } |