草庐IT

文章结构

全部标签

struct - 在将它作为接口(interface)传递并运行它的方法后,让你将结构恢复为它的数据类型?

我有一个结构如下typeMyStruct{EmbeddedFooBar}func(m*MyStruct)Foo(b*http.Request){//Doingsomething}funcfn(args...interfaces){//It'shereIwanttogetmystructbackandrunthe"Get"method//PleasekeepinmindIamtoopassapointerparamintothestructmethodstrt:=args[0]....getstructbacktostaticdatatypeMyStructandrun"Get()",d

结构没有被完全编码

我有一个需要编码以使用web服务的结构,但在我的测试中,我的Marshal函数只编码一个字段:typeDataRows[]struct{mDatainterface{}}typeDataColumns[]struct{mColumnNamestringmColumnTypeintmColumnPrecisionintmColumnScaleint}typeDataTables[]struct{mDataColumnsDataColumnsmDataRowsDataRowsmIndexint}typeCFFDataSetstruct{mDataTablesDataTablesmUsers

json - 无法处理 golang 结构中的 json 字符串数据

我有一个字符串形式的json数据(来自第三方API)。我无法在golang中解码json字符串数据。请帮忙。JSON字符串={"data":{"additional-30":{"id_sales_rule_set":255626,"voucher_code":"PR35ZR5J5","from_date":"2015-06-1616:19:22","to_date":"2018-09-2823:59:59","conditions_ruleset":{"subTotal":0,"category":{},"customer":"0","paymentMethod":null,"capO

arrays - 提高在结构 slice 中搜索值的性能

我如何优化下面的代码以搜索map数组中的特定键值(然后返回其他键值)?typeuserMapstruct{JiraUsernamestringCHProjectIDintCHIDstring}funcmain(){varuserMaps[]userMapuserMaps=append(userMaps,userMap{JiraUsername:"ted",CHProjectID:81,CHID:"23jk3f32jl3323",})fmt.Println(GetUserInfo(userMaps,"ted"))}funcGetUserInfo(userMaps[]userMap,jir

go - 无法控制父初始化时初始化嵌入式结构

我有这样的结构:typeParentstruct{*WithContext}typeWithContextstruct{Ctxcontext.Context}func(wi*WithContext)SetContext(ctxcontext.Context){//nilpointerwi.Ctx=ctx}Parent由一些自动化过程初始化(作为解码流程的一部分),所以我无法初始化嵌入的WithContext结构,有什么方法可以避免“SetContext”函数中的nil指针吗?我尝试覆盖指针接收器,但它没有任何效果,谢谢,阿萨夫。 最佳答案

go - 如何在没有嵌套循环的情况下将嵌套结构塑造成另一个结构?

如何将A和B的选定值注入(inject)下面的子C?decoder.go(Playgroundlink)packagemainimport("fmt")typeInputstruct{A[]A}typeAstruct{AIDintB[]B}typeBstruct{BIDintC[]C}typeCstruct{//IwanttoinjectonlyAIDandBIDhere//But,withoutinjectingAandBdirectly//(withoutrecursively)CIDint}funcmain(){res:=Input{A:[]A{A{AID:1,B:[]B{B{B

go - 序列化为JSON动态结构

所有使用JSON的示例都描述了如何序列化为JSON简单类型或用户类型(如结构)。但我有不同的情况:a)我不知道我的类型/对象的字段b)每个对象都有不同的类型。这是我的案例的伪代码:while`select*fromitem`dowhile`selectfieldname,fieldvaluefromfieldswherefields.itemid=item.id`do...对于我数据库中的每个实体,我都获得了字段名称和字段值。结果我需要得到这样的东西:{"item.field1":value,..."item.fieldN":value,"custom_fields":{"fields

go - 为从其他包声明的结构分配一个值

这是我的代码。我将我的结构OperatInfo提取到struct.go并想在worker.go的主包中使用这个结构。结构.gopackagebatchtypeOperatInfostruct{eventIdstringhallIdstringuserIdstringoperatingstringoperatingIDstringipstring}worker.gopackagemainimport("time""fmt""strconv""./kernel/api""./kernel/db""./batch/basic""./batch/struct")varoperatInfobat

go - 使用 initilzer 函数创建的结构不会导出到测试包中吗?

假设我们有一个struct和一个类似这样的结构的构造函数packagemyPackagetypeClientstruct{aTypeAbTypeB}funcNewClient(aTypeA,bTypeB)ConcreteClient{return&Client{a:a,b:b,}}typeConcreteClientinterface{ExportedFunc()}func(c*Client)privateFunc(){//...}func(c*Client)ExportedFunc(){//...}我们在这样的测试包中使用这个客户端var(c=&Client{a:a,b:b,})fu

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

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