GoLang学习心得
__Lambda__
平常心,谦逊和礼貌
展开
-
MacOS下为golang配置Protobuf
首先去github下载protobuf如果电脑没有配置gcc,那么需要撞上gcchttps://github.com/protocolbuffers/protobuf按照描述执行编译文件进行编译./configuremake make check make install每步在执行过程中注意权限问题,有的命令不sudo执行会出问题。执行完成后,执行protoc --version,如果输出版本,那么就代表安装成功。除了protoc,我们还需要protoc-gen-go原创 2021-06-27 14:25:24 · 339 阅读 · 0 评论 -
golang结构体与方法
type People interface { Speak(string) string}type Student struct{}func (stu *Student) Speak(think string) (talk string) { if think == "speak" { talk = "speak" } else { talk = "hi" } return}func main() { var p原创 2021-02-07 11:41:50 · 316 阅读 · 0 评论 -
Go语言defer与函数返回值的陷阱
func test() (ret int){ ret = 10 return 1}函数的返回值是1func test01() (ret int){ defer func(){ ret = 10 }() return 1}函数的返回值是10func test02() (ret int){ defer func(){ ret += 10 }() return 1}函数的返回值是11func test03() (ret int){ ret = 10 defer原创 2020-11-22 12:14:01 · 753 阅读 · 0 评论 -
Go语言桥连接
func structBridge(v interface{},funcName string,args...interface{}){ rVal := v.(reflect.Value) vFunc := rVal.MethodByName(funcName) input := make([]reflect.Value, len(args)) for i, _ := range args { input[i] = reflect.ValueOf(args[i原创 2020-11-18 16:44:54 · 148 阅读 · 0 评论 -
GoLang中方法与结构体暧昧不清的地方
package mainimport( "fmt" "reflect")type Student struct { Name string Age int}func (this *Student)SetName(theName string) { (*this).Name = theName}// func (this Student)SetName(theName string) {// this.Name = theName// }func main() .原创 2020-10-11 12:17:49 · 132 阅读 · 0 评论