草庐IT

available_AL_buffer_array_curr_in

全部标签

arrays - 函数应返回 sha256/sha384/sha512 结果作为 byte slice

我正在编写一个函数,它将输入数据作为字符串和要调用的SHA算法的位大小。它应该将生成的散列作为byteslice返回(第一次尝试):packagemainimport("crypto/sha256""crypto/sha512""errors""fmt")funcmain(){input:="Thisisatest."sha256,_:=shaSum(input,256)sha384,_:=shaSum(input,384)sha512,_:=shaSum(input,512)fmt.Println(input,sha256,sha384,sha512)}funcshaSum(data

arrays - []json.Rawmessage 是什么意思

[]json.Rawmessage是什么意思。它在这个结构中:typeRequeststruct{Jsonrpcstring`json:"jsonrpc"`Methodstring`json:"method"`Params[]json.RawMessage`json:"params"`IDinterface{}`json:"id"`}我知道它是一个json类型的片段。我不明白.RawMessage指的是什么。我试着在golangtour和我的golangbook中查找它。最终我知道Params是类型[]json.Rawmessage被捆绑到另一种类型称为Request此外:这些段jso

arrays - 使用结构变量数组访问结构变量golang

funcGetprofilesApi(c*gin.Context){varpProfileprofiles,err,count:=p.GetProfiles()iferr!=nil{log.Fatalln(err)}c.JSON(http.StatusOK,gin.H{"NumberofResults":count,"profiles":profiles,})}//Getprofiles()functionfunc(p*Profile)GetProfiles()(profiles[]Profile,errerror,countint){profiles=make([]Profile,0

pointers - 为什么在将它传递给另一个函数时需要指向 Go bytes.Buffer 的指针?

在下面的代码中,write_commas要求缓冲区参数是一个指针。它有效。替代方案(即不使用指针)会导致空白输出。为什么传递实际的bytes.Buffer无法打印任何内容?或者换句话说,传递实际的bytes.Buffer是否会创建一个副本,从而将字节写入一个没有任何内容正在读取的缓冲区?packagemainimport("fmt""bytes")funcmain(){s:="1234567898"fmt.Println(Comma(s))}funcComma(sstring)string{varbufbytes.Buffer//0{whole_part:=sbytes[:decima

go - 如何将 []byte 转换为 *bytes.Buffer

我正在尝试解码通过另一个fasthttp端点发送的gob输出并收到错误Fasthttpendpoint(encode[]stringthroughgob)---->Fasthttpendpoint(接收和解码)buffer:=&bytes.Buffer{}buffer=ctx.PostBody()backToStringSlice:=[]string{}gob.NewDecoder(buffer).Decode(&backToStringSlice)我收到错误:ctx.PostBody()(type[]byte)astype*bytes.Bufferinassignment如何将[]b

arrays - 使用 Go 递归在数组中累积/追加值时出现问题

首先,这是我第一个使用Go的非虚拟程序。任何建议将不胜感激。代码说明:我想从对信息进行分页的API中检索所有信息。所以我想遍历所有页面以获取所有信息。这是我目前所做的:我有这两个功能:funcrequest(requestData*RequestData)[]*ProjectsResponse{client:=&http.Client{Timeout:time.Second*10,}projects:=[]*ProjectsResponse{}innerRequest(client,requestData.URL,projects)returnprojects}funcinnerReq

arrays - 动态数组json解析

我正在尝试解析json以进行langstruck,但一些对象如何返回空:Json对象:`{"names":[{"David":{"id":"100","country":"usa","group":["A1","A2"]}},{"John":{"id":"1","country":"uk","group":["A1","A2"]}}]}`GoLang结构:typeDatastruct{Names[]Names`json:"names"`}typeNamesstruct{IDstring`json:"id"`Countrystring`json:"country"`Group[]stri

go - "Missing type in composite literal"结构中映射的匿名列表

编辑:编译错误在Missingtypeincompositeliteral与我的问题相同,它们的组成差异很大,以至于我不明白我将如何将解决方案应用到我的程序中,因此创建了这个问题。我是新来的,我正在尝试为我已验证可以成功调用的函数编写测试,如下所示:funcmain(){items:=[]map[string]int{map[string]int{"value":100,"weight":5,},map[string]int{"value":90,"weight":2,},map[string]int{"value":80,"weight":2,},}fmt.Println(KnapS

go - 不能在 db.Query 的参数中使用缓冲区(类型 bytes.Buffer)作为类型字符串

我在buffer.WriteString()中编写了一个SQL查询,但无法在db.Query()中使用该缓冲区。buffer.WriteString(fmt.Sprintf(`SELECTc.id,c.company_name,ss.start_date,ss.shift_length,ss.bill_rate,ss.ot_hrs,ss.dt_hrs,ts.pay_rate,ts.wc_rate,ts.paid,td.wcFROMcompanycJOINusersu1ONc.id=u1.company_idJOINschedulesONu1.id=s.user_idJOINschedu

postgresql - 如何将 pgtype.Int4Array(来自 pgx 库)转换为 []int64 Golang 类型?

我使用Go和Postgres(使用pgxdriver)在我的Postgres表中,我有一个包含整数数组的字段。我创建了一个变量来存储扫描后的整数数组。varidspgtype.Int4Array如何将ids转换为[]int64? 最佳答案 使用ids.AssignTo(&sliceOfInt64) 关于postgresql-如何将pgtype.Int4Array(来自pgx库)转换为[]int64Golang类型?,我们在StackOverflow上找到一个类似的问题: