<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>golang on Tequila's 学习笔记</title><link>https://latnx.github.io/docs/notes/d-205f3859abe469be/d-f7ccae636d10bb41/</link><description>Recent content in golang on Tequila's 学习笔记</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><copyright>© 2026 Tequila</copyright><atom:link href="https://latnx.github.io/docs/notes/d-205f3859abe469be/d-f7ccae636d10bb41/index.xml" rel="self" type="application/rss+xml"/><item><title>反射</title><link>https://latnx.github.io/docs/notes/d-205f3859abe469be/d-f7ccae636d10bb41/n-b79d65cb92567a70/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://latnx.github.io/docs/notes/d-205f3859abe469be/d-f7ccae636d10bb41/n-b79d65cb92567a70/</guid><description>反射就是程序在运行时能够检测自身和修改自身的一种能力。
用途 # json 序列化和反序列化 ORM 配置文件解析yaml，ini
reflect # reflect.TypeOf() # func reflectType(x interface{}){ obj := reflect.TypeOf(x) fmt.Println(obj) } package main import ( &amp;#34;fmt&amp;#34; &amp;#34;reflect&amp;#34; ) type myInt int64 func reflectType(x interface{}) { t := reflect.TypeOf(x) fmt.Printf(&amp;#34;type:%v kind:%v\n&amp;#34;, t.Name(), t.Kind()) } func main() { var a *float32 // 指针 var b myInt // 自定义类型 var c rune // 类型别名 reflectType(a) // type: kind:ptr reflectType(b) // type:myInt kind:int64 reflectType(c) // type:int32 kind:int32 type person struct { name string age int } type book struct{ title string } var d = person{ name: &amp;#34;沙河小王子&amp;#34;, age: 18, } var e = book{title: &amp;#34;《跟小王子学Go语言》&amp;#34;} reflectType(d) // type:person kind:struct reflectType(e) // type:book kind:struct } Go语言的反射中像数组、切片、Map、指针等类型的变量，它们的.</description></item><item><title>泛型</title><link>https://latnx.github.io/docs/notes/d-205f3859abe469be/d-f7ccae636d10bb41/n-f153110138845055/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://latnx.github.io/docs/notes/d-205f3859abe469be/d-f7ccae636d10bb41/n-f153110138845055/</guid><description>func sumGeneric[T int | float64](numbers []T) T { var total T for _, num := range numbers { total += num } return total } 泛型为Go语言引入了三个重要的新特性：
支持在函数和类型定义中使用类型参数,使其更加通用。 扩展了接口的概念,使其可以表示一组类型的集合,不再局限于方法集。 引入智能类型推导机制,在很多场景下可以省略显式的类型参数。 类型也可以使用泛型 # 要使用泛型类型，必须进行实例化。
type List[T any] []T type Pair[K comparable, V any] struct { Key K Value V } type Node[T any] struct { next *Node[T] value T } type Vector []int32 func MultiplyEach[E constraints.Integer](s []E, factor E) []E MultiplyEach(Vector{1,2,3}, 3) -&amp;gt;MultiplyEach([]int32, int32) []int32 func MultiplyEach[S ~[]E, E constraints.</description></item></channel></rss>