草庐IT

Makefile文件

全部标签

go - 运行由 Go build 创建的二进制文件时出现问题

我有一个简单的Go应用程序,它有一些模板文件,我可以在其中呈现一些文本。在使用Gobuild构建我的二进制文件后,我尝试运行该文件,但出现错误:panic:html/template:patternmatchesnofiles:public/*.html我正在使用Echo框架并按照他们的步骤为模板添加渲染。这是我的main.go文件中的代码//TemplateRendererisacustomhtml/templaterendererforEchoframeworktypeTemplateRendererstruct{templates*template.Template}//Rend

mongodb - 如何使用 Golang 从 Mongo GridFS 下载文件?

我正在尝试编写一个具有基本文件上传、下载功能的RestAPI。我能够很好地完成上传部分,但我很难从gridfs下载文件。有什么建议吗? 最佳答案 更新:我想我知道怎么做了。我很好奇是否有人有任何其他建议:这是我现在的样子:funcDownloadRecord(whttp.ResponseWriter,filenamestring)error{if!fileExists(filename){returnerrors.New("Filedoesn'texist.Nothingtodownload")}session:=sqlconnec

go - 如何将变量作为 shell 脚本文件运行

我需要在golang中运行一个变量作为shell脚本文件。我试过像下面的代码packagemainimport("fmt""os/exec")funcmain(){varnamespaceYamlstring=`#!/bin/bashdockerverson`out,err:=exec.Command(namespaceYaml).Output()fmt.Println(err,string(out))}但是我得不到任何结果。我找不到错误在哪里。请任何人解决此问题。提前致谢。 最佳答案 来自官方doc:funcCommand(nam

在另一个文件中转到公共(public)结构

我是GO的新手,不了解一些基础知识-所以我真的不知道如何向谷歌询问。所以我有一个包含2个文件的项目,它们都在main包中——src的根目录。一个文件是main.gopackagemainvar(node*NodeDTO)funcmain(){node=&NodeDTO{ID:1}}还有一个是dto.gowithpackagemaintypeNodeDTOstruct{IDint}所以main.go告诉我-“undefined:NodeDTO”。但是如果我在main.go附近创建一个dirdto并从那里使用我的NodeDTO就像packagemainimport"another_tcp_

go - 无法编译 Go 文件 - "initialization failure...xxxx redeclared in this block"

我是Go的新手,我按照website中的说明进行操作和youtubevideo当我运行gobuildhello.go时出现以下错误:go:disablingcache(/home/myuser/.cache/go-build)duetoinitializationfailure:open/home/myuser/.cache/go-build/log.txt:permissiondenied#runtime/usr/local/go/src/runtime/map.go:64:2:bucketCntBitsredeclaredinthisblockpreviousdeclaration

即使文件存在,通过 github.com repo 的 Golang 本地导入也不起作用

我确实知道Go对于导入来说很古怪,但我已经尝试(我相信)遵循约定,但是我无法导入结构。项目结构:/project-name/parser/main.go/query/main.go...Projectfilesinroot我在/parser/main.go导出了一个结构:packageparsertypeSomeTranslationStuffstruct{IDint`json:"Id"`Languagestring`json:"Language"`}我希望在/query/main.go中导入它。我是这样做的:import("github.com/org/project-name/pa

file - 查找目录中的重复文件

这是我的第一个Go程序。我正在学习这门语言,但理解所有概念有点困难,所以为了练习我写了一个代码来检测相同的文件。这是一个简单的程序,可以递归地检查目录中的重复文件。但是:如何检测目录文件中的重复文件问题不是目录递归。问题是如何比较 最佳答案 您可以获取每个文件主体的哈希值,然后比较字典/映射中的哈希值。packagemainimport("crypto/md5""fmt""io""io/ioutil""log""os")funcmain(){contentHashes:=make(map[string]string)iferr:=r

php - 在 golang 中读取 *.wav 文件

我使用file_get_contents在PHP中读取WAV文件,我想使用包github.com/mjibson/go-dsp/wav对于Go中的相同任务。但是没有关于这个包的任何简单示例。我是Go的新手,不了解它。有没有人指导我或建议其他方法?PHP代码:$wsdl='http://myApi.asmx?WSDL';$client=newSoapClient($wsdl));$data=file_get_contents(public_path()."/forTest/record.wav");$param=array('userName'=>'***','password'=>'*

typescript - 使用 golang 生成头文件/声明文件 - 都在一个文件中?

我希望根据一些.json数据自动生成一些Golang声明文件。理想情况下,我可以将所有声明/header数据放入一个文件中。但是Golang包/命名空间的工作方式,我怀疑我能做到这一点。我可以使用TypeScript而不是Golang,将很多TS类型/声明放在一个文件中,使用这样的命名空间:exportnamespaceEntities{exportnamespaceFoo{exportnamespaceGET{exportnamespaceBasic{exportinterfaceReq{}exportinterfaceRes{}}}exportnamespacePUT{export

go - 如何使 template.Execute() 写入文件而不是 response.Writer?

我有下面的代码来解析模板文件并将解析后的html写入ResponseWriter:-packagemainimport("net/http""html/template")funchandler(whttp.ResponseWriter,r*http.Request){t,_:=template.ParseFiles("view.html")t.Execute(w,"HelloWorld!")}funcmain(){server:=http.Server{Addr:"127.0.0.1:8080",}http.HandleFunc("/view",handler)server.List