Go语言中文网 为您找到相关结果 14

golang 声明常量

*声明一个常量 const MAX = 4096 *声明一个指定类型的常量 const LIMIT int16 = 1024 const LIMIT2 = int16(1024) *声明一组常量 const ( start = 0x1 resume = 0x2 stop = 0x4 ) *声明一组指定类型的常量 const ( start int8 = 0x1 resume int8 = 0x2 stop int8 = 0x4 ) *用iota简化上面的写法 const ( start int8 = 1 << iota resume stop ...阅读全文

博文 2015-05-10 12:00:03 guonaihong

两行开启Go http quic

QUIC,简单来说,就是使用UDP的传输协议,根据Google自己的报告,速度可以加快30%。 主要优点有: 1. 快速建立链接(不用3次握手和TLS4次握手) 2. 多路复用 3. 改进的流控 4. 快速SSL/TLS握手 5. 适合移动用户访问 quic-layer 这么好的性能,当然要赶紧用Go试试看。 https://github.com/lucas-clemente/quic-go 示例中的代码也很简单。 http.Handle("/", http.FileServer(http.Dir(wwwDir))) h2quic.ListenAndServeQUIC("localhost:4242", "/path/to/cert/chain.pem", "/path/to/privkey...阅读全文

博文 2017-08-26 09:09:44 zhuo/blog

Golang 格式化json忽略指定的字段

如下的结构体,格式化为json时我想忽略DataSource字段 type RealTimeData struct { Code string `json:"code"` Time time.Time `json:"time"` OpenPrice float32 `json:"openPrice"` PrevClosePrice float32 `json:"prevClosePrice"` LastPrice float32 `json:"lastPrice"` HighPrice float32 `json:"highPrice"` LowPrice float32 `json:"lowPrice"` MarketValue float32 `json:"marketValue"` P...阅读全文

博文 2019-08-10 23:32:56 鹅鹅鹅_

go 语言 Makefile 指定依赖包位置

编译 go 程序可以使用自带的一些 Makefile 脚本来简化编写 Makefile 。官方的文档过于简略,没提到需要指定依赖包位置的方法。翻过那几个脚本代码后,发现原来有 LDIMPORTS 和 GCIMPORTS 可以指定。 比如: include $(GOROOT)/src/Make.inc LDIMPORTS=-L ./pkg/_obj GCIMPORTS=-I ./pkg/_obj TARG=tool GOFILES=\ tool.go\ include $(GOROOT)/src/Make.cmd GCIMPORTS 指定编译阶段的参数,对 Make.cmd,Make.pkg 都有效。LDIMPORTS 指定链接阶段的参数,这个对 Make.pkg 就没用了。 另外,还可以用类...阅读全文

博文 2014-10-04 19:26:42 shihao