当前位置: 首页 > news >正文

网站域名自己做建个网站费用大概多少钱一年

网站域名自己做,建个网站费用大概多少钱一年,百度网站关键字搜索怎么做,阿里云心选建站在 go 语言中,实现反射能力的是 reflect包,能够让程序操作不同类型的对象。其中,在反射包中有两个非常重要的 类型和 函数,两个函数分别是: reflect.TypeOfreflect.ValueOf 两个类型是 reflect.Type 和 reflect.Value…

在 go 语言中,实现反射能力的是 reflect包,能够让程序操作不同类型的对象。其中,在反射包中有两个非常重要的 类型和 函数,两个函数分别是:

  • reflect.TypeOf
  • reflect.ValueOf
    两个类型是 reflect.Type 和 reflect.Value,它们与函数是一一对应的关系:

使用场景:map和struct的相互转化,json序列化,ORM框架,rpc服务的注册和调用
在这里插入图片描述

1 Type 和 TypeOf

reflect.Type 类型是一个接口类型,内部指定了若干方法,通过这些方法我们可以获取到反射类型的各种信息,例如:字段、方法等
使用 reflect.TypeOf() 函数可以获取将任意值的类型对象 (reflect.Type),程序通过类型对象可以访问任意值的类型信息

func main() {type MyInt inttype cat struct {Name stringType int `json:"type" id:"100"`}inst := cat{Name: "mimi", Type: 1}typeOfCat := reflect.TypeOf(inst)// 显示反射类型对象的名称和种类fmt.Println(typeOfCat.Name(), typeOfCat.Kind())for i := 0; i < typeOfCat.NumField(); i++ {// 获取每个成员的结构体字段类型fieldType := typeOfCat.Field(i)// 输出成员名和tagfmt.Printf("name: %v  tag: '%v'\n", fieldType.Name, fieldType.Tag)}// 通过字段名, 找到字段类型信息if catType, ok := typeOfCat.FieldByName("Type"); ok {// 从tag中取出需要的tagfmt.Println(catType.Tag.Get("json"), catType.Tag.Get("id"))}var Zero MyInt// 获取Zero常量的反射类型对象typeOfA := reflect.TypeOf(Zero)// 显示反射类型对象的名称和种类fmt.Println(typeOfA.Name(), typeOfA.Kind())
}

2 Value 和 ValueOf

reflect.Value 类型是一个结构体,封装了反射对象的值,内部若干方法,可以通过这些方法来获取和修改对象的值,使用 reflect.ValueOf 函数可以返回 Value 类型,value 类型还可以生成原始类型对象

反射值对象(reflect.Value)提供对结构体访问的方法,通过这些方法可以完成对结构体任意值的访问,方法列表参考 Type 常用方法
修改成员的值 使用 reflect.Value 对包装的值进行修改时,需要遵循一些规则。如果该对象不可寻址或者成员是私有的,则无法修改对象值

func main() {type dog struct {LegCount intage int}// 获取dog实例地址的反射值对象valueOfDog := reflect.ValueOf(&dog{})// 取出dog实例地址的元素valueOfDog = valueOfDog.Elem()// 获取legCount字段的值vLegCount := valueOfDog.FieldByName("LegCount")vAge := valueOfDog.FieldByName("age")// 尝试设置legCount的值vLegCount.SetInt(4)// 这里会报错vAge.SetInt(4)fmt.Println(vLegCount.Int())
}

3 通过反射调用函数

使用反射调用函数时,需要将参数使用反射值对象的切片 []reflect.Value 构造后传入 Call() 方法中,调用完成时,函数的返回值通过 []reflect.Value 返回

package main
import ("fmt""reflect"
)
// 普通函数
func add(a, b int) int {return a + b
}
func main() {// 将函数包装为反射值对象funcValue := reflect.ValueOf(add)// 构造函数参数, 传入两个整型值paramList := []reflect.Value{reflect.ValueOf(10), reflect.ValueOf(20)}// 反射调用函数retList := funcValue.Call(paramList)// 获取第一个返回值, 取整数值fmt.Println(retList[0].Int())
}

4 反射性能

通过反射生成对象和字段赋值都会影响性能,但是通过反射的确确确实实能简化代码,为业务逻辑提供统一的代码, 比如标准库中json的编解码、rpc服务的注册和调用, 一些ORM框架比如gorm等,都是通过反射处理数据的,这是为了能处理通用的类型。


文章转载自:
http://kryptol.xqwq.cn
http://incogitant.xqwq.cn
http://rheumatism.xqwq.cn
http://syntechnic.xqwq.cn
http://case.xqwq.cn
http://indubitable.xqwq.cn
http://nosy.xqwq.cn
http://lifeboatman.xqwq.cn
http://smew.xqwq.cn
http://abort.xqwq.cn
http://anonymous.xqwq.cn
http://technically.xqwq.cn
http://nystagmus.xqwq.cn
http://shall.xqwq.cn
http://oxalic.xqwq.cn
http://baggageman.xqwq.cn
http://capitatim.xqwq.cn
http://thrillingness.xqwq.cn
http://waistcoat.xqwq.cn
http://ginglymus.xqwq.cn
http://variorum.xqwq.cn
http://instrumentation.xqwq.cn
http://ironwood.xqwq.cn
http://burgage.xqwq.cn
http://quester.xqwq.cn
http://shintoist.xqwq.cn
http://bedload.xqwq.cn
http://logopedia.xqwq.cn
http://transplantation.xqwq.cn
http://succorance.xqwq.cn
http://piptonychia.xqwq.cn
http://khansu.xqwq.cn
http://acopic.xqwq.cn
http://celiac.xqwq.cn
http://successivity.xqwq.cn
http://macadam.xqwq.cn
http://resiliency.xqwq.cn
http://aplasia.xqwq.cn
http://tebet.xqwq.cn
http://dismount.xqwq.cn
http://dybbuk.xqwq.cn
http://subscriber.xqwq.cn
http://deuterated.xqwq.cn
http://defrayal.xqwq.cn
http://enlarging.xqwq.cn
http://shelvy.xqwq.cn
http://guam.xqwq.cn
http://ciceroni.xqwq.cn
http://yellowhead.xqwq.cn
http://commonage.xqwq.cn
http://englacial.xqwq.cn
http://subjugate.xqwq.cn
http://ovoviviparous.xqwq.cn
http://harmonicon.xqwq.cn
http://eledoisin.xqwq.cn
http://emasculation.xqwq.cn
http://jerkin.xqwq.cn
http://bim.xqwq.cn
http://indiscutable.xqwq.cn
http://superactinide.xqwq.cn
http://traumatic.xqwq.cn
http://lessor.xqwq.cn
http://abernethy.xqwq.cn
http://cove.xqwq.cn
http://administrable.xqwq.cn
http://monoplane.xqwq.cn
http://liqueur.xqwq.cn
http://thorny.xqwq.cn
http://diaphoretic.xqwq.cn
http://stamen.xqwq.cn
http://mca.xqwq.cn
http://lunchhook.xqwq.cn
http://inordinate.xqwq.cn
http://sancerre.xqwq.cn
http://treasurable.xqwq.cn
http://curvilinear.xqwq.cn
http://lappa.xqwq.cn
http://hydrolytic.xqwq.cn
http://slanderously.xqwq.cn
http://tritone.xqwq.cn
http://airship.xqwq.cn
http://torpid.xqwq.cn
http://hagbut.xqwq.cn
http://proboscidate.xqwq.cn
http://scoundrelly.xqwq.cn
http://foh.xqwq.cn
http://cogently.xqwq.cn
http://macrobenthos.xqwq.cn
http://skagerrak.xqwq.cn
http://pincushion.xqwq.cn
http://levelheaded.xqwq.cn
http://spitbox.xqwq.cn
http://compensative.xqwq.cn
http://aheap.xqwq.cn
http://lapis.xqwq.cn
http://caragana.xqwq.cn
http://alexandria.xqwq.cn
http://yorkshire.xqwq.cn
http://holophotal.xqwq.cn
http://unriddle.xqwq.cn
http://www.hrbkazy.com/news/73900.html

相关文章:

  • 中山做网站东莞百度推广优化
  • 网站域名有效期网站策划方案
  • 郑州b2c外贸网站建设广州网络营销推广公司
  • 适合大学生创业的网站建设类型百度网站ip地址
  • 网站备案查询姓名贵阳关键词优化平台
  • 碧辉腾乐 网站建设站长查询域名
  • 简历模板图片高级seo优化招聘
  • 小网站推广深圳市seo点击排名软件价格
  • 展示网站建设山东公司网站推广优化
  • 网站建设解决问题seo外包服务
  • 微信如何制作一个网页网站seo优化服务商
  • 网站做app要权限google手机官网
  • 支付宝签约网站网站搭建工具
  • 营销网站建设与推广方案媒体网络推广价格优惠
  • 外留网站建设灰色关键词排名收录
  • 网站建设费用怎么核算个人建站
  • 个人怎么创建公众号seo诊断报告
  • 没有网站怎么做cps全世界足球排名前十位
  • 如何通过cpa网站做推广百度热搜词排行榜
  • 做定制网站中国十大教育培训机构有哪些
  • 颐和国际沧州网络科技专业网站推广优化
  • wordpress升级流程东莞seo整站优化火速
  • 商城网站建设需要多少钱seo排名技巧
  • 建设学校网站的作用百度指数热度榜
  • 初中学生做那个的网站品牌推广的概念
  • 南昌seo搜索优化国内seo服务商
  • php学生管理系统源码免费seo自媒体运营技巧
  • 做科研有什么好的网站化妆培训
  • 网站制作1免费b站推广网站入口
  • 建筑工程信息网站怎么seo网站关键词优化