2 * Copyright 2020 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 func parseTags(tag reflect.StructTag) (string, string) {
25 fieldName := tag.Get("json")
29 fieldNames := strings.Split(fieldName, ",")
31 if len(fieldNames) > 1 {
32 secTag = fieldNames[1]
34 return fieldNames[0], secTag
37 func LoadObjByInd(dst interface{}, src interface{}, direction string) bool {
38 rflDst := reflect.ValueOf(dst).Elem()
39 rflSrc := reflect.ValueOf(src).Elem()
40 vType := rflDst.Type()
41 for i := 0; i < rflDst.NumField(); i++ {
42 fieldName, secTag := parseTags(vType.Field(i).Tag)
46 if secTag != direction {
50 valDst := rflDst.Field(i)
51 srcNode := ObjReflectPath(rflSrc, rflSrc, fieldName)
52 if srcNode.e != nil || srcNode.CurNode.Kind() == reflect.Invalid {
56 valSrc := srcNode.CurNode
57 if direction == "in" {