草庐IT

其他OS

全部标签

post - cURL 有效,但没有其他客户端使用 Go sebserver

有一个简单的GOWebServer,它接受图像作为POST请求的一部分。代码片段-请求映射到此函数funcUploadFile(whttp.ResponseWriter,r*http.Request,phttprouter.Params){successResponse:=models.HTTPResponse{FileURL:"http://testing.com",}WrapResponse(w,successResponse,http.StatusOK)}回复作者功能funcWrapResponse(writerhttp.ResponseWriter,contentinterfa

go - 带有 O_CREATE 标志的 os.OpenFile 抛出没有这样的文件或目录

我正在尝试使用os.OpenFile函数打开带有os包的日志文件,如果此类文件不存在,它应该使用适当的标志创建文件。但它返回非零错误:没有这样的文件或目录。顺便说一句,我正在使用linux并使用1.6。日志文件打开发生在init函数中。这是我的代码:packagemainimport("encoding/json""fmt""log""net/http""os""github.com/gorilla/mux""github.com/gorilla/sessions")//Structsholdsserverconfigurationdatafromconfigjson.typeserv

Go OS 文件从文档中读取示例不起作用 - 声明

我在这里阅读GOOS文档https://golang.org/pkg/os/文档给出了这段代码file,err:=os.Open("file.go")//Forreadaccess.iferr!=nil{log.Fatal(err)}然后是这个data:=make([]byte,100)count,err:=file.Read(data)iferr!=nil{log.Fatal(err)}然而,当我在这个例子中使用它时,我得到了函数体之外的非声明。我应该如何使用此示例中的文档代码?packagemainimport("encoding/xml""fmt""log""os")typedo

windows - os.File.SetReadDealine : file type does not support deadline

我用的是win10和go1.11windows/amd64deviceid,err:=getdeviceid(config.PlatformSpecificParams.ComponentID)iferr!=nil{returnnil,err}path:="\\\\.\\Global\\"+deviceid+".tap"pathp,err:=syscall.UTF16PtrFromString(path)iferr!=nil{returnnil,err}fileFd,err:=syscall.CreateFile(pathp,syscall.GENERIC_READ|syscall.G

unit-testing - 如何使用 os.O_RDWR 和 os.O_CREATE 标志测试 file.Open?

我正在尝试为结构构造函数编写单元测试,如果在file.Open期间发生错误,它也可能返回nil。我不知道如何使用标志测试/模拟文件错误:os.O_RDWR|os.O_CREATE|os.O_APPEND我试图在测试中检查nil值,但失败了。构造函数:typeAppstruct{someFieldstringlog*log.Logger}funcNew()*App{app:=&App{}f,err:=os.OpenFile("info.log",os.O_RDWR|os.O_CREATE|os.O_APPEND,0666)iferr!=nil{fmt.Printf("erroropeni

Golang 将任何结构存储在其他结构字段中

我有这个代码:typeTestDatastruct{Keystring}typeTemporaryStoreItemstruct{keystringdatainterface{}aliveUntiltime.Time}func(s*TemporaryStoreItem)SetData(srcinterface{}){src=s.data}data:=TestData{Key:"value",}item:=TemporaryStoreItem{key:"item1",data:data,aliveUntil:time.Now(),}oldItem:=TestData{}item.SetD

linux - 在 go 中使用 windows dll 库,为 linux 和 mac os x 编译

我只是想知道是否有机会在我的go项目中使用专有的windowsdll,为macosx和linux编译? 最佳答案 不,您不能在Linux/OSX上使用Windowsdll。但是,如果您真的必须这样做,您总是可以像TeamViewer那样使用预编译的wine和Steam上的一些“近乎原生”的游戏来发布您的软件。 关于linux-在go中使用windowsdll库,为linux和macosx编译,我们在StackOverflow上找到一个类似的问题: https:

gob 编码到/从 *os.File 解码不工作

当我使用文件指针时f*os.File我得到一个空映射funcdecode(f*os.File,bmap[string]interface{})error{err:=gob.NewDecoder(f).Decode(&b)fmt.Printf("%+v\n",b)returnerr}funcencode(f*os.File,bmap[string]interface{})error{bb:=map[string]interface{}{"X":1,"Greeting":"hello",}err:=gob.NewEncoder(f).Encode(bb)f.Sync()//fmt.Prin

file - os.File 是如何实现 io.Writer 的?

我能做到:f,err:=os.Create("file")iferr!=nil{....}by:=bufio.NewWriter(f)还有这个:var_io.Writer=&os.File{}os.File的包文档导致thissourcefile它确实包含一个未导出的写函数,但是当我尝试使用未导出的函数实现接口(interface)时出现错误。var_Disease=&Scratch{}//*Scratchdoesn'timplementDiseasehavespread()wantSpread()typeDiseaseinterface{Spread()}typeScratchstr

go - conn.Read 在通过其他 go 例程关闭 conn 时进入无限循环

我的代码有点复杂,但简单来说,它有多个go例程,所有都调用不同的TCP服务器,并在流中出现可读消息时在for循环中读取输入。到目前为止,一切都很好。现在有另一个go例程来管理之前的一堆“客户端”并在用户需要时关闭它们。为此,我将每个“conn”与适当的goroutine客户端相关联并关闭它。我面临的问题是,只要我调用任何conn对象的close函数,其对应的Read函数就会进入无限循环,不断读取空字符串。我写了一个简单的代码,类似于我在多个go例程中处理连接的方式-https://play.golang.org/p/wq7zt9Kqz7长话短说简而言之,我有一个“类”,它代表一个远程服