会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
KangKang闲事杂谈
博客园
首页
新随笔
联系
订阅
管理
2022年2月11日
go 实现timeout功能
摘要: package main import ( "fmt" "math/rand" "time" ) func init() { rand.Seed(time.Now().UnixNano()) } func main() { ch1 := make(chan bool) timeout := make
阅读全文
posted @ 2022-02-11 10:59 wangsk
阅读(242)
评论(0)
推荐(0)
2022年2月10日
go 通过goroutine例程读取文件的行数
摘要: package main import ( "bufio" "fmt" "io/fs" "os" "path/filepath" "strings" "sync" ) func FileLine(path string) int { file, err := os.Open(path) //定义行数
阅读全文
posted @ 2022-02-10 15:50 wangsk
阅读(252)
评论(0)
推荐(0)
2022年2月3日
go 根据文件的大小,加上单位值
摘要: package main import ( "fmt" "io/ioutil" ) func FormatSize(size int64) string { units := [6]string{"B", "KB", "MB", "GB", "TB", "PB"} fsize := float64(
阅读全文
posted @ 2022-02-03 16:44 wangsk
阅读(77)
评论(0)
推荐(0)
go 实现Copy方法
摘要: package main import ( "fmt" "io" "os" ) /* 拷贝文件 读 写入新文件 */ func CopyFile(src, dest string) error { srcFile, err := os.Open(src) if err != nil { return
阅读全文
posted @ 2022-02-03 15:34 wangsk
阅读(299)
评论(0)
推荐(0)
go 遍历文件中的所有文件打印
摘要: package main import ( "fmt" "io" "os" "strings" ) type fileFilter func(fpath string) bool type callBack func(path string) func ReadFile(path string) {
阅读全文
posted @ 2022-02-03 11:17 wangsk
阅读(113)
评论(0)
推荐(0)
go log写入文件中
摘要: package main import ( "log" "os" ) func main() { file, err := os.OpenFile("logfile.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, os.ModePerm) if err != nil
阅读全文
posted @ 2022-02-03 10:12 wangsk
阅读(415)
评论(0)
推荐(0)
公告