github.com/ystia/yorc/v4@v4.3.0/storage/utils/utils.go (about) 1 // Copyright 2019 Bull S.A.S. Atos Technologies - Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois, France. 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 utils 16 17 import "github.com/pkg/errors" 18 19 // CheckKeyAndValue returns an error if k == "" or if v == nil 20 func CheckKeyAndValue(k string, v interface{}) error { 21 if err := CheckKey(k); err != nil { 22 return err 23 } 24 return CheckVal(v) 25 } 26 27 // CheckKey returns an error if k == "" 28 func CheckKey(k string) error { 29 if k == "" { 30 return errors.New("The passed key is an empty string, which is invalid") 31 } 32 return nil 33 } 34 35 // CheckVal returns an error if v == nil 36 func CheckVal(v interface{}) error { 37 if v == nil { 38 return errors.New("The passed value is nil, which is not allowed") 39 } 40 return nil 41 }