草庐IT

api接口

全部标签

go - 如何在go中找到实现接口(interface)的类型

我需要一个io.Writer作为函数。我不知道如何从文件中获取...我知道接口(interface)是隐式的,所以搜索起来很复杂...... 最佳答案 查看os.File文档:它有一个func(*File)Write方法,这意味着它是一个Writer。您可以使用命令guru列出实现接口(interface)的所有类型。值得注意的是,实现查询:Theimplementsqueryshowsinterfacesthatareimplementedbytheselectedtypeand,iftheselectedtypeisitself

go - 如何在函数中使用接口(interface),其中参数是另一个具有相同函数列表的接口(interface)?

我在函数参数中遇到接口(interface)问题。packagemainimport("fmt")typeAinterface{New()AB()C()}typeBinterface{New()BB()}typeASstruct{}func(AS)New()A{returnAS{}}func(AS)B(){}func(AS)C(){}funcHello(bB){b.New()}funcmain(){fmt.Println("Hello,playground")as:=AS{}a:=A(as)Hello(a)}我遇到了这个错误:tmp/sandbox293137995/main.go:3

go - 为什么 Go 认为这个结构不遵守这个接口(interface)?

假设我设置了两个Go接口(interface)并按如下方式实现它们:typefooInterfaceinterface{buildBar()barInterface}typebarInterfaceinterface{stuff()}typefooStructstruct{}typebarStructstruct{}func(*fooStruct)buildBar()*barStruct{return&barStruct{}}func(*barStruct)stuff(){}当我尝试将fooStruct分配给fooInterface变量时,我收到以下错误:cannotusefooStr

Golang 将映射分配给接口(interface)

我想将一个映射分配给一个接口(interface),其中基础值是map[string]interface类型。typeDatastruct{datainterface{}}result:=make(map[string]interface{})data:=Data{data:result}details:=make(map[string]interface{})details["CreatedFor"]="dfasfasdf"details["OwnedBy"]="fasfsad"如何将详细信息值插入Data结构中的data接口(interface)? 最佳

go - 使用接口(interface)获取结构的值

我正在尝试解析此请愿书(https://www.binance.com/api/v1/depth?symbol=MDABTC&limit=500)我在为它创建一个结构时遇到了很多问题,所以我使用了一个自动化工具,这就是我的结构的样子:typeorderBookstruct{Bids[][]interface{}`json:"Bids"`Asks[][]interface{}`json:"Asks"`}我通过执行以下操作来恢复和解析请愿书:url:="https://www.binance.com/api/v1/depth?symbol=MDABTC&limit=500"resp,err

api - Go 不会立即响应 GET 请求,它会在 ticker 完成后响应

我是Go编程的新手,我尝试为多人游戏构建API。如果我对http://localhost:8080/create_game/gameName发出GET请求.自动收报机完成后服务器对请求的响应。我需要立即从服务器获得响应,但是当自动收报机结束并且游戏超时并被删除时我得到了它。这是我的代码:varclients=make(map[*websocket.Conn]bool)varbroadcast=make(chanGame)//GAME_TIMEOUTinsecondsconstGAME_TIMEOUT=20//IDgeneratingvargenID=0vargames=[]Game{}

go - 为什么解码此 API 响应会返回意外的 EOF?

问题我正在使用ProtocolBuffer和gRPC在Go中创建一个微服务。它与第三方API(Snooth)交互,我正在尝试使用proto包将JSON响应解码为我创建的protobuf结构。解码返回一个意外的EOF错误。我尝试过的使用json.newDecoder而不是json.unmarshaljsonpb.Unmarshal而不是proto.Unmarshal(返回StructValue中键的错误值错误)使用io.LimitReader限制响应读取我还读过一些关于在原型(prototype)类型前加上尺寸标签之类的东西?但我不确定那是什么或者它是否相关。这是Github上的repo

GO API 安装失败 "evq/chromaticity"

我正在尝试在我自己的机器上安装色度进行测试,无论我做什么,我总是会遇到这张图片中看到的错误installationerror我不知道为什么会这样,我试着搜索,但我在网上什么也没找到。我的问题是有人知道为什么会这样吗?或者可以指出我正确的方向?我检查了文件夹,是的,里面没有GO文件,但我不明白为什么这是个问题API可以在这里找到:https://github.com/evq/chromaticity 最佳答案 这不是项目的问题(如错误),而是由于缺乏有关如何构建项目本身的文档而导致的问题。如果您查看根目录中的Makefile文件,您会

rest - 从 Go Code 使用 API 时出现 401 错误,而 cURL 运行良好

我编写了一个简单的go代码,向API发送GET请求,作为响应,我收到了401错误。但是,当我使用cURL时,我收到了所需的响应。我还使用APITester获得了预期的响应.所以,我相信,我的代码一定有问题,而且我无法找出来。下面是我的Go代码,它以401错误响应funcmain(){clusterId:=os.Getenv("CLUSTER_ID")apiUrl:="https://api.qubole.com/api/v1.3/clusters/"+clusterId+"/state"auth_token:=os.Getenv("X_AUTH_TOKEN")fmt.Println("

go - map 范围循环中的空接口(interface)

下面的代码没有按预期工作。packagemainimport"fmt"funcmain(){questions:=make(map[int]interface{})questions[1]=map[interface{}]string{"q1":"ThisisQuestion-1?","op1":"ThisisOption-1","op2":"ThisisOption-2",true:"ThisisOption-1",}//Thisgivemap[interface{}]stringfmt.Printf("%T\n",questions[1])//Thisnotworkingforke