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

golang的slice作为函数参数传值的坑

直接贴代码 func sliceModify(slice []int) { // slice[0] = 88 slice = append(slice, 6) } func main() { slice := []int{1, 2, 3, 4, 5} sliceModify(slice) fmt.Println(slice) } 返回的没变,坑爹的,这个设计太那啥了,可以正确跑出效果的版本如下: func sliceModify(slice *[]int) { *slice = append(*slice, 6) } func main() { slice := []int{1, 2, 3, 4, 5} sliceModify(&slice) fmt.Println(slice) ...阅读全文

博文 2014-10-04 19:26:12 ziyouchutuwenwu

华为云 路由器的天坑

问题在华为云服务器上使用Golang直接监听UDP端口,外部将无法访问这些端口,因为华为云服务器的路由不会允许外部与这些UDP端口直接通信。即便在配置了安全组以后亦是如此。解决方案Golang 建立连接后,使用 conn.Write() 写入部分数据即可(无需指定目的地)。如此一来,华为云的路由器便能放行此 UDP 端口。问题猜测华为云路由器的 NAT 算法应该是华为自己魔改的。尽管外网 IP 对 服务器内网IP是 1对1 的,但路由器对外部的访问存在限制。需要像 IP限制锥形 NAT 一样向往外发送数据后才能正常使用...阅读全文

博文 2020-05-05 05:32:43 鹿沐浔

golang坑

1.新建文件后再删除失败,提示文件正在被另一程序使用中(The process cannot access the file because it is being used by another process.) func main() { NewConfigIni() DeleteConfigTemp() } func DeleteConfigTemp() { path := "time.ini" err := os.Remove(path) //如果文件不存在时执行会报错 fmt.Println("删除ini err:", err) } func NewConfigIni() { os.Create("time.ini") } 修正: func NewConfigIni() { f,...阅读全文

博文 2014-10-04 19:27:22 陈好

GO语言学习笔记(二) - GUI For Go(基于Electron)

GO语言学习笔记(二) - GUI For Go(基于Electron)前言网上找了一下Golang的GUI,然后找到了一个基于Electron的介绍。一开始觉得应该比较简单,但是还是碰到各种坑。所以将碰到的一些坑和解决方法在这里记录一下。使用Eletron作为Golang GUI的文章链接:https://studygolang.com/articles/12065?fr=sidebar简介>>>阅读全...阅读全文

博文 2018-08-31 15:37:29 倔强_beaf

golang实现http post

package main import ( "fmt" "io/ioutil" "net/http" "net/url" "strings" ) func main() { v := url.Values{} v.Set("huifu", "hello world") body := ioutil.NopCloser(strings.NewReader(v.Encode())) //把form数据编下码 client := &http.Client{} req, _ := http.NewRequest("POST", "http://192.168.2.83:8080/bingqinggongxiang/test2", body) req.Header.Set("Content-Type"...阅读全文

博文 2016-11-18 11:00:08 徐学良

golang新版本对于cgo支持的一个坑

文件test.h如下 #ifndef _TEST_H #define _TEST_H #ifdef __cplusplus extern "C" { #endif extern void myTest(); #ifdef __cplusplus } #endif #endif 文件test.cc如下 #include "_cgo_export.h" extern "C" { void myTest() { test(); } } 文件test.go如下 package test /* #include "test.h" */ import "C" import () func Test() { C.myTest() } //export test func test() { println(...阅读全文

博文 2015-06-17 20:17:42 HopingWhite

go mysql 的坑

url := m.meta_user + ":" + m.meta_passwd + "@tcp(" + m.meta_host + ":" + strconv.Itoa(m.meta_port) + ")/" + m.meta_db + "?autocommit=true&charset=utf8" m.conn, err = sql.Open("mysql", url) if err != nil { panic(err) } 这段代码 只是作为mysql的建立连接使用,看似没问题。 实际上, 只要这些连接参数是合法的, err永远是nil的,你肯定期连接失败的时候报错的,实际却不会,这是因为: Open may just validate its arguments without c...阅读全文

博文 2016-01-30 16:00:02 frankwangzy1103

golang链接mssql数据库挖坑,填坑

先是用了github.com上面星星最多的一个库 "github.com/denisenkom/go-mssqldb",可是死活连不上我的mssqldb,提示是Login Error:EOF,搞不清怎么回事。后来没办法又查到一个 "github.com/mattn/go-adodb" 说是用的原生的activex?不知道能不能跨平台了。不过这个可以连接到我的mssql.先凑合着用吧。 之前链接到mysql ,tdib 都是好好的,mssql咋这么不靠谱了。type Mssql struct { *sql.DB dataSource string database string windows bool sa SA}type SA struct { user string passwd str...阅读全文

博文 2019-03-21 01:34:40 毛毛v5

golang坑之 'godoc' 不是内部或外部命令,...

@[TOC](golang坑之 'godoc' 不是内部或外部命令,...) golang坑之 'godoc' 不是内部或外部命令,... 最近接触了一点golang, 发现这个语言蛮有趣的, 因为第一次接触, 还是遇到了不少坑, 记录一次'godoc' 不是内部或外部命令,...的坑. 前言 因为我下载的是最新的版本的go1.13, 在某个旧版本前, golang好像就去除了godoc工具, 要另行编译,在官方x包tools库下的cmd有个godoc. 可以自行下载进行install到gopath目录. 也可参照此教程, 少踩坑(调皮) ! 前提准备: 拥有最基本的Go环境 gopm安装 gopm 可以帮助我们拉取需要翻墙的go资源 我遇到的坑 我的坑 前面说过了, 这是因为我下载的是最新...阅读全文

博文 2020-03-09 15:35:57 Iven_Colt

mac 上手GoLand-EAP

GoLand-EAP确实时golang开放的利器,不过mac上安装时有个大坑,就是DEBUG无法使用。 OS版本10.10.5 ,设置debug断点时,会panic。 最后解决方法。 1. 将sdk的版本,从go 1.7升级到1.9 可以在Preferences->GO->GoROOT中修改 2. Debugger的 Use native backend勾选 可以在Preferences->GO->Build,Execution,Deployment->Debugger中勾...阅读全文

博文 2017-11-29 02:10:03 nbg_xuan

golang中的坑

package main import ( "fmt" ) func main() { t1 := []int32{1, 2, 3} fmt.Println(printSelf(t1)) fmt.Println(t1) fmt.Println("................................") t2 := &[]int32{1, 2, 3} fmt.Println(&t2) t3 := printAddr(t2) fmt.Println(&t2, *t2) fmt.Println(&t3) fmt.Println("--------------------------------") t4 := []int32{1, 2, 3} fmt.Println(t4) print...阅读全文

博文 2016-03-06 12:00:01 samete

Golang的坑socket too many open file

第一个方法是用一个全局的client,函数DoRequest()中每次都只在这个全局client上发送数据。 第二个方法是在transport分配时将它的DisableKeepAlives参数置为false,像下面这样: transport := http.Transport{ Dial: dialTimeout, DisableKeepAlives: false, } client := http.Client{ Transport: &transport, ...阅读全文

博文 2018-10-23 16:34:50 Feng_Sir

golang time包t.After的坑

代码如下 package main import ( "fmt" "sync" "time" ) func main() { const FORMAT = "2006-01-02 15:04:05" var a = new(sync.Map) b := time.Now() fmt.Println(b.Location()) a.Store("a", b) //c, _ := a.Load("a") fmt.Println(b.Format(FORMAT)) time.Sleep(time.Second * 10) after := time.Hour * 5 //t, ok := c.(time.Time); ok && t := b if t.Add(after).After(time....阅读全文

博文 2019-07-11 10:32:42 悟道人

golang初试:坑爷的

用Golang与perl脚本比较, 初想至多差一倍吧...结果可不是一般的坑爹, 简直就是坑爷了. Perl脚本 #!/bin/bash source /etc/profile; function extractAndZip(){ _debug "$FUNCNAME,$@"; local logFile="${2}" local gzipFile="${1}" perl -ne 'if(m/([^ ]*) \- ([^ ]*) \[([^ ]*) [\+\-][0-9]{4}\] \"(\-|(([^ ]*) )?([^\?\;\% ]*)([\?\;\%]([^ ]*))?( ([^\"]*))?)\" ([^ ]*) ([^ ]*) \"([^\"]*)\" \"([^\"]*)\" \...阅读全文

博文 2016-09-09 18:00:01 zolo

golang 如何将imagemagick 和golang 打包到docker 环境中

公司最近开发了个项目,用到了imagemagick 和golang 环境,在我本地机上开发妥妥的,结果准备部署到线上环境的时候,出现了大坑,尝试了无数次后,最后还是解决了,官方说有问题也不说清楚点,一步一步的摸索直接上最后的代码吧 FROM golang MAINTAINER jackluo RUN apt-get update && apt-get install -y --no-install-recommends libwebp-dev libjpeg-dev libpng-dev wget freetype2-demos libfreetype6-dev libfreetype6 RUN wget https://www.imagemagick.org/download/ImageM...阅读全文

博文 2017-12-01 00:00:01 jackluo

golang初试:坑爷的

http://www.jiaoyou8.com/friends_diary/IntOTherAin/9_9_2016/view_24094709_no_2016_0909.html http://www.jiaoyou8.com/friends_diary/Terrence09/9_9_2016/view_24094710_no_2016_0909.html http://www.jiaoyou8.com/friends_diary/WEICHENGXUN/9_9_2016/view_24094712_no_2016_0909.html http://www.jiaoyou8.com/friends_diary/IntOTherAin/9_9_2016/view_24094716_no_20...阅读全文

博文 2016-09-08 17:00:02 bbwangmail

hdu 5546/Ancient Go

Problem Description Yu Zhou likes to play Go with Su Lu. From the historical research, we found that there are much difference on the rules between ancient go and modern go. Here is the rules for ancient go they were playing: ⋅The game is played on a 8×8 cell board, the chess can be put on the intersection of the board lines, so there are 9×9 diffe...阅读全文

博文 2016-10-05 15:00:02 qq_32944513

Godep使用中的坑,求指导

1. Godep 使用 Restore之后将下载下来的包放在了github.com的目录下,而没有放在Vendor目录下,我想把下载下来的包放到vendor的目录下,但是执行godep save [package]没有反映,使用Godep怎样才能做到我要的效果? 2. 某些文件在执行godep restore的时候下载失败,我把这些包手动放在了vendor下,然后提交到远程,执行go save的时候怎么忽略我手动放到vendor的包? ...阅读全文

即使是大神也没见过的glide的 大坑!!!!!

***大神,我在网上搜索过了,都没有遇到这种问题,于是乎想到了这里和你*** **** 问题描述: >这个是执行完 glide init 后的结果,ty是项目,不知道为什么glide.yaml中package 为 “.” ,我认为它应该为ty,并且glide.yaml中显示需要引入ty/controller 等等,我认为不应该出现本地的包的。所以我再执行glide install时就报错了,因为找不到这些本地文件。 望大神解救!~~~~~ 执行过程:glide init >![a.jpg](https://static.studygolang.com/180716/8b4549035700106f2372a3dc4278f4ad.jpg) 执行过程:glide install >![webw...阅读全文

博文 2018-07-16 17:28:58 xmge

golang map初始化的坑

Map nil import ( "fmt" ) //panic: assignment to entry in nil map type Param map[string]interface{} type Show struct { Param } func main() { s := new(Show) //s.Param["RMB"] = 10000 //panic: assignment to entry in nil map s.Param = map[string]interface{}{} s.Param = Param{} s.Param["RMB"] = 10000 fmt.Println(s) } package main import "fmt" type Param ...阅读全文

博文 2020-05-29 11:34:13 夜空一起砍猩猩