golang type 说明和使用

我对type不了解,因为我没有完整的看完一本讲golang的书,我学习golang的过程基本都是在看源码的过程中,遇到不懂得先猜一下,后续有时间去查一查这个概念。

1、type 和 struct

我最先见到的类似的使用方式,以为type就是用来定义结构体的呢,片面了。后面才知道type的其他使用方式。

type Student struct {
id int
name string
}

2、type 和interface

关于interface我也不熟悉,还需要看看。

type People interface {
	SayHello()
	GetDetails()
}

type HandlerFunc func(ResponseWriter, *Request)

3、类型定义

4、类型别名

posted @ 2022-03-06 10:37  叶常落  阅读(3)  评论(0编辑  收藏  举报