Documentation ¶
Index ¶
- Constants
- Variables
- func AddHeadContent(content []byte, head []byte) []byte
- func AddTailContent(content []byte, tail []byte) []byte
- func Any2String(a any) string
- func CatFile(fileName string, w io.Writer)
- func CompressAndUncompress(src []byte)
- func CopyFile(dstName, srcName string) (written int64, err error)
- func DecodeHexOrBase64(content string) ([]byte, error)
- func DeleteLines(content []byte, lr LineRange) ([]byte, error)
- func DurationToTime(ms int64, duration time.Duration) time.Time
- func Exists(path string) bool
- func FindDigits(filename string) []byte
- func GracefulFprintf(data ...interface{}) string
- func ISSupportDuration(duration time.Duration) bool
- func IsDir(path string) bool
- func IsFile(path string) bool
- func KeyValue(buf *bytes.Buffer, val reflect.Value)
- func LocalIp() (string, error)
- func MapToString(a map[interface{}]interface{}) (string, error)
- func MillisecondToTime(ms int64) time.Time
- func Mkdir(path string) error
- func NewContext() (context.Context, context.CancelFunc)
- func NewContextWithTimeout(n time.Duration) (context.Context, context.CancelFunc)
- func RandomBytes(n int, alphabets ...byte) []byte
- func ReadFile(filename string) []string
- func Sieve() chan int
- func Sort(ids []uint32)
- func StartCPUProfile(fileName string) error
- func StringReverse(src string) string
- func SubString(src string, begin int) string
- func SubStringRange(src string, begin, end int) string
- func TimeToDuration(t time.Time, duration time.Duration) int64
- func TimeToMillisecond(t time.Time) int64
- func ToBytes(key string) ([]byte, error)
- func ToInt8s(key string) (is []int8, err error)
- func ToString(a interface{}) (string, error)
- func Walk(root string, recursive bool, suffix string, walkFn WalkFunc) error
- func ZlibCompress(src []byte) []byte
- func ZlibRead(in []byte) (ret []byte)
- func ZlibUnCompress(compressSrc []byte) []byte
- func ZlibWrite(in []byte) []byte
- type Compressor
- type LFCompressor
- type LineRange
- type OriginCompressor
- type Supervisor
- type WalkFunc
Constants ¶
View Source
const NBUF = 512
Variables ¶
View Source
var ErrLineRange = errors.New("go-util.file: line range error")
Functions ¶
func AddHeadContent ¶ added in v1.0.1
文件头部添加内容
func AddTailContent ¶ added in v1.0.1
文件尾部添加内容
func Any2String ¶ added in v1.0.5
func CompressAndUncompress ¶
func CompressAndUncompress(src []byte)
func DecodeHexOrBase64 ¶
func FindDigits ¶
FindDigits find digits from file 切片的底层指向一个数组,该数组的实际体积可能要大于切片所定义的体积。 只有在没有任何切片指向的时候,底层的数组内层才会被释放,这种特性有时会导致程序占用多余的内存。
func GracefulFprintf ¶
func GracefulFprintf(data ...interface{}) string
func ISSupportDuration ¶
func MapToString ¶
func MillisecondToTime ¶
func NewContextWithTimeout ¶
func RandomBytes ¶
RandomBytes generate random []byte by specify chars.
func StartCPUProfile ¶
func SubStringRange ¶
func Walk ¶ added in v1.0.1
遍历访问指定文件夹下的文件 @param root 需要遍历访问的文件夹 @param recursive 是否递归访问子文件夹 @param suffix 指定文件名后缀进行过滤,如果为"",则不过滤
func ZlibCompress ¶
func ZlibUnCompress ¶
Types ¶
type Compressor ¶ added in v1.0.1
type Compressor interface { // 将整型切片压缩成二进制字节切片 Compress(ids []uint32) (ret []byte) // 将二进制字节切片反序列化为整型切片 // 反序列化后得到的整型切片,切片中整型的顺序和序列化之前保持不变 UnCompress(b []byte) (ids []uint32) }
具体使用见 LFCompressor 和 OriginCompressor
type LFCompressor ¶ added in v1.0.1
type LFCompressor struct { FB uint32 // 用几个字节的 bit 表示跟随的数据 ZlibExt bool // 压缩之后,是否再用 zlib 进一步压缩 // contains filtered or unexported fields }
func (*LFCompressor) Compress ¶ added in v1.0.1
func (lfc *LFCompressor) Compress(ids []uint32) (ret []byte)
传入的整型切片必须是从小到大有序排列
func (*LFCompressor) UnCompress ¶ added in v1.0.1
func (lfc *LFCompressor) UnCompress(b []byte) (ids []uint32)
type OriginCompressor ¶ added in v1.0.1
type OriginCompressor struct {
ZlibExt bool // 压缩之后,是否再用 zlib 进一步压缩
}
func (*OriginCompressor) Compress ¶ added in v1.0.1
func (oc *OriginCompressor) Compress(ids []uint32) (ret []byte)
并不强制要求整型切片有序
func (*OriginCompressor) UnCompress ¶ added in v1.0.1
func (oc *OriginCompressor) UnCompress(b []byte) (ids []uint32)
type Supervisor ¶
type Supervisor struct {
// contains filtered or unexported fields
}
func MakeSupervisor ¶
func MakeSupervisor(maxRestartTime uint) Supervisor
MakeSupervisor create goroutine supervisor that proper panic
func (*Supervisor) Run ¶
func (s *Supervisor) Run(f func(), info string)
Click to show internal directories.
Click to hide internal directories.