github.com/gogf/gf@v1.16.9/os/gfpool/gfpool.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 // Package gfpool provides io-reusable pool for file pointer. 8 package gfpool 9 10 import ( 11 "github.com/gogf/gf/container/gmap" 12 "github.com/gogf/gf/container/gpool" 13 "github.com/gogf/gf/container/gtype" 14 "os" 15 "time" 16 ) 17 18 // File pointer pool. 19 type Pool struct { 20 id *gtype.Int // Pool id, which is used to mark this pool whether recreated. 21 pool *gpool.Pool // Underlying pool. 22 init *gtype.Bool // Whether initialized, used for marking this file added to fsnotify, and it can only be added just once. 23 ttl time.Duration // Time to live for file pointer items. 24 } 25 26 // File is an item in the pool. 27 type File struct { 28 *os.File // Underlying file pointer. 29 stat os.FileInfo // State of current file pointer. 30 pid int // Belonging pool id, which is set when file pointer created. It's used to check whether the pool is recreated. 31 pool *Pool // Belonging ool. 32 flag int // Flash for opening file. 33 perm os.FileMode // Permission for opening file. 34 path string // Absolute path of the file. 35 } 36 37 var ( 38 // Global file pointer pool. 39 pools = gmap.NewStrAnyMap(true) 40 )