github.com/wangyougui/gf/v2@v2.6.5/util/gutil/gutil_default.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/wangyougui/gf. 6 7 package gutil 8 9 // GetOrDefaultStr checks and returns value according whether parameter `param` available. 10 // It returns `param[0]` if it is available, or else it returns `def`. 11 func GetOrDefaultStr(def string, param ...string) string { 12 value := def 13 if len(param) > 0 && param[0] != "" { 14 value = param[0] 15 } 16 return value 17 } 18 19 // GetOrDefaultAny checks and returns value according whether parameter `param` available. 20 // It returns `param[0]` if it is available, or else it returns `def`. 21 func GetOrDefaultAny(def interface{}, param ...interface{}) interface{} { 22 value := def 23 if len(param) > 0 && param[0] != "" { 24 value = param[0] 25 } 26 return value 27 }