随笔分类 -  golang

摘要:package main import ( "context" "log" ) func main() { _Handler( "hello", context.Background(), multi([]Interceptor{A, B}...), ) } func A(ctx context.C 阅读全文
posted @ 2021-10-06 00:30 gdut17 阅读(55) 评论(0) 推荐(0)
摘要:1.当结构体实现了某个接口的所有方法,结构体指针可转换为接口类型 package main import "fmt" type service interface { Get(string) (string, error) Print() } type node struct { } func (n 阅读全文
posted @ 2021-08-31 23:56 gdut17 阅读(207) 评论(0) 推荐(0)
摘要:这里讨论复用context的情况 package main import ( "context" "fmt" "time" ) func main() { // 传递带超时的上下文告诉阻塞函数 // 超时过后应该放弃它的工作。 ctx, cancel := context.WithTimeout(c 阅读全文
posted @ 2021-08-31 23:45 gdut17 阅读(307) 评论(0) 推荐(0)
摘要:package main import ( "net" "time" ) func main() { addr := "127.0.0.1:80" netAddr := &net.TCPAddr{Port: 6666} d := net.Dialer{LocalAddr: netAddr} cc, 阅读全文
posted @ 2021-07-17 16:44 gdut17 阅读(890) 评论(0) 推荐(0)