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

go proxy 设置

在Go 1.13中,我们可以通过GOPROXY来控制代理,以及通过GOPRIVATE控制私有库不走代理。 设置GOPROXY代理: go env -w GOPROXY=https://goproxy.cn,direct 设置GOPRIVATE来跳过私有库,比如常用的Gitlab或Gitee,中间使用逗号分隔: go env -w GOPRIVATE=*.gitlab.com,*.gitee.com 如果在运行go mod vendor时,提示Get https://sum.golang.org/lookup/xxxxxx: dial tcp 216.58.200.49:443: i/o timeout,则是因为Go 1.13设置了默认的GOSUMDB=sum.golang.org,这个网站是...阅读全文

博文 2019-10-09 18:32:46 aside section ._1OhGeD

Go 1.13设置代理

在Go 1.13中,我们可以通过GOPROXY来控制代理,以及通过GOPRIVATE控制私有库不走代理。 设置GOPROXY代理: go env -w GOPROXY=https://goproxy.cn,direct 设置GOPRIVATE来跳过私有库,比如常用的Gitlab或Gitee,中间使用逗号分隔: go env -w GOPRIVATE=*.gitlab.com,*.gitee.com 如果在运行go mod vendor时,提示Get https://sum.golang.org/lookup/xxxxxx: dial tcp 216.58.200.49:443: i/o timeout,则是因为Go 1.13设置了默认的GOSUMDB=sum.golang.org,这个网站是...阅读全文

博文 2019-09-26 14:33:27 aside section ._1OhGeD

golang 二维slice初始化

二维slice有多个一维slice元素组成,显然,每个元素的长度不必一致。 a := [][]float64{ {1, 2, 3, 4}, {12, 21, 3, 14}, {1, 1, 2, 3}, {2, 3, 1, 6}, {2, 2, 3, 3}, {1, 1, 1, 1}} 1、应有二维的类型, 2、大花括号下的每个小花括号后均有逗号,最后一个除外 3、最后的大花括号应与最后一个元素在一行,挨着最后的小花括号 a := [][4]float64{//限定4列 {1, 2, 3, 4}, {12, 21, 3, 14}, {1, 1, 2, 3,5},//5个数 {2, 3, 1, 6}, {2, 2, 3, 3}, {1, 1, 1, 1}} 编译会出错:out of bound...阅读全文

博文 2017-07-22 10:03:29 小白雕

解决Get https://sum.golang.org/lookup/xxxxxx: dial tcp 2 i/o timeout问题

自:作者:癞痢头链接:https://www.jianshu.com/p/e0c878d4ca19来源:简书在Go 1.13中,我们可以通过GOPROXY来控制代理注意 : 通过 GOPRIVATE 控制私有库不走代理设置GOPROXY代理:goenv-w GOPROXY=https://goproxy.cn,direct设置GOPRIVATE来跳过私有库,比如常用的Gitlab或Gitee,中间使用逗号分隔:goenv-w GOPRIVATE=*.gitlab.com,*.gitee.com如果在运行go mod vendor时,提示Get https://sum.golang.org/lookup/xxxxxx: dial tcp 216.58.200.49:443: i/o timeo...阅读全文

博文 2019-10-21 23:32:54 aside section._1OhGeD

golang-利用反射给结构体赋值

由于想给一个结构体的部分成员赋值,但是有不知道具体名字,故将tag的json名字作为索引,按照json名字来一一赋值 //将结构体里的成员按照json名字来赋值 func SetStructFieldByJsonName(ptr interface{}, fields map[string]interface{}) { logger.Debug("fields:", fields) v := reflect.ValueOf(ptr).Elem() // the struct variable for i := 0; i < v.NumField(); i++ { fieldInfo := v.Type().Field(i) // a reflect.StructField tag := fi...阅读全文

博文 2017-11-06 01:00:01 fwdqxl

golang 处理数字3位一组展示,中间用逗号分开

package main import ( "fmt" "strings" ) func main() { strResult := NumberFormat("1234567898.55") fmt.Println(strResult) } //格式护数值 1,234,567,898.55 func NumberFormat(str string) string { length := len(str) if length < 4 { return str } arr := strings.Split(str, ".") //用小数点符号分割字符串,为数组接收 length1 := len(arr[0]) if length1 < 4 { return str } count := (le...阅读全文

博文 2017-12-28 01:21:12 18393910396

golang 远程连接mssql 2000

package main import ( "database/sql" "flag" "fmt" "log" ) import ( _ "github.com/mattn/go-adodb" ) var ( local bool remoteIP string remoteDS string ) func init() { flag.BoolVar(&local, "local", true, "set window connect.") flag.StringVar(&remoteIP, "remoteIP", "192.168.1.104", "set up remote mssql of ip.") flag.StringVar(&remoteDS, "remoteDS", "MSS...阅读全文

博文 2016-07-14 11:00:06 CodyGuo

Go 1.13设置代理

在Go 1.13中,我们可以通过GOPROXY来控制代理,以及通过GOPRIVATE控制私有库不走代理。 设置GOPROXY代理: go env -w GOPROXY=https://goproxy.cn,direct 设置GOPRIVATE来跳过私有库,比如常用的Gitlab或Gitee,中间使用逗号分隔: go env -w GOPRIVATE=*.gitlab.com,*.gitee.com 如果在运行go mod vendor时,提示Get https://sum.golang.org/lookup/xxxxxx: dial tcp 216.58.200.49:443: i/o timeout,则是因为Go 1.13设置了默认的GOSUMDB=sum.golang.org,这个网站是...阅读全文

博文 2019-09-05 17:32:46 shallot

Go学习笔记之:Switch 语句

当条件判断分支太多的时候,我们会使用switch语句来优化逻辑。 package main import "fmt" import "time" func main() { // 基础的switch用法 i := 2 fmt.Print("write ", i, " as ") switch i { case 1: fmt.Println("one") case 2: fmt.Println("two") case 3: fmt.Println("three") } // 你可以使用逗号来在case中分开多个条件。还可以使用default语句, // 当上面的case都没有满足的时候执行default所指定的逻辑块。 switch time.Now().Weekday() { case ti...阅读全文

博文 2014-11-27 23:00:03 Goopand

m3u文件转pls文件(go语言实现)

m3u是一种文件格式,类似于下: #EXTINF:,CCTV 1 mms://live.cctv.com/cctv_live1 #EXTINF:,CCTV 2 mms://live.cctv.com/live12 比如第一行是#EXTINF:,CCTV 1,那么用逗号隔开的第2个字符串就是文件名称;而第二行则是文件路径 对应的pls文件如下: [playlist] NumberOfEntries=116 File1=mms://live.cctv.com/cctv_live1 Title1=CCTV 1 File2=mms://live.cctv.com/live12 Title2=CCTV 2 它会指明总共有多少个个文件,文件名和文件路径(以key=val这种形式展示) 下面就是利用程序将...阅读全文

博文 2016-02-16 21:00:02 rongyongfeikai2

ok 是怎么赋值的

```go func main() { //声明 m2 := map[string]string{ "a": "aaaa", // "b": "bbbb", //这个也要有逗号 } fmt.Println(m2) //修改 m2["a"] = "cccc" fmt.Println(m2) //增加 m2["c"] = "cccc" fmt.Println(m2) //删除 delete(m2, "c") fmt.Println(m2) //判断键值对是否存在 if v, ok := m2["a"]; ok { fmt.Println(v) fmt.Println(ok) } else { ...阅读全文

Golang的func参数及返回值

参数及返回值 参数一指定数据类型为int 参数二 (...interface{}) 可传任何多个类型的参数 返回值:单个返回值直接指定数据类型可以不使用 (),多个返回值需使用()。各返回值之间使用逗号分隔 func main() { demo.Params(10, 20, "golang", true) } func Params(id int, params ...interface{}) (error, error) { fmt.Println(id) fmt.Println(params[0]) fmt.Println(params[1]) fmt.Println(params[2]) for key, val := range params { fmt.Println("key",...阅读全文

博文 2020-04-01 09:33:03 是个懒人

go语言:switch语句

go语言专门用于多条件分支语句。 这里有个基本的switch语句。 在同一个case语句中,可以用逗号分隔不同的条件。在这个例子中,我们使用默认的default语句。 没有表达式的switch语句可以替代if/else语句。这里我们显示了case表达式可以不是常量。 Plain Text code ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 package main import "fmt" import "time" func main() { i := 2 fmt.Print("write ", i, " as ") switch i { case 1: fmt.Pr...阅读全文

博文 2015-06-17 23:01:41 xming4321

golang 学习笔记

golan 声明的变量必须要用到? 语法 a,b:=2323; b为 bool 类型 结构体的赋值 需要用到逗号分隔字段 并且最后一个字段后也必须加上逗号 这和 JavaScript 的对象不一样哦 golang 要严谨写 type person struct{ name string old int } func main(){ a:=person{ name:'feifei', old:12 ,// 这里的逗号不能少 JavaScript中可以少的 } ...阅读全文

博文 2016-03-17 21:00:02 freefei

golang跨域配置

//值可以设为星号,也可以指定具体主机地址,可设置多个地址用逗号隔开,设为指定主机地址第三项才有效 ctx.Header("Access-Control-Allow-Origin", "http://192.168.5.106:8080") //允许请求头修改的类容 ctx.Header("Access-Control-Allow-Headers", "Content-Type") //允许使用cookie ctx.Header("Access-Control-Allow-Credentials", "true"...阅读全文

博文 2019-02-27 09:34:41 不浪人

Go by Example: Switch

Switch声明通过众多分支来表达条件判断。 package main import "fmt" import "time" func main() { // 基础的switch用法 i := 2 fmt.Print("write ", i, " as ") switch i { case 1: fmt.Println("one") case 2: fmt.Println("two") case 3: fmt.Println("three") } // 你可以使用逗号来在case中分开多个条件。还可以使用default语句。 // 当上面的case都没有满足的时候执行default所指定的逻辑块。 switch time.Now().Weekday() { case time.Saturda...阅读全文

博文 2015-06-18 09:03:53 codemanship

golang 远程连接mssql 2000

package main import ( "database/sql" "flag" "fmt" "log" ) import ( _ "github.com/mattn/go-adodb" ) var ( local bool remoteIP string remoteDS string ) func init() { flag.BoolVar(&local, "local", true, "set window connect.") flag.StringVar(&remoteIP, "remoteIP", "192.168.1.104", "set up remote mssql of ip.") flag.StringVar(&remoteDS, "remoteDS", "MSS...阅读全文

博文 2016-09-07 12:00:02 CodyGuo

golang 远程连接mssql 2000

package main import ( "database/sql" "flag" "fmt" "log" ) import ( _ "github.com/mattn/go-adodb" ) var ( local bool remoteIP string remoteDS string ) func init() { flag.BoolVar(&local, "local", true, "set window connect.") flag.StringVar(&remoteIP, "remoteIP", "192.168.1.104", "set up remote mssql of ip.") flag.StringVar(&remoteDS, "remoteDS", "MSS...阅读全文

博文 2016-09-07 15:00:03 CodyGuo

golang 远程连接mssql 2000

package main import ( "database/sql" "flag" "fmt" "log" ) import ( _ "github.com/mattn/go-adodb" ) var ( local bool remoteIP string remoteDS string ) func init() { flag.BoolVar(&local, "local", true, "set window connect.") flag.StringVar(&remoteIP, "remoteIP", "192.168.1.104", "set up remote mssql of ip.") flag.StringVar(&remoteDS, "remoteDS", "MSS...阅读全文

博文 2016-09-07 13:00:02 CodyGuo

Go 第二部分:分支语句、函数

这是 Go 系列的第二篇文章,主要介绍 if/else , switch 和函数的各种用法。 系列整理: Go 第一部分:变量、常量和枚举类型 如果对 Go 语言本身感兴趣,可以阅读我的这篇译文 Go语言的优点,缺点和令人厌恶的设计。 if/else // 声明可以先于条件,if 中的声明的变量只在此 if/else 有效 if num := 9; num < 0 { } else if num < 10 { } else { } switch // 普通 switch switch time.Now().Weekday() { // 可以用逗号写多个值 case time.Saturday, time.Sunday: fmt.Println("It's the weekend") defa...阅读全文

博文 2018-05-08 18:34:38 彼得堡的遗书

go代理设置转载https://www.cnblogs.com/lijiejoy/p/11520944.html

在Go 1.13中,我们可以通过GOPROXY来控制代理,以及通过GOPRIVATE控制私有库不走代理。 设置GOPROXY代理: go env -w GOPROXY=https://goproxy.cn,direct 设置GOPRIVATE来跳过私有库,比如常用的Gitlab或Gitee,中间使用逗号分隔: go env -w GOPRIVATE=*.gitlab.com,*.gitee.com 如果在运行go mod vendor时,提示Get https://sum.golang.org/lookup/xxxxxx: dial tcp 216.58.200.49:443: i/o timeout,则是因为Go 1.13设置了默认的GOSUMDB=sum.golang.org,这个网站是...阅读全文

博文 2020-02-05 19:32:45 风洛神