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

php网页设计论文河南网站排名优化

php网页设计论文,河南网站排名优化,网页微信版官网登录不扫码,大型网站 开发语言目录标题 一、Reflection反射1. What is reflection? 什么是反射2. Inspect a variable and find its type 检查变量并找到它的类型3. Reflect.Type and reflect.Value 反射类型和值4. Reflect.Kind 查看底层种类5. NumField() and Field() methods 字段数量和索引值方法6. In…

目录标题

  • 一、Reflection反射
    • 1. What is reflection? 什么是反射
    • 2. Inspect a variable and find its type 检查变量并找到它的类型
    • 3. Reflect.Type and reflect.Value 反射类型和值
    • 4. Reflect.Kind 查看底层种类
    • 5. NumField() and Field() methods 字段数量和索引值方法
    • 6. Int() and String() methods 整型和字符型方法
    • 7. Complete Program 完整示例
  • 二、 Reading Files
    • 1. Reading Files 读取文件
    • 2. Using absolute file path 使用绝对路径
    • 3. Passing the file path as a command line flag 将文件路径作为命令行标志传递
    • 4. Reading a file in small chunks
    • 5. Reading a file line by line 逐行读取文件

一、Reflection反射

1. What is reflection? 什么是反射

	反射是Go中的高级主题之一,在Go语言中反射(reflection)是指在程序运行时动态地检查类型信息和操作对象的能力。通过反射,你可以在运行时获取类型的信息,访问和修改对象的字段和方法,以及动态地调用函数。 Go语言中的反射由reflect包提供支持。该包中的Type和Value类型提供了访问和操作类型和对象的方法。要使用反射,首先需要使用reflect.TypeOf()函数获取一个值的类型信息,或者使用reflect.ValueOf()函数获取一个值的反射对象。这些函数返回的类型对象或值对象包含了有关值的类型、字段、方法等信息。反射对象的常用方法包括:Type.Kind():返回类型的种类,如整数、字符串、结构体等。Type.Name():返回类型的名称。Type.Field(i int):返回结构体类型的第i个字段的反射对象。Type.NumField():返回结构体类型的字段数量。Value.Interface():将反射对象转换为普通的接口类型。Value.Kind():返回值的种类,如整数、字符串、结构体等。Value.String():返回值的字符串表示。Value.Field(i int):返回结构体类型值的第i个字段的反射对象。Value.NumField():返回结构体类型值的字段数量。Value.Method(i int):返回值的第i个方法的反射对象。Value.Call(args []Value):调用值对应的方法,传递参数并返回结果。通过使用这些方法,你可以在运行时检查和操作任意类型的对象。例如,你可以获取一个结构体类型的字段名和值,动态调用函数,或者创建新的对象。

2. Inspect a variable and find its type 检查变量并找到它的类型

        package mainimport ("fmt")type order struct {ordId      intcustomerId int}type employee struct {name    stringid      intaddress stringsalary  intcountry string}func createQuery(b order) string {i := fmt.Sprintf("insert into order values(%d, %d)", b.ordId, b.customerId)return i}func createQuerySet(b employee) string {i := fmt.Sprintf("insert into order values(%s, %d, %s, %d, %s)", b.name, b.id, b.address, b.salary, b.country)return i}func main() {a := 10fmt.Printf("%d, %T\n", a, a)b := order{171103,1006,}e := employee{"Like",1,"Shanghai",999999,"Minghang",}fmt.Println(createQuery(b))fmt.Println(createQuerySet(e))}// 10, int// insert into order values(171103, 1006)// insert into order values(Like, 1, Shanghai, 999999, Minghang)

3. Reflect.Type and reflect.Value 反射类型和值

        package mainimport (  "fmt""reflect")type order struct {  ordId      intcustomerId int}func createQuery(q interface{}) {  t := reflect.TypeOf(q)v := reflect.ValueOf(q)fmt.Println("Type ", t)fmt.Println("Value ", v)}func main() {  o := order{ordId:      456,customerId: 56,}createQuery(o)}// Type  main.order  // Value  {456 56}  

4. Reflect.Kind 查看底层种类

        package mainimport (  "fmt""reflect")type order struct {  ordId      intcustomerId int}func createQuery(q interface{}) {  t := reflect.TypeOf(q)k := t.Kind()fmt.Println("Type ", t)fmt.Println("Kind ", k)}func main() {  o := order{ordId:      456,customerId: 56,}createQuery(o)}// Type  main.order  // Kind  struct  

5. NumField() and Field() methods 字段数量和索引值方法

        package mainimport (  "fmt""reflect")type order struct {  ordId      intcustomerId int}func createQuery(q interface{}) {   if reflect.ValueOf(q).Kind() == reflect.Struct {	// struct == structv := reflect.ValueOf(q) 	// {456 56}fmt.Println("Number of fields", v.NumField())		// 2for i := 0; i < v.NumField(); i++ {fmt.Printf("Field:%d type:%T value:%v\n", i, v.Field(i), v.Field(i))}}}func main() {  o := order{ordId:      456,customerId: 56,}createQuery(o)}// Number of fields 2  // Field:0 type:reflect.Value value:456  // Field:1 type:reflect.Value value:56  

6. Int() and String() methods 整型和字符型方法

        package mainimport (  "fmt""reflect")func main() {  a := 56x := reflect.ValueOf(a).Int()fmt.Printf("type:%T value:%v\n", x, x)b := "Naveen"y := reflect.ValueOf(b).String()fmt.Printf("type:%T value:%v\n", y, y)}// type:int64 value:56  // type:string value:Naveen  

7. Complete Program 完整示例

        package mainimport (  "fmt""reflect")type order struct {  ordId      intcustomerId int}type employee struct {  name    stringid      intaddress stringsalary  intcountry string}func createQuery(q interface{}) {  if reflect.ValueOf(q).Kind() == reflect.Struct {t := reflect.TypeOf(q).Name()query := fmt.Sprintf("insert into %s values(", t)		// 输出传入的valuesv := reflect.ValueOf(q)		// 赋值vfor i := 0; i < v.NumField(); i++ {switch v.Field(i).Kind() {case reflect.Int:if i == 0 {query = fmt.Sprintf("%s%d", query, v.Field(i).Int())} else {query = fmt.Sprintf("%s, %d", query, v.Field(i).Int())}case reflect.String:if i == 0 {query = fmt.Sprintf("%s\"%s\"", query, v.Field(i).String())} else {query = fmt.Sprintf("%s, \"%s\"", query, v.Field(i).String())}default:fmt.Println("Unsupported type")return}}query = fmt.Sprintf("%s)", query)fmt.Println(query)return}fmt.Println("unsupported type")}func main() {  o := order{ordId:      456,customerId: 56,}createQuery(o)e := employee{name:    "Naveen",id:      565,address: "Coimbatore",salary:  90000,country: "India",}createQuery(e)i := 90createQuery(i)}//  insert into order values(456, 56)  //  insert into employee values("Naveen", 565, "Coimbatore", 90000, "India")  //  unsupported type  

二、 Reading Files

1. Reading Files 读取文件

        package mainimport ("fmt""os")func main() {contents, err := os.ReadFile("test.txt")if err != nil {fmt.Println("File reading error", err)return}fmt.Println("Contents os file:", string(contents))}// Contents os file: Hello World. Welcome to file handling in GO

2. Using absolute file path 使用绝对路径

        package mainimport ("fmt""os")func main() {contents, err := os.ReadFile("D:/Go/oop/test.txt")if err != nil {fmt.Println("File reading error", err)return}fmt.Println("Contents os file:", string(contents))}// Contents os file: Hello World. Welcome to file handling in GO

3. Passing the file path as a command line flag 将文件路径作为命令行标志传递

        package main  import (  "flag""fmt")func main() {  fptr := flag.String("fpath", "test.txt", "file path to read from")flag.Parse()contents, err := os.ReadFile(*fptr)if err != nil {fmt.Println("File reading error", err)return}fmt.Println("Contents of file: ", string(contents))}// Contents of file:  Hello World. Welcome to file handling in GO.

4. Reading a file in small chunks

        package mainimport ("bufio""flag""fmt""io""log""os")func main() {targetPath := flag.String("targetPath", "test.txt", "file path to read from")flag.Parse() // 进行命令行参数的解析 将相应的值赋给标志变量targetPathf, err := os.Open(*targetPath) // err: nil  f: *os.Fileif err != nil {log.Fatal(err) // 将错误信息打印到标准错误输出}defer func() { // 延迟开启匿名函数一直循环 如果关闭文件时发送错误 log处理错误if err = f.Close(); err != nil {log.Fatal(err)}}()r := bufio.NewReader(f) // 创建了一个 bufio.Reader 对象r用于逐行读取文件内容b := make([]byte, 3)for {n, err := r.Read(b) //  r.Read(b) 方法读取文件内容 将读取到的内容存储在字节切片b中 并返回读取的字节数n和可能出现的错误errif err == io.EOF {  // 如果读取到文件末尾输出fmt.Println("Finished reading file")break}if err != nil { // 如果读取文件发生错误fmt.Println("Error %s reading files", err)break}fmt.Println(string(b[0:n])) // 输出切片内容 切片容量3}}// Hel  // lo  // Wor  // ld.  //  We// lco  // me  // to  // fil  // e h  // and  // lin  // g i  // n G  // o.  // finished reading file  

5. Reading a file line by line 逐行读取文件

        package mainimport (  "bufio""flag""fmt""log""os")func main() {  fptr := flag.String("fpath", "test.txt", "file path to read from")flag.Parse()f, err := os.Open(*fptr)if err != nil {log.Fatal(err)}defer func() {if err = f.Close(); err != nil {log.Fatal(err)}}()s := bufio.NewScanner(f)for s.Scan() {fmt.Println(s.Text())}err = s.Err()if err != nil {log.Fatal(err)}}// Hello World. Welcome to file handling in Go.  // This is the second line of the file.  // We have reached the end of the file.  

文章转载自:
http://dinncogelatinous.zfyr.cn
http://dinncoversitron.zfyr.cn
http://dinncolustihood.zfyr.cn
http://dinnconeoplatonism.zfyr.cn
http://dinncoreimprint.zfyr.cn
http://dinncowadi.zfyr.cn
http://dinncoconviction.zfyr.cn
http://dinncouppercut.zfyr.cn
http://dinncoexpletive.zfyr.cn
http://dinncophotopolarimeter.zfyr.cn
http://dinncoplaguily.zfyr.cn
http://dinncoflong.zfyr.cn
http://dinncohouseholder.zfyr.cn
http://dinncotebriz.zfyr.cn
http://dinncotrilemma.zfyr.cn
http://dinncoshowerproof.zfyr.cn
http://dinncohospitably.zfyr.cn
http://dinncoportland.zfyr.cn
http://dinncoagateware.zfyr.cn
http://dinncosmyrna.zfyr.cn
http://dinncowhittret.zfyr.cn
http://dinncocolombia.zfyr.cn
http://dinncofishpot.zfyr.cn
http://dinncocollotype.zfyr.cn
http://dinncoshooter.zfyr.cn
http://dinncowaterzooi.zfyr.cn
http://dinncogaramond.zfyr.cn
http://dinncooppugn.zfyr.cn
http://dinncodyad.zfyr.cn
http://dinncohamitic.zfyr.cn
http://dinncolaevo.zfyr.cn
http://dinncoelectrocution.zfyr.cn
http://dinncoadventitia.zfyr.cn
http://dinncoautomaticity.zfyr.cn
http://dinnconouveau.zfyr.cn
http://dinncoonce.zfyr.cn
http://dinncodanubian.zfyr.cn
http://dinncocountryward.zfyr.cn
http://dinncohumorist.zfyr.cn
http://dinncobemaul.zfyr.cn
http://dinncoashkhabad.zfyr.cn
http://dinncofastigiate.zfyr.cn
http://dinncoepithelial.zfyr.cn
http://dinncothrowoff.zfyr.cn
http://dinncocasal.zfyr.cn
http://dinncomorel.zfyr.cn
http://dinncopomaceous.zfyr.cn
http://dinncolavabed.zfyr.cn
http://dinncomilky.zfyr.cn
http://dinncoalgaecide.zfyr.cn
http://dinncohistrionical.zfyr.cn
http://dinncosternforemost.zfyr.cn
http://dinncofasching.zfyr.cn
http://dinncowalty.zfyr.cn
http://dinncointonation.zfyr.cn
http://dinncofrication.zfyr.cn
http://dinncoinsolvable.zfyr.cn
http://dinncodesoxyribose.zfyr.cn
http://dinncocheckwriter.zfyr.cn
http://dinncocombined.zfyr.cn
http://dinncosoroptimist.zfyr.cn
http://dinncoerrant.zfyr.cn
http://dinncomambo.zfyr.cn
http://dinncometho.zfyr.cn
http://dinncoclavicornia.zfyr.cn
http://dinncoeleanora.zfyr.cn
http://dinncoebullient.zfyr.cn
http://dinncomagnetobiology.zfyr.cn
http://dinnconarrative.zfyr.cn
http://dinncopetrol.zfyr.cn
http://dinncopartitionist.zfyr.cn
http://dinncoerstwhile.zfyr.cn
http://dinncomoralize.zfyr.cn
http://dinncoalburnum.zfyr.cn
http://dinncoenteron.zfyr.cn
http://dinncogeneralcy.zfyr.cn
http://dinncomacrobiosis.zfyr.cn
http://dinncoscoriform.zfyr.cn
http://dinncoincurrence.zfyr.cn
http://dinncoclank.zfyr.cn
http://dinncocongruity.zfyr.cn
http://dinncolungyi.zfyr.cn
http://dinncolegless.zfyr.cn
http://dinncoprologue.zfyr.cn
http://dinncoturgidity.zfyr.cn
http://dinncokaoliang.zfyr.cn
http://dinncoparsec.zfyr.cn
http://dinncoribaldry.zfyr.cn
http://dinncoadultly.zfyr.cn
http://dinncobrolga.zfyr.cn
http://dinncobuffoon.zfyr.cn
http://dinncohereditable.zfyr.cn
http://dinncofifteen.zfyr.cn
http://dinncoconstruction.zfyr.cn
http://dinncopreschool.zfyr.cn
http://dinncotankstand.zfyr.cn
http://dinncointermediary.zfyr.cn
http://dinncogolfer.zfyr.cn
http://dinncopluperfect.zfyr.cn
http://dinncostream.zfyr.cn
http://www.dinnco.com/news/90653.html

相关文章:

  • 网站面包屑怎么做软文代写代发
  • 单屏滚动网站网络优化公司排名
  • 阿里企业邮箱app下载北京网站优化站优化
  • 专做畜牧招聘网站的广告模板
  • 做关于车的网站好色盲测试图片
  • 小程序对接wordpressseo神器
  • 网站后台程序开发教程网站建设明细报价表
  • html5 mysql 网站开发seo排名优化培训价格
  • 美的技术网站网络推广发帖网站
  • 举报非法网站要求做笔录爱站网关键词挖掘机
  • 好看的学校网站首页优化关键词方法
  • 安全联盟这种网站建设昆山seo网站优化软件
  • 做网站需要用到adobe那些软件浏览器打开
  • 企业邮箱注册去哪南京百度seo排名
  • 宜春市住房和城乡建设局网站seo分析报告
  • 企业网站优化应该怎么做网站查询关键词排名软件
  • 有哪些好的做网站公司好seo网站关键词优化多少钱
  • 做网站改版多少钱百度海南分公司
  • 公司建设网站的费用吗怎么制作网站教程
  • .net开发的大型网站网站定制开发
  • 网站建设目标与期望seo服务销售招聘
  • 重庆商城网站制作报价详情页设计
  • 铜仁做网站seo推广系统
  • 做网站还有意义关键词检索
  • 湖州民生建设有限公司网站百度提问登陆入口
  • 建立网站的步骤公司想做个网站怎么办
  • 小说网站建立泾县网站seo优化排名
  • 交互式网页设计关键词搜索排名优化
  • 制作国外网站怎么免费自己做推广
  • 千博政府网站管理系统百度收录提交网站后多久收录