草庐IT

hello-writer

全部标签

go - 当我的 io.Writer 故意不写入它传递的所有字节时,它应该返回什么 "number of bytes written"

我想创建一个实现io.Writer的结构,即Write(p[]byte)(nint,errerror)。该结构将省略传递给它的某些字节,因此实际上不会写入p参数中传递的所有字节。(实际目的并不重要,但它可以是例如忽略写入的前10个字节,忽略第二个字节或其他改变从调用者传递给方法的字节数写入的字节数的东西)。Thedocumentationio.Writer的Write方法说明如下(强调我的):Writewriteslen(p)bytesfromptotheunderlyingdatastream.Itreturnsthenumberofbyteswrittenfromp(0Writem

go - 堆叠写入器和 zlib.writer 的校验和错误

我有两个对象写入器,第一个封装了io.Writer并在写入时同时计算内容的SHA1校验和,第二个首先封装并写入zlib压缩数据。我的带有一些测试数据的单元测试用例通过了第一个编写器,但第二个编写器失败了。我在哪里做错了什么?代码片段:import("compress/zlib""crypto/sha1""hash""io")typeObjectWriterinterface{io.WriterCommit()([]byte,error)}typeoWriterstruct{writerio.Writersumhash.Hash}func(ow*oWriter)Write(b[]byte

带有 LiteIDE 的 GOLANG : I can't see "Hello World!" in Build Output window

我已经按照本教程在Windows864位上安装了golanghttp://www.i-programmer.info/programming/other-languages/6600-a-programmers-guide-to-go-with-liteide-part-1.html因此,我创建了一个名为“hello”的“Go1命令项目”,当“构建输出”窗口中的“构建+运行”(Ctrl+R)看不到“HelloWorld!”这是我在输出中得到的:Currentenvironmentchangeid"win64-user"C:/go/bin/go.exeenv[c:\go]setGOARC

sockets - 服务器未在 "Hello World"套接字程序中获取消息

我正在练习将Unix套接字与bufio一起使用。这是程序://Registerserversocketos.Remove("serversock")socket,err:=net.ListenUnix("unix",&net.UnixAddr{"serversock","unix"})iferr!=nil{panic(err)}gofunc(){for{//Acceptnewconnectionconn,err:=socket.Accept()iferr!=nil{panic(err)}fmt.Println("Gotconnection")reader:=bufio.NewReade

go - cgo(golang): error: underfined reference to 'hello'

我只是写了一个非常简单的demo来测试用cgo(golang)加载共享库,代码如下:xxx.h#pragmaoncevoidmyprint(constchar*str);xxx.c#include"xxx.h"#includevoidmyprint(constchar*str){printf("%s\n",str);}构建共享库:gcc-fPIC-sharedxxx.c-olibxxx.so好的,从这里开始一切正常。现在,使用cgo加载libxxx.so,并使用myprint函数:packagemain/*#include#cgolinuxCFLAGS:-I../../include#

go - 运行 Hello Couchbase 应用程序时出现紧急运行时错误

关闭。这个问题需要debuggingdetails.它目前不接受答案。编辑问题以包含desiredbehavior,aspecificproblemorerror,andtheshortestcodenecessarytoreproducetheproblem.这将有助于其他人回答问题。关闭3年前。Improvethisquestion按照此处给出的说明安装goSDK1.6:https://docs.couchbase.com/go-sdk/current/start-using-sdk.html创建了如上页所列的HelloCouchbase应用程序。运行应用程序时,程序在:sligh

go - Hello World 语法错误

当我尝试使用6g编译器编译go语言网站首页的示例时,出现以下错误:hello.go:5:syntaxerrornear""我searchonGooglereveals有几个人遇到过这种情况,但我没有找到解决办法。答案似乎总是:“这对我有用,你一定做错了什么”。我找到了descriptionoftheproblem这可以追溯到5个月前,所以我怀疑这不是我正在使用的特定go版本的问题。此外,我已尝试拉取较新版本,但问题仍然存在。有问题的源代码:packagemainimport"fmt"funcmain(){fmt.Println("Hello,世界")}顺便说一句,我将源代码保存为UTF

go - 通过 Go 中的自定义 io.Writer 编辑敏感数据

我正在执行一些输出敏感数据的exec.Command。我想过滤掉这些数据。由于您可以将stdoutwriter设置为Command结构,我的想法是编写一个自定义io.Writer,它基本上使用输出和过滤器给定单词的输出。typepasswordFilterstruct{keyWordstring}func(pfpasswordFilter)Write(p[]byte)(nint,errerror){//thisiswhereIhavenoideawhattodo//IthinkIshouldsomehowuseascannerandthenfilter//out=strings.Rep

go - `bufio.Writer` 还是 `io.Writer`?

我有一个函数可以将数据写入任何实现接口(interface)的对象,该接口(interface)使用Write(b[]byte)(nint,errerror)方法。现在在我的程序中,我写入一个实际的Conn,但遵循最佳实践(https://dave.cheney.net/2016/08/20/solid-go-design),并且因为我只调用Write,所以我想接受最小接口(interface)实现该方法。为此,我接受了接口(interface)为io.Writer的参数。由于我的函数可以非常快速地输出大量数据,我应该接受bufio.Writer吗?还是函数的消费者有责任使用缓冲编写器

go - 在 Go 中实现 io.Writer 接口(interface)

我正在尝试通过“Write”方法创建一个满足io.Writer接口(interface)的结构类型:packagemainimport("fmt")typePersonstruct{name[]byte}func(pPerson)Write(data[]byte)(nint,errerror){p.name=datareturnlen(data),nil}funcmain(){b:=[]byte("Dave")person:=Person{}fmt.Fprint(person,b)fmt.Printf("Personname:%s\n",person.name)}但是指令fmt.Fpr