
go语言学习
后台开发者Ethan
李大健一个想从事大数据的java开发者、go初级学习者
展开
-
2021-11-10
三个队列 runnext 、 local queue 、global queue 多级队列是为了解决程序的局部性问题,最新的程序 通常最近需要执行。go 创建runnext 为空的情况go func(){ println("hello world")}()此时runnext 不为空,新来一个踢走本地队列未满,放入到local queuelocal quque 满的情况拿出原来的一般和被踢走的G 组成一个新的链表 ...原创 2021-11-11 13:25:04 · 565 阅读 · 0 评论 -
go-errors
1、error接口提供Error() 方法供实现// http://golang.org/pkg/builtin/#errortype error interface { Error() string}// http://golang.org/src/pkg/errors/errors.gotype errorString struct { s string}// http://golang.org/src/pkg/errors/errors.gofunc (e *errorSt原创 2021-09-29 11:44:42 · 135 阅读 · 0 评论 -
类型断言assertion
类型断言有个非常好的使用场景:当某个类型为interface{}的变量,真实类型为A时,才做某件事时,这时可以使用类型断言,注意 x必须是接口类型x.(T):import "fmt"func printValue(v interface{}) { fmt.Printf("The value of v is: %v", v.(int))}func main() { v := 10 printValue(unc printValue(v interface{}) { if v,原创 2021-09-27 14:21:12 · 110 阅读 · 0 评论 -
interface and embedding
多态性:// Sample program to show how polymorphic behavior with interfaces.package mainimport ( "fmt")// notifier is an interface that defines notification// type behavior.type notifier interface { notify()}// user defines a user in the program原创 2021-09-16 11:29:57 · 117 阅读 · 0 评论 -
function-
function1 值类型或者指针类型都可以互相调用值接受者或者指针接受者2 是否改变原来的值 取决于接受者是值类型还是指针类型// Sample program to show how to declare methods and how the Go// compiler supports them.package mainimport ( "fmt")// user defines a user in the program.type user struct { na原创 2021-09-15 12:51:34 · 114 阅读 · 0 评论 -
map---
声明一个map var my map[int]int 这个map 是nil ,值为map[],长度为0 ,hash[key]=value 赋值报错,单允许访问 声明map make方式 var my make(map[T]T,num) ,num为初始map长度,默认为0 map的key 不能是function,slice,map,可以是bool,数字,string,指针,channer,interface,struct,array in short 可以用==判断 As men...原创 2021-09-15 11:07:28 · 72 阅读 · 0 评论 -
ex-常量
未定义类型常量和已定义类型常量constant a = 123等式左边已命名常量,右边是未命名常量,拥有未定义的类型。当有足够的内存来存储整数值时,可以始终精确地表示整数未命名常量只会在编译期间存在,因此其不会存储在内存中,而命名常量存在于内存静态只读区,不能被,Go语言禁止了对常量取地址的操作// Constants live within the compiler. // They have a parallel type system. // Compiler can per..原创 2021-09-13 15:56:19 · 126 阅读 · 0 评论 -
go反射-
var z = 123var y = &zvar x interface{} = yfmt.Println("y ",reflect.ValueOf(y))fmt.Println("x ",reflect.ValueOf(x))reflect.ValueOf(y) 和 reflect.ValueOf(x) 都是 &z 即123的地址如果var x interface{} = &y 那么reflect.ValueOf(x) 就是&y...原创 2021-08-30 16:40:18 · 171 阅读 · 0 评论 -
go-关于nil
在go语言中nil只是一个变量名,buildin/buildin.go 中 定义// nil is a predeclared identifier representing the zero value for a// pointer, channel, func, interface, map, or slice type.var nil Type // Type must be a pointer, channel, func, interface, map, or slice ty...原创 2021-08-10 16:36:09 · 638 阅读 · 0 评论 -
goland-gopath
通过在goland 的terminal 可以go env 可以查看到go 配置set GO111MODULE=onset GOPATH=D:\opt\gopath;C:\Users\lixiaojian\go电脑上powderShell go env 查看set GOPATH=C:\Users\lixiaojian\gogoland 的go 配置仅限goland编译器关于下载包的问题当我们开启go mod 模式 go env -w GO111MODULE=on 即s...原创 2021-07-29 15:40:53 · 528 阅读 · 0 评论 -
go相关知识
g1 := model.GormUser{ ID: 10, Name: "", Age: 30,}gv1 := reflect.ValueOf(&g1)gv1 := reflect.ValueOf(g1)reflect.valueof 方法获取新创建变量的地址,,一般该方法返回的是传入变量的一份值复制。此处直接传递变量的地址,得到的也是变量的地址对象。然后调用Elem方法获取地址指针指向的值封装。如果传递的是g1 非指针类,那么不可对其进行修改,应为..原创 2021-07-15 00:31:57 · 75 阅读 · 0 评论 -
关于struct方法的值接受者和指针接受者问题
type Student struct { Mame string `json:"mame" form:"fname"` Age int `json:"jage" from:"fage"` Email string}func (s Student) Change(i int) { s.Age = i}func (s *Student) Change2(i int) { s.Age = i}change方法 是值接受者:它可以用指针类型调用也可以用值类型调用用值类型调用:.原创 2021-07-01 01:16:38 · 126 阅读 · 0 评论 -
go-OAuth2.0
注册在https://github.com/settings/applications/new注册一个应用,获取clientId 和 client secrets通过github进行授权前段页面 访问:<a href="https://github.com/login/oauth/authorize?client_id=e511f4733c56d5487d5d&redirect_uri=http://localhost:8087/oauth/redirect">..原创 2021-06-30 00:24:53 · 924 阅读 · 0 评论 -
go rpc
// Code generated by protoc-gen-go. DO NOT EDIT.// versions:// protoc-gen-go v1.26.0// protoc v3.14.0// source: test.protopackage bbbimport ( context "context" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status .原创 2021-03-24 01:07:02 · 174 阅读 · 0 评论