# reflect_fast **Repository Path**: luyue_zhang/reflect_fast ## Basic Information - **Project Name**: reflect_fast - **Description**: 用reflect做些事的demo,比如reflect实现json.marshal、reflect设置值、reflect实现rpc方法调用 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-05-15 - **Last Updated**: 2025-05-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 反射reflect速记 go ## 基本概念 ![基本概念](反射reflect速记%20go.assets/基本概念.png) ## demo 源码:https://gitee.com/luyue_zhang/reflect_fast ### reflect 实现简版json.Marshal、json.UnMarshal #### 演示 test文件位置:https://gitee.com/luyue_zhang/reflect_fast/blob/master/test/marshal_test.go ![reflect实现marshal](反射reflect速记%20go.assets/reflect实现marshal.gif) ### 反射实现方法调用 #### 使用场景 rpc服务调用 #### 演示 test文件位置:https://gitee.com/luyue_zhang/reflect_fast/blob/master/test/reflect_method_test.go ![image-20250515173328636](反射reflect速记%20go.assets/image-20250515173328636.png) ### 使用反射设置值 #### 使用场景 orm框架selector.get(val any) #### 演示 test文件位置:https://gitee.com/luyue_zhang/reflect_fast/blob/master/test/set_value_test.go ![reflect实现setValue](反射reflect速记%20go.assets/reflect实现setValue.gif) #### .Elem()含义 .Elem()用于获取指针、切片、数组或映射map的基础类型 - 对于指针`*test`,.Elem()返回`test` - 对于切片`[]*test`, .Elem()返回`*test` // 元素类型 - 对于数组`[5]test`, .Elem()返回`test` // 元素类型 - 对于映射`map[string]test`, .Elem()返回`test` ## 相关资料 [反射](https://www.topgoer.com/%E5%B8%B8%E7%94%A8%E6%A0%87%E5%87%86%E5%BA%93/%E5%8F%8D%E5%B0%84.html)