Documentation ¶
Overview ¶
Package oss 操作系统相关.
Index ¶
- Constants
- Variables
- func Abs(path string) (string, error)
- func AppendFile(filename string) (*os.File, error)
- func Exist(path string) bool
- func IsDarwin() bool
- func IsDir(path string) bool
- func IsLinux() bool
- func IsWindows() bool
- func Open(file string) error
- func Remove(path string, depth int) error
- func Show(file string) error
Examples ¶
Constants ¶
View Source
const ( DefaultFileMode os.FileMode = 0o664 DefaultDirFileMod os.FileMode = 0o771 )
Variables ¶
View Source
var ErrNotDefined = errors.New("OS is not defined")
ErrNotDefined 系统不支持.
Functions ¶
func Abs ¶
Abs 返回路径的绝对表示,~符号表示用户根目录.
Example ¶
package main import ( "fmt" "os" "path/filepath" "github.com/samber/lo" "github.com/xuender/kit/oss" ) func main() { home, _ := os.UserHomeDir() fmt.Println(lo.Must1(oss.Abs("~/file")) == filepath.Join(home, "file")) }
Output: true
func AppendFile ¶ added in v1.0.10
AppendFile appends the given file.
Example ¶
ExampleAppendFile is an example function.
package main import ( "fmt" "os" "path/filepath" "github.com/xuender/kit/oss" ) func main() { file, err := oss.AppendFile(filepath.Join(os.TempDir(), "go-cli", "create.txt")) fmt.Println(err) fmt.Println(file.Write([]byte("123"))) file.Close() file, err = oss.AppendFile(filepath.Join(os.TempDir(), "go-cli", "create.txt")) fmt.Println(err) _, _ = file.Write([]byte("aaaa")) file.Close() data, _ := os.ReadFile(file.Name()) fmt.Println(string(data)) os.Remove(file.Name()) }
Output: <nil> 3 <nil> <nil> 123aaaa
func IsDarwin ¶
func IsDarwin() bool
IsDarwin 是否是 Darwin 系统.
Example ¶
package main import ( "fmt" "github.com/xuender/kit/oss" ) func main() { fmt.Println(oss.IsDarwin()) }
Output: false
func IsLinux ¶
func IsLinux() bool
IsLinux 是否是 Linux 系统.
Example ¶
package main import ( "fmt" "github.com/xuender/kit/oss" ) func main() { fmt.Println(oss.IsLinux()) }
Output: true
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.