Documentation ¶
Overview ¶
* @Author: soso * @Date: 2022-01-12 15:58:23 * @LastEditTime: 2022-01-25 12:48:20 * @LastEditors: Please set LastEditors * @Description: 文件锁操作 * @FilePath: /file-sync/utils/flock/flock.go
* @Author: your name * @Date: 2022-02-09 13:18:12 * @LastEditTime: 2022-02-09 17:28:57 * @LastEditors: Please set LastEditors * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @FilePath: /go-mesh-sync/go-utils/utils/map.go
* @Author: soso * @Date: 2022-03-15 11:22:37 * @LastEditTime: 2022-03-15 13:35:35 * @LastEditors: Please set LastEditors * @Description: 网络相关 * @FilePath: /go-utils/utils/net.go
* @Author: soso * @Date: 2022-03-09 16:46:07 * @LastEditTime: 2022-03-09 16:58:36 * @LastEditors: Please set LastEditors * @Description: 获取工作路径 * @FilePath: /go-utils/utils/path.go
* @Author: soso * @Date: 2022-01-20 18:29:37 * @LastEditTime: 2022-01-26 14:57:37 * @LastEditors: Please set LastEditors * @Description: soso * @FilePath: /file-sync/utils/time.go
* @Author: soso * @Date: 2022-01-05 18:55:23 * @LastEditTime: 2022-03-15 11:23:14 * @LastEditors: Please set LastEditors * @Description: 通用工具 * @FilePath: /file-sync/utils/utils.go
Index ¶
- Constants
- func AppendFile(filename string, buf []byte) (err error)
- func AskForConfirmation(s string) bool
- func B2s(b []byte) string
- func CheckIsHidden(file os.FileInfo) bool
- func ClearBlock(filename string, offset, size int64) (nn int64, err error)
- func ClientIP(r *http.Request) string
- func ClientPublicIP(r *http.Request) string
- func CreateEmptyFile(filePath string, size int64) error
- func Difference(slice1, slice2 []string) []string
- func ExecCommand(commandName string, arg ...string) ([]string, error)
- func ExecDir() (execdir string)
- func FileCropBlock(filename string, offset, size int64) error
- func FileExist(filePath string) (fs.FileInfo, error)
- func FileReadToEnd(filename string, offset int64) (data []byte, err error)
- func FileReplaceBlock(filename string, offset, size int64, newBytes []byte) error
- func FindInIntSlice(a []int, x int) int
- func FindInStrSlice(a []string, x string) int
- func GetAllFiles(pathname string) (files []string)
- func GetClientIP() (ip string, err error)
- func GetCurrentAbPath() string
- func GetFileContentType(out *os.File) (string, error)
- func GetFileType(fSrc []byte) string
- func GetIpByLocalDns(dnsIp string) (ip string, err error)
- func GetIpBySubnet(subnet string) (ip string, err error)
- func GetLocalIP() string
- func GetLocalIPOnce() string
- func GetOutBoundIP() (ip string, err error)
- func HasLocalIP(ip net.IP) bool
- func HasLocalIPddr(ip string) bool
- func HashFileMd5(filename string) (md5str string, err error)
- func HashLargeFileMD5(path string) string
- func HideFile(filename string) error
- func Intersect(slice1, slice2 []string) []string
- func LastSecOfTheDayBeforeYesterday(tm time.Time) time.Time
- func MyCaller() string
- func OnInternet() bool
- func OpenAppendFile(filename string, autoCreate bool) (f *os.File, err error)
- func OpenRDonlyFile(filename string) (f *os.File, err error)
- func OpenWRonlyFile(filename string, autoCreate bool) (f *os.File, err error)
- func RelativePath(path1, path2 string) (string, error)
- func RunCommand(out chan string, name string, arg ...string) error
- func S2b(s string) (b []byte)
- func StringMd5(val []byte) []byte
- func TimeFromString(val string) time.Time
- func ToMap(in interface{}, tagName string) (map[string]interface{}, error)
- func TouchAFile(filePath string) error
- func Union(slice1, slice2 []string) []string
- func WriteFile(filename string, data []byte, perm fs.FileMode) error
- type Bar
- type Flock
Constants ¶
const (
BufSize = 8 * 1024
)
Variables ¶
This section is empty.
Functions ¶
func B2s ¶
b2s converts byte slice to a string without memory allocation. See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
Note it may break if string and/or slice header will change in the future go versions.
func CheckIsHidden ¶
func ClearBlock ¶
清除文件的一块
func ClientPublicIP ¶
ClientPublicIP 尽最大努力实现获取客户端公网 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。
func ExecCommand ¶
*
- @description: 执行命令
- @param {string} commandName
- @param {...string} arg
- @return {*}
func FileCropBlock ¶
func FileReadToEnd ¶
文件读取到最后
func FileReplaceBlock ¶
替换文件中的某一块
func FindInIntSlice ¶
func FindInStrSlice ¶
func GetLocalIPOnce ¶
func GetLocalIPOnce() string
*
- @description: 以两种方式获得本地IP
- @param {*}
- @return {*}
func MyCaller ¶
func MyCaller() string
MyCaller returns the caller of the function that called it :)
func OnInternet ¶
func OnInternet() bool
func RelativePath ¶
func RunCommand ¶
RunCommand run shell
func S2b ¶
s2b converts string to a byte slice without memory allocation.
Note it may break if string and/or slice header will change in the future go versions.
func TimeFromString ¶
Types ¶
type Bar ¶
type Bar struct {
// contains filtered or unexported fields
}
func (*Bar) NewOptionWithGraph ¶
type Flock ¶
type Flock struct {
// contains filtered or unexported fields
}
func FlockCreate ¶
创建文件锁,配合 defer f.Release() 来使用