草庐IT

unused-functions

全部标签

php - 高语 : create a function that accept an interface (I came from PHP)

在PHP中我可以创建一个接口(interface)interfaceHello{publicfunctionbar();}以及一些实现它的类finalclassFooimplementsHello{publicfunctionbar(){//dosomething}}finalclassBarimplementsHello{publicfunctionbar(){//dosomething}}然后,我还可以创建一个接受该接口(interface)的NewClass::bar()方法。finalclassNewClass{publicfunctionbar(Hello$hello){//

function - 结构中缺少函数体和字符串标记

这个问题在这里已经有了答案:Functionsignaturewithnofunctionbody(1个回答)关闭4年前。我在Go中发现了一些没有函数体的函数。我知道这意味着Go中的外部函数。但是我在哪里可以找到函数boby呢?typeCreatorfunc(*Beat,*common.Config)(Beater,error)我还在Gostruct中找到了一个字符串。什么意思?typeBeatConfigstruct{//output/publishingrelatedconfigurationsOutputcommon.ConfigNamespace`config:"output"

function - 如何转换函数类型?

关闭。这个问题是notreproducibleorwascausedbytypos.它目前不接受答案。这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这个问题的解决方式不太可能帮助future的读者。关闭4年前。Improvethisquestion我想在expend中使用upCase作为变量,但它说“不能将‘upCase(s1)’(typestring)用作typefunc(string)string。我怎样才能转换upCase类型?或者我需要做什么才能使错误消失?packagemainimport("fmt""strings")funcma

function - 添加到 []interface{} 的对象。现在需要获取对象并调用对象各自的 Display() fn

我做了以下事情:用Display()fn定义了一个“父”接口(interface)。创建了2个实现各自Display()fn的子结构。在main()中,创建了2个子对象并将它们添加到:availableObjs[]interface{}现在,在For循环中,想要获取对象并调用其各自的Display()函数。这就是令我震惊的地方。GoPlayground代码:https://play.golang.org/p/jdHpueokrEk尝试在线搜索。内联相同代码:packagemainimport("fmt""reflect")//////ParentInterfacewhichhasDis

function - 在go函数中将函数作为参数传递

我想在go函数中将函数作为参数传递。这是我的代码:funcCall(pathstring,methodfunc()){//TODOlaunchthemethodhere}当我想调用这个函数时,我想这样做:funcroutes(){app.Call("/",controllers.Index())}Index()方法是:funcIndex(reshttp.ResponseWriter,reqhttp.Request){userAgent:=req.Header.Get("User-Agent")fmt.Fprintf(res,"You'reUser-Agentis%s",userAgen

function - 传递值时与通过引用传递时 map 的奇怪突变(Golang)

在第一种情况中,我按值将map传递给:包主import("fmt""time")functimeMap(zmap[string]interface{}){z["updated_at"]=time.Now()}funcmain(){foo:=map[string]interface{}{"Matt":42,}timeMap(foo)fmt.Println(foo)}输出是一个静音贴图:map[updated_at:2009-11-1023:00:00+0000UTCMatt:42]在第二种情况中,代码几乎相同,但通过引用传递:packagemainimport("fmt""time")f

function - 如何将 time.Duration 类型传递给 go 函数?

我正在学习GOLANG,尤其是它的并发能力。已尝试进一步开发worker_pool示例之一,以便每个工作人员都收到一个作业ID和一个作业负载,以作业的随机持续时间表示。time.sleep命令使用持续时间来等待分配的纳秒数,这是随机计算的。代码看起来像这样......//worker_poolimprovedexamplepackagemainimport"fmt"import"time"import"math/rand"//Here'stheworker,ofwhichwe'llrunseveral//concurrentinstances.Theseworkerswillrecei

function - Golang 中没有返回值函数

当我在看《thelittlego》这本书时,我发现它建议写一个没有任何返回值的函数。所以我继续测试该功能,但程序无法编译并给我这个“...用作值”错误。有人知道这里发生了什么吗?packagemainimport("fmt")funclog(messagestring){fmt.Println(message)}funcmain(){msg:=log("justamessage")fmt.Println(msg)}我知道这个函数很简单(也许这个问题也很愚蠢)。但我只是想知道这种函数在Go中是否合法? 最佳答案 这里的功能你用过fun

function - 如何在golang中仅显示多值结果的一个输出

最近在研究Golang一个函数可以返回多个结果。所以我写了一个函数:funcstore(x,yint)(int,int){returnx+y,x-y}在这之后我写了下面的代码:funcmain(){a,b:=store(6,4)fmt.Println(a,b)}结果是:102这工作正常。但是如果我想只打印一个,那我该怎么做呢?funcmain(){a,b:=store(6,4)fmt.Println(a)}结果:tmp/sandbox683412938/main.go:12:19:bdeclaredandnotused还有,为什么我不会写:funcmain(){a:=store(6,4

function - 计算函数被调用了多少次

关闭。这个问题需要debuggingdetails.它目前不接受答案。编辑问题以包含desiredbehavior,aspecificproblemorerror,andtheshortestcodenecessarytoreproducetheproblem.这将有助于其他人回答问题。关闭5年前。Improvethisquestion如何在go中优雅地完成它?在python中我可以使用这样的属性:deffunction():function.counter+=1function.counter=0go是否有同样的机会?