草庐IT

file_base_name

全部标签

http - 在 golang 中渲染来自 base64 的图像

我想在golang中渲染来自base64的图像(这里是Twitter图标)packagemainimport(base64"encoding/base64""fmt""io""net/http""strconv")funcpix(whttp.ResponseWriter,r*http.Request){fmt.Fprintf(w,"Hithere,Ilove%s!",r.URL.Path[1:])varcookie*http.Cookiecookie,err:=r.Cookie("csrftoken")iferr!=nil{fmt.Printf("error")fmt.Println(

go - Base64 编码/解码导致输出损坏

我正在尝试编写一些base64编码和解码byteslice的便利包装函数。(无法理解为什么在stdlib中不方便地提供这一点。)但是这段代码(在playground中):funcb64encode(b[]byte)[]byte{encodedData:=&bytes.Buffer{}encoder:=base64.NewEncoder(base64.URLEncoding,encodedData)deferencoder.Close()encoder.Write(b)returnencodedData.Bytes()}funcb64decode(b[]byte)([]byte,erro

javascript - 给定相同的输入字符串,为什么这些 base64 编码输出不同?

当从相同的输入字符串中获取bas64编码的字符串时,我发现JavaScript、Groovy和Go具有相同的结果,但GNUbase64略有不同。这是为什么?JavaScript(nodejsv0.10.33):newBuffer('LaurenceTureaudisMr.T').toString('base64');TGF1cmVuY2UgVHVyZWF1ZCBpcyBNci4gVA==Groovy(Java8上的2.3.7):'LaurenceTureaudisMr.T'.bytes.encodeBase64().toString()TGF1cmVuY2UgVHVyZWF1ZCBpc

odbc - golang : CSV file to MS SQL does not work properly without placing fmt. Printf() 到 for 循环结束

我正在使用Go读取CSV文件并使用go-odbc将记录保存在MSSQL数据库中。它工作得很好,但我有一些记录(大约10条记录)没有被存储的问题。这是一个随机问题,有时3条没有保存,其他时候2条,等等。保存所有记录的唯一时间是当我将fmt.Printf("")放在末尾时循环。请注意,它必须打印一个空格,它不能只是fmt.Printf("")。我不确定我没有做错什么。任何建议表示赞赏。此外,没有产生任何错误,程序正常终止。我包含了相关问题的代码,如果您需要我发布完整代码,请告诉我。Go版本:go1.1windows/amd64for{record,err:=c.Read()iferr==i

gcc - 尝试使用 sqlite3 驱动程序运行 sql 应用程序时出现 "No such file or directory"错误

packagemainimport("fmt"_"github.com/mattn/go-sqlite3")funcmain(){DB,err:=sql.Open("sqlite3","/Users/MyUser/Documents/GOProj/test.db")iferr!=nil{fmt.Printf("Error:%s\n",err)}deferDB.Close()}每次我运行这段代码(使用SublimeText3,MacOSX10.9)我得到这个:execgcc:Nosuchfileordirectory/usr/local/go/pkg/tool/darwin_amd64/

google-app-engine - 要传递给 appengine/file.Delete() 的 fileName 的值是?

我想知道当你从gae/go中删除一个gcs文件时要传递的文件名是什么。虽然传递了“/gs/{bucketname}/{filename}”,但返回错误信息“RPCerrorUNKNOWN_ERROR:”packagemainimport("appengine""appengine/file""net/http")funchandle(whttp.ResponseWriter,r*http.Request){c:=appengine.NewContext(r)file.Delete(c,"/gs/{bucketname}/{filename}")} 最佳答案

macos - Go: "stat hello.go: no such file or directory"

刚刚在MacOSX上安装了Go,Yosemite版本10.10.3,如GettingStarted中所述官网页面:MacOSXpackageinstallerDownloadthepackagefile,openit,andfollowthepromptstoinstalltheGotools.ThepackageinstallstheGodistributionto/usr/local/go.Thepackageshouldputthe/usr/local/go/bindirectoryinyourPATHenvironmentvariable.Youmayneedtorestart

戈朗 : How do I determine the number of lines in a file efficiently?

在Golang中,我正在寻找一种确定文件行数的有效方法。当然,我总是可以遍历整个文件,但似乎效率不高。file,_:=os.Open("/path/to/filename")fileScanner:=bufio.NewScanner(file)lineCount:=0forfileScanner.Scan(){lineCount++}fmt.Println("numberoflines:",lineCount)有没有更好(更快、更便宜)的方法来查明一个文件有多少行? 最佳答案 这是一个更快的行计数器,使用bytes.Count来查找

java - 如何触发 java 应用程序(来自 Google GO/golang sub_process 的 java -jar <app name>

我正在尝试将java命令行应用程序作为golang的子进程触发。由于某种原因它失败了,实际上当我从GO启动它时我没有得到javaAPP界面。它等待几秒钟并以错误代码“无法连接...”终止这是我尝试使用的代码:packagemainimport("fmt""os/exec")funcmain(){start_java_app_test()}funcstart_java_app_test(){cmd_prep:="java-Xmx2g-jartest_app.jar"cmd_output,err:=exec.Command("bash","-c",cmd_prep).Output()ife

linux - go1.6 File方法WriteString频繁调用导致系统缓存大

go1.6文件方法WriteString频繁调用导致系统缓存很大。如何解决这个问题。进入环境:linuxamd64。这是Linux系统的问题吗?代码:packagemainimport("fmt""net/http""os""time")varlogCtxChchan*http.RequestvaraccessLogFile*os.FiletypeHandlerHttpstruct{}func(this*HandlerHttp)ServeHTTP(whttp.ResponseWriter,req*http.Request){sendAccessLog(req)w.Write([]byt