<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                使用場景: 類似Java的BeanUtil.copyPropertity等工具類 ~~~ type Animal struct { Name string Age int Weight float64 } type Person struct { Name string Age int } type FieldMap map[string]bool func isStructPointer(obj interface{}) bool { if reflect.TypeOf(obj).Kind() != reflect.Ptr { return false } return reflect.TypeOf(obj).Kind() == reflect.Struct || reflect.TypeOf(obj).Elem().Kind() == reflect.Struct } func getAllFieldName(param interface{}) FieldMap { result := make(FieldMap) t := reflect.TypeOf(param).Elem() fieldNum := t.NumField() for i := 0; i < fieldNum; i++ { field := t.Field(i) fieldName := field.Name result[fieldName] = true } return result } func CopyObjects(source interface{}, dest interface{}) error { if !isStructPointer(source) || !isStructPointer(dest) { return errors.New("object must be struct pointer") } sourceFieldMap := getAllFieldName(source) t := reflect.TypeOf(dest).Elem() fieldNum := t.NumField() for i := 0; i < fieldNum; i++ { field := t.Field(i) if _, ok := sourceFieldMap[field.Name]; ok { // 取出source中該字段的值 value := reflect.ValueOf(source).Elem().FieldByName(field.Name) reflect.ValueOf(dest).Elem().FieldByName(field.Name).Set(value) } } return nil } func TestCopyObjects(t *testing.T) { person := new(Person) animal := &Animal{ Name: "Bear", Age: 15, Weight: 200, } t.Log(CopyObjects(animal, person)) t.Log("persion:", person) o1 := 10 o2 := 20 t.Log(CopyObjects(o1, o2)) } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看