草庐IT

ROOT_INPUT_INIT_FAILURE

全部标签

go - golang 的 init() 是如何工作的。我很迷惑

我在“config/config.go”中定义了一个init()函数配置.gopackageconfigimport(log"github.com/sirupsen/logrus")funcinit(){log.SetReportCaller(true)}我在auth包中有另一个名为auth.go的go文件packageauthimport(log"github.com/sirupsen/logrus")funcauth(usernamestring,pwdstring){//someauthcodelog.Info("Authsuccess")}当在auth.go中调用log.Inf

go - 从另一个函数调用 init 函数

为什么我不能从另一个函数调用init函数,init()是正确的函数,为什么我不能只调用init函数,我应该更改golangRFC以使其发生吗packagemainimport("fmt")funcinit(){fmt.Println("Hello,playground")}funcmain(){goinit()fmt.Println("Hello,playground")}错误:./prog.go:12:8:undefined:init 最佳答案 TheGoProgrammingLanguageSpecificationPackag

go - 如何对 init() 函数进行基准测试

我正在玩以下使用查找表计算人口数量的Go代码:packagepopulationimport("fmt")varpc[256]bytefuncinit(){fori:=rangepc{pc[i]=pc[i/2]+byte(i&1)}}funccountPopulation(){varxuint64=65535populationCount:=int(pc[byte(x>>(0*8))]+pc[byte(x>>(1*8))]+pc[byte(x>>(2*8))]+pc[byte(x>>(3*8))]+pc[byte(x>>(4*8))]+pc[byte(x>>(5*8))]+pc[byt

unit-testing - 错误 : suite. go:61: test paniced: reflect: Call with too few input arguments

我正在golang中设置单元测试。但是现在我在运行gotest-v时遇到错误。我想解决这个错误并使测试成功。article├client├api│├main.go│├contoroller││├contoroller.go││└contoroller_test.go│├service││├service.go││└service_test.go│├dao││├dao.go││└dao_test.go│├s3││├s3.go││└s3_test.go│├go.mod│├go.sum│└Dockerfile├nginx└docker-compose.yml现在我正在为service.go设

go - for init 语句只进入函数一次

我开始使用Go进行编程,我正在尝试创建一个程序来查询数据库并返回数据。我做到了这一点,但在此期间我遇到了一些问题。首先,我尝试创建一个带有条件的for来告诉程序何时我想停止查询,但是for的Init语句看起来只被评估一次-而且我再也不会被要求通过输入输入terminal-(我在这里读到是因为他的值是hold然后它不再执行函数:Golangswitchstatementonlycallsfunctiononce):已编辑funcmain(){varquerystringforquery=ReadQuery();query!="exit\n";{rows,err:=db.Query(que

go - 无法编译 Go 文件 - "initialization failure...xxxx redeclared in this block"

我是Go的新手,我按照website中的说明进行操作和youtubevideo当我运行gobuildhello.go时出现以下错误:go:disablingcache(/home/myuser/.cache/go-build)duetoinitializationfailure:open/home/myuser/.cache/go-build/log.txt:permissiondenied#runtime/usr/local/go/src/runtime/map.go:64:2:bucketCntBitsredeclaredinthisblockpreviousdeclaration

variables - Golang 的 init() 函数中的包范围变量赋值

我想在一些Go代码中初始化一个包范围的变量以连接到数据库,但我一直收到nil指针异常,很明显赋值没有正确发生。这会引发错误:packagemainimport("fmt""database/sql"_"github.com/lib/pq")varconnection*sql.DBfuncinit(){connectionString:="host=172.17.0.3dbname=postgresuser=postgrespassword=postgresport=5432sslmode=disable"connection,err:=sql.Open("postgres",conne

戈朗 : sha256 returns two different values for the same input

我正在努力实现一些需要哈希操作的加密函数(我想计算自定义结构的哈希)所以我想使用crypto中的SHA256哈希函数golang包。但是,我注意到,当我针对同一输入多次运行哈希函数时,有时它会返回不同的值。我的理解是SHA函数为单个输入值返回相同的哈希输出。下面是我对哈希函数的实现:funcmyHash(sMyStruct)[]byte{bytes:=[]byte(fmt.Sprintf("%v",s))h:=sha256.New()h.Write(bytes)returnh.Sum(nil)}myStruct有以下字段:typeMyStructstruct{elliptic.Curv

postgresql - pq : invalid input syntax for type double precision: "$1" with Golang

我正在尝试在我的GO程序中将一个简单的INSERT插入到postgresql数据库中。我的数字0是一个float64,我的数据库中有一列需要doubleprecision。我不知道我需要将数字转换成什么才能让数据库接受该值。 最佳答案 PostgreSQL驱动程序可以很好地处理将float64插入到double列中:tmp=#\dtestTable"public.test"Column|Type|Modifiers--------+------------------+-----------v|doubleprecision|和代码

使用ubuntu时忘记root密码,重置详细步骤:

目录1、ctrl+Alt+t打开命令行输入:init6重启Ubuntu2、重启开始时,按住shift键,进入以下界面,按e键3、向下移动光标,删除下图红框部分​编辑4、在当前位置输入下图内容5、按ctrl+x跳转,输入passwd,重置密码(密码不显示)6、重启客户机7、使用新密码登录即可1、ctrl+Alt+t打开命令行输入:init6重启Ubuntu2、重启开始时,按住shift键,进入以下界面,按e键3、向下移动光标,删除下图红框部分4、在当前位置输入下图内容5、按ctrl+x跳转,输入passwd,重置密码(密码不显示)6、重启客户机7、使用新密码登录即可