草庐IT

new_array

全部标签

arrays - GO 中的 : Parsing byte array of excel data using https://github. com/tealeg/xlsx 库

我想使用https://github.com/tealeg/xlsx解析excel数据的字节数组GOLANG中的库。实际上,我正在从请求(作为字节数组)获取数据到我的GRPC服务器,我必须在其中解析和处理它。我检查了库API,但它接受文件名作为参数。"github.com/tealeg/xlsx"funcmain(){xlsx.OpenFile("file.xslx")}知道如何直接传递字节数组并对其进行处理。 最佳答案 明白了。用过的funcOpenBinary(bs[]byte)(*文件,错误)

go - 使用 pg.Array 时如何将 reflect.Pointer() 转换为 []string?

我正在使用go-pg编写自定义查询缓存系统,该系统采用传递给查询函数的查询参数并生成用于Redis的哈希键。我正在使用Go的reflect来检查有效的参数类型,直到我使用pg.Array作为传递的参数。Reflect给了我reflect.Ptr,但是我如何在调用switchcaseblock时提取指针的结构/数组?funcGenerateQueryCacheKey(args...interface{})string{varargumentString=""for_,arg:=rangeargs{v:=reflect.ValueOf(arg)switchv.Kind(){caserefl

pointers - Golang 使用 New() 返回结构指针而不是直接创建一个

我正在读这个repounittest代码和Client结构是以我以前从未见过的方式创建的。typeClientstruct{//clientstuff}//Inclient_test.go//Creatingdefaultclientfortestingc:=dc()//Inresty_test.gofuncdc()*Client{DefaultClient=New()DefaultClient.SetLogger(ioutil.Discard)returnDefaultClient}我的问题是返回New()的目的是什么?下面的代码是否与New()风格类似?为什么要二选一?funcdc

arrays - 来自 Yaml 的数组 - Golang

我尝试为我的go应用程序创建配置文件,循环执行一些作业。我的.yaml文件看起来像这样(数组):jobToRun:-name:ThisismyfirstjobtorunsqlToRun:select1fromsome_tablesomeVariable:1-name:OtherjobtorunsqlToRun:select2fromsome_tablesomeVariable:2我已成功导入YAML文件并创建了结构。typeServicestruct{JobToRun[]struct{Namestring`yaml:"name"`SQLToRunstring`yaml:"SqlToRu

arrays - 迭代时更改值

假设我有这些类型:typeAttributestruct{Key,Valstring}typeNodestruct{Attr[]Attribute}并且我想迭代节点的属性以更改它们。我希望能够做到:for_,attr:=rangen.Attr{ifattr.Key=="href"{attr.Val="something"}}但是因为attr不是一个指针,所以这是行不通的,我必须这样做:fori,attr:=rangen.Attr{ifattr.Key=="href"{n.Attr[i].Val="something"}}有没有更简单或更快的方法?是否可以直接从range获取指针?显然,

arrays - 迭代时更改值

假设我有这些类型:typeAttributestruct{Key,Valstring}typeNodestruct{Attr[]Attribute}并且我想迭代节点的属性以更改它们。我希望能够做到:for_,attr:=rangen.Attr{ifattr.Key=="href"{attr.Val="something"}}但是因为attr不是一个指针,所以这是行不通的,我必须这样做:fori,attr:=rangen.Attr{ifattr.Key=="href"{n.Attr[i].Val="something"}}有没有更简单或更快的方法?是否可以直接从range获取指针?显然,

arrays - 从 slice 中删除特定元素

我有这个密码:typeTimeSlotstruct{IDint64`json:"id"sql:"auto_increment"`}typeReservestruct{IDint64`json:"id"sql:"auto_increment"`TimeSlotTimeSlot`gorm:"foreignkey:time_slot_id;association_autoupdate:false"json:"-"`TimeSlotIDint64`json:"time_slot_id"`}funcGetFreeTimeSlotList(whttp.ResponseWriter,r*http.R

arrays - 如何在 golang 中编写具有嵌套递归数据的结构

我有如下数据{"cars":{"toyota":["sedan","pickup"],"honda":["sedan","couple","pickup"]....}}该列表可能会继续增长。我正在尝试找出一个合适的结构来为数据提供服务并返回到一个http响应编写器。我拥有的结构。typeAutosstruct{Carsstruct{Toyota[]string`json:"toyota"`Honda[]string`json:"honda"`}`json:"cars"`}但是上面的结构已经预定义了“Toyota”“Honda”我正在寻找一种只使用一个或两个结构来表示数据结构的方法。提前

multilingual - 如何使用 "hugo new"命令

我在多语言环境中使用Hugo(v0.58.1)。我的帖子存储在不同的文件夹中。例如:content/zh/...content/fr/…我不知道如何使用hugonew--kindpost命令按语言/文件夹创建.md文件(例如hugonew--kindpostfr/2019/09/…)?也许-c,--contentDir字符串或-d,--destination字符串标志?但我不明白如何使用它们。hugonew-kpost-c/Users/ns/projects/hugo/tests/hugo-template/content/fr/post/2019/09/07/test.md

arrays - [] byte {10}或[] byte(“\n”)与[] byte {92,110}

我正在使用github.com/tarm/serial来连接一些串行仪器。在开发过程中,我使用/dev/ttyp0和/dev/ptyp0对,其中go进程连接到一个,我使用screen连接到另一个。我编写了一个函数,它与serial.Config.ReadTimeout结合起来,最多可以读取ReadTimeout或接收到给定的字节序列。该功能是:funcreadToTermination(sserial.Port,termination[]byte,ratetime.Duration)[]byte{varout[]bytelterm:=len(termination)for{buf:=m