1 Star 0 Fork 0

aspnmy/i18n4go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
no_strings.go 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
package app
import (
"io/ioutil"
"os"
"path/filepath"
"strconv"
"sync"
"time"
)
func TempDir(namePrefix string, cb func(tmpDir string, err error)) {
tmpDir, err := ioutil.TempDir("", namePrefix)
defer func() {
os.RemoveAll(tmpDir)
}()
cb(tmpDir, err)
}
func TempFile(namePrefix string, cb func(tmpFile *os.File, err error)) {
tmpFile, err := ioutil.TempFile("", namePrefix)
defer func() {
tmpFile.Close()
os.Remove(tmpFile.Name())
}()
cb(tmpFile, err)
}
// TempPath generates a random file path in tmp, but does
// NOT create the actual directory
func TempPath(namePrefix string) string {
return filepath.Join(os.TempDir(), namePrefix, nextSuffix())
}
// copied from http://golang.org/src/pkg/io/ioutil/tempfile.go
// Random number state.
// We generate random temporary file names so that there's a good
// chance the file doesn't exist yet - keeps the number of tries in
// TempFile to a minimum.
var rand uint32
var randmu sync.Mutex
func reseed() uint32 {
return uint32(time.Now().UnixNano() + int64(os.Getpid()))
}
func nextSuffix() string {
randmu.Lock()
r := rand
if r == 0 {
r = reseed()
}
r = r*1664525 + 1013904223 // constants from Numerical Recipes
rand = r
randmu.Unlock()
return strconv.Itoa(int(1e9 + r%1e9))[1:]
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/Aodao/i18n4go.git
git@gitee.com:Aodao/i18n4go.git
Aodao
i18n4go
i18n4go
v0.2.6

搜索帮助