mirror of
https://gitee.com/johng/gf
synced 2026-06-07 10:22:11 +08:00
临时去掉gfpool文件指针池的使用
This commit is contained in:
4
TODO.MD
4
TODO.MD
@ -41,8 +41,8 @@
|
||||
- https://github.com/Masterminds/sprig
|
||||
1. gform参考 https://gohouse.github.io/gorose/dist/index.html 进行改进
|
||||
1. 模板引擎增加对对象的支持(参考https://segmentfault.com/q/1010000016829214);
|
||||
|
||||
|
||||
1. 由于系统对inotify实例数量(`fs.inotify.max_user_instances`)以及队列大小(`fs.inotify.max_user_watches`)有限制,需要改进`gfsnotify`;
|
||||
1. 改进gfpool在文件指针变化时的更新;
|
||||
|
||||
|
||||
# DONE
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
package gfile
|
||||
|
||||
import (
|
||||
"gitee.com/johng/gf/g/os/gfpool"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@ -35,7 +34,7 @@ func GetBinContents(path string) []byte {
|
||||
}
|
||||
|
||||
// 写入文件内容
|
||||
func putContents(path string, data []byte, flag int, perm os.FileMode) error {
|
||||
func putContents(path string, data []byte, flag int, perm int) error {
|
||||
// 支持目录递归创建
|
||||
dir := Dir(path)
|
||||
if !Exists(dir) {
|
||||
@ -43,8 +42,8 @@ func putContents(path string, data []byte, flag int, perm os.FileMode) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// 创建/打开文件,使用文件指针池,默认60秒
|
||||
f, err := gfpool.OpenFile(path, flag, perm, gFILE_POOL_EXPIRE*1000)
|
||||
// 创建/打开文件
|
||||
f, err := OpenWithFlagPerm(path, flag, perm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -103,9 +102,9 @@ func GetNextCharOffset(file *os.File, char byte, start int64) int64 {
|
||||
|
||||
// 获得文件内容下一个指定字节的位置
|
||||
func GetNextCharOffsetByPath(path string, char byte, start int64) int64 {
|
||||
if f, err := gfpool.Open(path, os.O_RDONLY, gDEFAULT_PERM, gFILE_POOL_EXPIRE*1000); err == nil {
|
||||
if f, err := OpenWithFlagPerm(path, os.O_RDONLY, gDEFAULT_PERM); err == nil {
|
||||
defer f.Close()
|
||||
return GetNextCharOffset(&f.File, char, start)
|
||||
return GetNextCharOffset(f, char, start)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
@ -122,9 +121,9 @@ func GetBinContentsTilChar(file *os.File, char byte, start int64) ([]byte, int64
|
||||
|
||||
// 获得文件内容直到下一个指定字节的位置(返回值包含该位置字符内容)
|
||||
func GetBinContentsTilCharByPath(path string, char byte, start int64) ([]byte, int64) {
|
||||
if f, err := gfpool.Open(path, os.O_RDONLY, gDEFAULT_PERM, gFILE_POOL_EXPIRE*1000); err == nil {
|
||||
if f, err := OpenWithFlagPerm(path, os.O_RDONLY, gDEFAULT_PERM); err == nil {
|
||||
defer f.Close()
|
||||
return GetBinContentsTilChar(&f.File, char, start)
|
||||
return GetBinContentsTilChar(f, char, start)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
@ -142,9 +141,9 @@ func GetBinContentsByTwoOffsets(file *os.File, start int64, end int64) []byte {
|
||||
|
||||
// 获得文件内容中两个offset之间的内容 [start, end)
|
||||
func GetBinContentsByTwoOffsetsByPath(path string, start int64, end int64) []byte {
|
||||
if f, err := gfpool.Open(path, os.O_RDONLY, gDEFAULT_PERM, gFILE_POOL_EXPIRE*1000); err == nil {
|
||||
if f, err := OpenWithFlagPerm(path, os.O_RDONLY, gDEFAULT_PERM); err == nil {
|
||||
defer f.Close()
|
||||
return GetBinContentsByTwoOffsets(&f.File, start, end)
|
||||
return GetBinContentsByTwoOffsets(f, start, end)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@ -8,19 +8,18 @@
|
||||
package glog
|
||||
|
||||
import (
|
||||
"os"
|
||||
"io"
|
||||
"time"
|
||||
"fmt"
|
||||
"strings"
|
||||
"runtime"
|
||||
"gitee.com/johng/gf/g/os/gfile"
|
||||
"gitee.com/johng/gf/g/util/gregex"
|
||||
"gitee.com/johng/gf/g/container/gtype"
|
||||
"gitee.com/johng/gf/g/os/gfile"
|
||||
"gitee.com/johng/gf/g/os/gmlock"
|
||||
"gitee.com/johng/gf/g/os/gfpool"
|
||||
"sync"
|
||||
"gitee.com/johng/gf/g/os/gtime"
|
||||
"gitee.com/johng/gf/g/util/gregex"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Logger struct {
|
||||
@ -128,14 +127,14 @@ func (l *Logger) GetWriter() io.Writer {
|
||||
}
|
||||
|
||||
// 获取默认的文件IO
|
||||
func (l *Logger) getFilePointer() *gfpool.File {
|
||||
func (l *Logger) getFilePointer() *os.File {
|
||||
if path := l.path.Val(); path != "" {
|
||||
// 文件名称中使用"{}"包含的内容使用gtime格式化
|
||||
file, _ := gregex.ReplaceStringFunc(`{.+?}`, l.file.Val(), func(s string) string {
|
||||
return gtime.Now().Format(strings.Trim(s, "{}"))
|
||||
})
|
||||
fpath := path + gfile.Separator + file
|
||||
if fp, err := gfpool.Open(fpath, gDEFAULT_FILE_POOL_FLAGS, 0666); err == nil {
|
||||
if fp, err := gfile.OpenWithFlagPerm(fpath, gDEFAULT_FILE_POOL_FLAGS, 0666); err == nil {
|
||||
return fp
|
||||
} else {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
@ -249,20 +248,20 @@ func (l *Logger) GetBacktrace(skip...int) string {
|
||||
from := 0
|
||||
// 首先定位业务文件开始位置
|
||||
for i := 0; i < 10; i++ {
|
||||
if _, cfile, _, ok := runtime.Caller(i); ok {
|
||||
if !gregex.IsMatchString("/g/os/glog/glog.+$", cfile) {
|
||||
if _, file, _, ok := runtime.Caller(i); ok {
|
||||
if !gregex.IsMatchString("/g/os/glog/glog.+$", file) {
|
||||
from = i
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
// 从业务文件开始位置根据自定义的skip开始backtrace
|
||||
goroot := runtime.GOROOT()
|
||||
goRoot := runtime.GOROOT()
|
||||
for i := from + customSkip + l.btSkip.Val(); i < 10000; i++ {
|
||||
if _, cfile, cline, ok := runtime.Caller(i); ok && cfile != "" {
|
||||
if _, file, cline, ok := runtime.Caller(i); ok && file != "" {
|
||||
// 不打印出go源码路径及glog包文件路径,日志打印必须从业务源码文件开始,且从glog包文件开始检索
|
||||
if (goroot == "" || !gregex.IsMatchString("^" + goroot, cfile)) && !gregex.IsMatchString(`<autogenerated>`, cfile) {
|
||||
backtrace += fmt.Sprintf(`%d. %s:%d%s`, index, cfile, cline, ln)
|
||||
if (goRoot == "" || !gregex.IsMatchString("^" + goRoot, file)) && !gregex.IsMatchString(`<autogenerated>`, file) {
|
||||
backtrace += fmt.Sprintf(`%d. %s:%d%s`, index, file, cline, ln)
|
||||
index++
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -1,24 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gitee.com/johng/gf/g/frame/gmvc"
|
||||
"gitee.com/johng/gf/g/net/ghttp"
|
||||
"fmt"
|
||||
"gitee.com/johng/gf/g/os/gtime"
|
||||
"gitee.com/johng/gf/third/github.com/fsnotify/fsnotify"
|
||||
)
|
||||
type ControllerIndex struct {
|
||||
gmvc.Controller
|
||||
}
|
||||
func (c *ControllerIndex) Info() {
|
||||
c.View.Assign("title", "Go Frame 第一个网站")
|
||||
c.View.Assigns(map[string]interface{}{
|
||||
"name" : "很开心",
|
||||
"score" : 100,
|
||||
})
|
||||
c.View.Display("web/index.html")
|
||||
}
|
||||
|
||||
func main() {
|
||||
s := ghttp.GetServer()
|
||||
s.SetServerRoot("/home/john/Workspace/Go/GOPATH/src/gitee.com/johng/gf/geg/other/web/")
|
||||
s.BindController("/", new(ControllerIndex))
|
||||
s.SetPort(8199)
|
||||
s.Run()
|
||||
if w, err := fsnotify.NewWatcher(); err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Println(gtime.Now().String())
|
||||
w.Add("/tmp/test")
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,12 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gitee.com/johng/gf/g/util/gregex"
|
||||
"gitee.com/johng/gf/g/container/garray"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := `[0-9][0-9]/Jan/[0-9][0-9][0-9][0-9]:[0-9][0-9]:[0-9][0-9]:[0-9][0-9] \+[0-9][0-9][0-9][0-9]`
|
||||
s,_ = gregex.ReplaceString(`[A-Za-z]`, `[A-Za-z]`, s)
|
||||
fmt.Println(s)
|
||||
a := garray.NewSortedIntArray(0)
|
||||
a.Add(1)
|
||||
a.Remove(0)
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
123456789
|
||||
Reference in New Issue
Block a user