|
@@ -160,13 +160,31 @@ func (s Map) String(key, defaultVal string) string {
|
|
|
return defaultVal
|
|
|
}
|
|
|
|
|
|
-func (s Map) Bytes(key, defaultVal []byte) []byte {
|
|
|
+func (s Map) StringWithError(key, defaultVal string) (string, error) {
|
|
|
+ if iface, check := s[key]; check {
|
|
|
+ val := val(iface, defaultVal).String()
|
|
|
+ if val == defaultVal {
|
|
|
+ return defaultVal, fmt.Errorf("FIELD [%s] IS EMPTY", key)
|
|
|
+ }
|
|
|
+ return val, nil
|
|
|
+ }
|
|
|
+ return defaultVal, fmt.Errorf("FIELD [%s] IS NOT EXISTS", key)
|
|
|
+}
|
|
|
+
|
|
|
+func (s Map) Bytes(key string, defaultVal []byte) []byte {
|
|
|
if iface, check := s[key]; check {
|
|
|
return []byte(val(iface, defaultVal).String())
|
|
|
}
|
|
|
return defaultVal
|
|
|
}
|
|
|
|
|
|
+func (s Map) BytesWithError(key string, defaultVal []byte) ([]byte, error) {
|
|
|
+ if iface, check := s[key]; check {
|
|
|
+ return []byte(val(iface, defaultVal).String()), nil
|
|
|
+ }
|
|
|
+ return defaultVal, fmt.Errorf("FIELD [%s] IS NOT EXISTS", key)
|
|
|
+}
|
|
|
+
|
|
|
func (s Map) StringVal(key, defaultVal string) string {
|
|
|
if iface, check := s[key]; check {
|
|
|
return fmt.Sprint(iface)
|