草庐IT

TO_STRING

全部标签

string - 从 Go 中的 slice 中删除字符串

这个问题在这里已经有了答案:Deleteelementinaslice(7个答案)关闭7年前。我有一段字符串,我想删除一个特定的字符串。strings:=[]stringstrings=append(strings,"one")strings=append(strings,"two")strings=append(strings,"three")现在如何从strings中删除字符串"two"?

json - Golang map : How to strip out empty fields automatically

给定以下结构...packagemodelsimport("time""gopkg.in/mgo.v2/bson""github.com/fatih/structs")typeUserstruct{Idbson.ObjectId`json:"id,omitempty"bson:"_id,omitempty"`Namestring`json:"name,omitempty"bson:"name,omitempty"`BirthDatetime.Time`json:"birth_date,omitempty"bson:"birth_date,omitempty"`}...我通过像这样解析H

戈朗 : Zip Package Modified Time Defaults to 30 November 1979, 00:00

如何将zip文件的修改时间更改为time.Now()?当我创建一个zip文件时,我得到的修改时间是1979年11月30日00:00。那么有没有简单的方法可以将修改时间设置为现在呢? 最佳答案 我发现这个函数可以满足我的需求:funcFileInfoHeader(fios.FileInfo)(*FileHeader,error)。这将获取一个输入数据文件并创建一个部分填充的FileHeader。 关于戈朗:ZipPackageModifiedTimeDefaultsto30November

arrays - 如何在 Go 中创建一个 map[string] [2]int?

这个问题在这里已经有了答案:Cannotassigntopairinamap(3个答案)关闭6年前。我想在Go中创建一个map[string][2]int。我试过this在Playground,但我遇到了错误。我该如何解决这个问题?fmt.Println("Hello,playground")m:=make(map[string][2]int)m["hi"]={2,3}m["heello"][1]=1m["hi"][0]=m["hi"][0]+1m["h"][1]=m["h"][1]+1fmt.Println(m)

Golang 中的正则表达式 : How to set character that makes the string not match?

我对正则表达式一窍不通(抱歉)。我试图制作一种非常简单的标记语言,匹配粗体和斜体,然后将它们转换为HTML。这是我使用的粗体示例:varbold=regexp.MustCompile("\\*([^\\*]+)\\*")它匹配两个星号之间的所有内容。现在,我希望它匹配*test*但不匹配\*test*。由于我对正则表达式知之甚少,但我正在尝试进行此实验,因此我想知道这样做的方法是什么。我到处搜索,但找不到完成这项工作的方法。 最佳答案 已更新Go不支持回顾。因此,解决方法可以是:(?:\A|(?:[^\\]+|\A)(\\{2})+

json - 接口(interface)转换: interface is map[string]interface {} not

我对Go中的所有不同类型感到非常困惑,但我有一个严格定义的结构“VMR”,我正在尝试将数据转换为它。我正在查询CouchDB(使用GoSDK),然后尝试将返回的数据断言到我的结构中。当然,这是行不通的,它引发了panic。我在黑暗中拍摄,试图找出我做错了什么。这是我的函数/结构:typeVMRstruct{Namestring`json:"name,omitempty"`InUsebool`json:"inuse"`Descriptionstring`json:"description,omitempty"`Viewstring`json:"view,omitempty"`Themes

arrays - 如何在 Golang 中将字符串转换为 map[int]string

我在将字符串转换为map时遇到了问题。我有来自url的下一个数据map[start:0draw:1length:10_:1475090278299search[value]:search[regex]:falseorder[0][dir]:ascorder[0][column]:0columns[0][orderable]:truecolumns[0][searchable]:truecolumns[0][search][value]:columns[0][search][regex]:falsecolumns[0][data]:namecolumns[0][name]:columns

performance - 戈朗 : right way to store map structure in lru cache

我有一个像这样的结构:map[key]value,我想通过一个字符串将它存储在"github.com/golang/groupcache/lru"中键,例如cacheKey。这是我的问题:我发现每当我想更新缓存项时,我都需要先获取:item:=cache.Get(cacheKey)ifv,ok:=item[key];ok{item[key]=new_valuecache.Add(cacheKey,item)}这样做是否正确?或者,正如一些人所建议的,我需要重新设计我的结构,以确保我可以在任何时候更新它时执行cache.Add(cacheKey,item)。或者,我什至应该使用像cach

戈朗 : building interfaces for existing types to make code testable

为了使调用sql包的代码可测试,我构建了以下2个接口(interface):typeDatabaseinterface{Close()errorQuery(string,...interface{})(DatabaseRows,error)}typeDatabaseRowsinterface{Close()errorNext()boolScan(...interface{})error}我要测试的实际代码是:funcgetDatabase(connectionStringstring)(dbDatabase,errerror){ifdb,err=sql.Open("mysql",con

objective-c - 从 Safari 显示 : Do you want to allow this page to open "(null)"? 启动的应用程序

我正在使用Go/Objective-C编写MacOS应用程序。可以这么说,我没有使用Xcode,而是手动组装了应用程序包。这是它的文件系统层次结构${APPNAME}.appContentsMacOS${APPNAME}(binary)ResourcesBase.lprojInfoPlist.strings(text)Info.plist(text)bundle启动正常。应用程序按预期工作。我的Plist文件中有一个CFBundleURLTypes字典,它为我的应用程序定义了一个URL方案。CFBundleURLTypesCFBundleURLName${APPNAME}CFBundl