草庐IT

is_io_type

全部标签

go - 编写 CLI : How to avoid showing the typed password on screen

这个问题在这里已经有了答案:getpasswdfunctionalityinGo?(11个答案)关闭7年前。我正在使用Go编写命令行工具,其中一个命令将查询用户的用户名和密码(并将其保存到主目录内的配置文件中)。目前我还不知道如何将键入的密码替换为“*”,甚至无法像许多命令行工具那样不键入任何内容。在使用golang时如何做到这一点?

go - 关于 "cannot use time.Now() (type time.Time) as type "

使用以下类型定义获取“不能使用time.Now()(类型time.Time)作为字段值中的类型typetime”import("time")typetypetimetime.TimetypeFriendsstruct{NamestringBirthdaytypetime}John:=Friends{Name:"John",Birthday:time.Now()}如果我用直接类型形式(time.Time)替换typetime,就没有问题。GO的规则背后是什么??:> 最佳答案 time.Time和typetime是不同的类型(尽管它们

ios - 如何使用 NSData 在我的 Golang 服务器上读取我从 iOS 发布的 JSON?

我正在尝试通过将收据从iOS发送到我的自定义服务器来验证收据。我有我的NSMutableURLRequest并将其设置为:letbody:[String:AnyObject]=["receipt":receipt,"prod_id":productID]letoptionalJson:NSData?do{optionalJson=tryNSJSONSerialization.dataWithJSONObject(body,options:[])}catch_{optionalJson=nil}guardletjson=optionalJsonelse{return}request.HT

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

json - Golang : Protobuff generated Struct is not decoding child attribute for json. 解码

我有一个结构体正在与protobuff序列化器一起使用并且运行良好。这个结构是由protobuff生成的,因此它有很多方法,比如Unmarshal等。typeFlightstruct{FlightNostring`json:"flightno,omitempty"`Carrierstring`json:"carrier,omitempty"`}func(m*Flight)Unmarshal(data[]byte)error{l:=len(data)iNdEx:=0foriNdEx=64{returnErrIntOverflowFlight}ifiNdEx>=l{returnio.Err

戈朗 : 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

go - 通过 go-socked.io 接收字节数组时出错

我正在尝试从浏览器发送一个Int8Array到go-socked.io,这是我客户的代码:functioninit(){conn=io('http://localhost:8080/');varc=newInt8Array([127]);conn.emit('m',c)}这是我的服务器代码funcmain(){server,err:=socketio.NewServer(nil)iferr!=nil{log.Fatal(err)}server.On("connection",on_connection)http.Handle("/socket.io/",server)http.Hand

json - 去 json 休息 : JSON payload is empty

我正在尝试使用go-json-rest创建RESTfulAPI我有这个模型结构:typeTodostruct{idintnamestring}我正在尝试执行POST请求以创建Todo类型的对象:funcCreateTodo(wrest.ResponseWriter,r*rest.Request){body,_:=ioutil.ReadAll(r.Body)log.Println("bodycontentis:",string(body))//hereIcansee{"name":"test1"}vartodoTodo=Todo{}err:=r.DecodeJsonPayload(&to

go - 为什么 golang duck typing 在我下面的代码中对我不起作用?

在下面的代码中,我尝试创建模型接口(interface)和API接口(interface)的具体实现:packagemainimport"fmt"/////////typeModelinterface{ID()string}typeAPIinterface{Create(Model)}/////////typeConcreteModelstruct{}func(modelConcreteModel)ID()string{return"123"}func(modelConcreteModel)Name()string{return"aron"}typeConcreteAPIstruct{

go - 为 io.Reader 添加前缀

我编写了一个小型服务器,它以io.Reader的形式接收一团数据,添加一个header并将结果流式传输回调用者。我的实现不是特别有效,因为我在内存中缓冲blob的数据,以便我可以计算blob的长度,这需要构成header的一部分。我看过一些io.Pipe()和io.TeeReader的例子,但它们更适合拆分io.Reader分成两部分,并将它们并行写入。我正在处理的blob大约是100KB,所以不是很大,但是如果我的服务器变得繁忙,内存很快就会成为一个问题...有什么想法吗?funcaddHeader(inio.Reader)(outio.Reader,errerror){buf:=n