jjzjj

run_func

全部标签

去新手 : how to run goroutines shell?

我尝试运行shell-basic但没有任何反应。这是我尝试过的:Torunthisexample,downloadandinstallitwithgoget:gogetgoroutines.com/shell-basic静默完成,我看到它下载了shell基本脚本,但是当我执行shell-basic时,我得到:$shell-basic-bash:shell-basic:commandnotfound我做错了什么,还是我遗漏了什么?我感兴趣的是将go作为scripts运行.. 最佳答案 goget将获取源并将其放入您的Go路径,在she

go - 在内存地址调用 func

我有一个映射,其中一个结构作为键,一个函数作为值,我想在检索给定键的值时调用函数map[struct]funcmap[{contact%!s(int=1)}:%!s(main.Controller=0x4c7b50){services/basket%!s(int=2)}:%!s(main.Controller=0x4c7ad0){categories%!s(int=1)}:%!s(main.Controller=0x4c7ae0){categories/{category}%!s(int=2)}:%!s(main.Controller=0x4c7af0){categories/{cat

go - 不能使用函数(类型 func())作为参数类型

packagemainimport("log""strings""asl.com/asl")/*TrivialservicetodemonstratechainingservicetogetherMessagestartsinoriginator,travelsthroughacoupleformatters,andthengetsbacktooriginator*/typeMessageTeststruct{Bodystring`json:"body"`}vars*asl.Servicefuncmain(){var(errerrorcidstring)//varmMessageDel

go - 不能在 func 参数中使用 bytes.Buffer 作为 io.WriterAt 类型

今天在go上苦苦挣扎..我不得不问的第二个问题。我有2个测试写入函数Write(),它采用writerio.WriterAt和contentinterface{}.我正在处理为函数编写的(2)个测试,TestWriteSuccessful和TestWriteFail。我在测试这两个函数时得到的错误是:cannotuse&b(type*bytes.Buffer)astypeio.WriterAtinargumenttoWrite:问题什么实现了我可以在这些测试中替换bytes.Buffer以使测试正常运行的WriterAt?我尝试过的将b的类型更改为os.File-b.len()>0将失

戈兰错误: `cannot find package` when running go get

我正在尝试解决Orielly一书中的DecentralizedApplications中提供的示例。go-ipfs包似乎已经过时,新版本不能正常工作。所以我手动应对旧版本并尝试编译go-kerala。尽管某些文件夹存在于路径中,但我收到错误消息。例如,/home/rajkumar/go/src/github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58(来自$GOPATH)在我手动复制旧版本文件后出现,但go-get命令仍然出错。$goget-dgithub.com/llSourcell/keral

algorithm - 不能在 time.AfterFunc 的参数中使用(属于)类型 func() 的函数

如果不遇到几个嵌套函数问题,我不知道如何解决这个Go算法问题。其中之一是,“不能在返回参数中使用func文字(类型func())作为类型func()字符串”。我现在使用的解决方案是://Writeafunctionthattakesin2numbers(a,b)andafunction.//Itshouldexecutethefunctionafteramilliseconds,//andthenexecutethefunctionagainafterbmilliseconds.packagemainimport"time"funcnewFunc(bint,fnfunc()string

go - "go run file.go"命令后可执行文件存储在哪里?

go编译器执行完如下命令后的可执行文件存放在哪里?$>gorunfile.go 最佳答案 在/tmp文件夹中,如果您使用的是unix机器。如果您使用的是Windows,则在\Users\SomeUser\AppData\Local\Temp\中。 关于go-"gorunfile.go"命令后可执行文件存储在哪里?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/46570517/

go - 为什么我不能在 go 中将 `func() []int` 作为 `func() []interface{}` 传递?

我有以下定义:func(c*Collector)RegisterSource(ffunc()[]interface{}){c.source=f}我尝试按如下方式调用它但出现错误:funcsource()[]int{return[]int{0,1,2,3,4}}...c.RegisterSource(source)这会遇到:cannotusesource(typefunc()[]int)astypefunc()[]interface{}inargumenttoc.RegisterSource 最佳答案 relevantGoFAQent

戈朗 : How to run the same logic at the beginning of every struct member functions?

例如,我想打印出某个结构的每个函数的函数名。除了我在每个成员函数的开头使用fmt.Println,还有什么更好的方法吗? 最佳答案 packagemainimport"fmt"import"runtime"funcmain(){pc,_,_,_:=runtime.Caller(0)fmt.Println("Nameoffunction:"+runtime.FuncForPC(pc).Name())fmt.Println()//or,defineafunctionforitfmt.Println("Nameoffunction:"+f

go - golang执行 'docker run..'异常退出

不确定为什么会这样,当我运行时dockerbuild–tmy-app.dockerrun-p8000:8000-dmy-app它立即退出dockerps-a输出:CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMESb7ede6791bafmy-app"./app"8secondsagoExited(0)7secondsagoadoring_einstein我的Dockerfile:FROMgolang:1.8RUNmkdir-p/appWORKDIR/appADD./appRUNgobuild./app.goCMD["./app"]我在Mac上。