草庐IT

文章结构

全部标签

GoLang - 填充结构数组

我有以下2个结构typeAAAAstruct{Aa[2]byteAb[2]byteAc[3]byte}typeBBBBstruct{Ba[4]byteBb[2]byteBc[3]byteBd[2]byte//NoOfStructAAAItemsBBStr[]AAAA}所以StructBBB在StructAAA中重复然后我有一个字符串作为输入,其中包含作为输入的结构的值input:="aaaabbccc02ddeefffddeeffff"(这里02是StructAAAA在StructBBBB中重复的次数)我需要读取输入字符串并填充结构BBBB,包括结构AAA的数组我写了下面的函数来实现这

go - 在golang的If-else block 中为变量分配不同的结构

我想做这样的事情typeStruct1{str1string}typeStruct2{int1int}ifsomething{someVar:=Struct1{str1:''}}else{someVar:=Struct2{int1:1}}somefunc(someVar)我知道我不能在一个block内声明c然后在外部访问它。我试过这样的东西typeStruct1{str1string}typeStruct2{int1int}someVar:=Struct2{b:1}ifsomething{someVar:=Struct1{a:''}}somefunc(c)它给出了一个错误-Cannot

dictionary - 构造深层结构不起作用

我有一个负责从yaml文件中解析数据的结构虽然这个结构在工作,但有时我会得到一些我需要解析的新字段这是有效的-name:test1type:typepath:path这不是-name:test1type:typepath:pathbuild-parameters:maven-opts:defines:skipTests:true这是结构typeModulesstruct{NamestringTypestringPathstringParametersParameters`yaml:"build-parameters,omitempty"`}参数的类型是:typeParametersma

json - 如何动态添加结构属性以避免冗余代码?

关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭5年前。Improvethisquestion您好,我基本上是在努力避免代码中的冗余。这是我的结构:typePersonstruct{NamestringTextstringStatusstring}这是我的函数:funcReworkElementsFromClient(whttp.ResponseWriter,r*http.Request){varpersons[]Personerr:=json.NewDecoder(r.Body).Dec

go - 将数组解码为结构

我正在尝试弄清楚如何(使用gin)从api调用创建结构"icon":["https://api.figo.me/assets/images/accounts/postbank.png",{"48x48":"https://api.figo.me/assets/images/accounts/postbank_48.png","60x60":"https://api.figo.me/assets/images/accounts/postbank_60.png","72x72":"https://api.figo.me/assets/images/accounts/postbank_72.

go - 如何将动态 JSON 响应映射到 GO 结构?

这个问题在这里已经有了答案:UnmarshalJSONwithsomeknown,andsomeunknownfieldnames(8个答案)关闭4年前。我是golang的新手,正在尝试解析来自网络服务的一些响应,响应如下所示:[{"Data":{"KeyA":1,"KeyB":2},"Type":0},{"Data":{"KeyX":"ValueX","KeyY":999},"Type":1},{"Data":{"Val":123,"Id":"999","Cnt":100},"Type":2}]您可以看到每个元素都有一个键“数据”和“类型”(必须),但是不同的“类型”会带来不同的“数

json - 两个 Api 调用,具有不同的 JSON 响应。如何将它们输入到不同的结构中,但在 Golang 中重新排列它们几乎相同?

我的第一个API返回:{"symbol":"ARKBTC","bidPrice":"0.00037580","bidQty":"12.59000000","askPrice":"0.00037690","askQty":"328.94000000"}我正在使用的处理代码是typeTckrstrstruct{Symbolstring`json:"symbol"`data}typedatastruct{BidPricefloat64`json:"bidPrice,string,omitempty"`AskPricefloat64`json:"askPrice,string,omitempt

Golang 类型断言/转换为中间结构

给定以下类型:typeEventinterface{}typeActionResultEventstruct{Resultstring}typeActionSuccessEventActionResultEventtypeActionFailureEventActionResultEventtypeeventHandleFuncfunc(eEvent)我的目标是为具体类型ActionSuccessEvent、ActionFailureEvent以及更多抽象ActionResultEvent。我想将后者用于ActionSuccessEvent和ActionFailureEvent。现在我

golang 新建一个结构但返回一个接口(interface)

这里是golang代码,funcnewXXX返回一个接口(interface),为什么不返回一个structtype_ABitOfEverythingServerstruct{vmap[string]*examples.ABitOfEverythingmsync.Mutex}typeABitOfEverythingServerinterface{examples.ABitOfEverythingServiceServer//interfaceexamples.StreamServiceServer//interface}funcnewABitOfEverythingServer()AB

go - 将接口(interface)引入结构

我对golang有点陌生,正在尝试处理一些websocket数据。我以以下形式获取数据:typeEventstruct{Eventstring`json:"event"`Datainterface{}`json:"data"`}Data字段是我要处理并进入以下结构的json对象:typeOrderBookstruct{Pairstring`json:"pair"`Timestampstring`json:"timestamp"`Brokerstring`json:"broker"`Bids[]OrderBookItem`json:"bids"`Asks[]OrderBookItem`j