Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractFile ¶
Example ¶
Extract the file from the embed path (src) to the output path (dst).
outputFilePath := "./output.txt"
if err := ExtractFile(&embedBuildBat, "testData/hello.txt", outputFilePath); err != nil {
panic(err)
}
if _, err := os.Stat(outputFilePath); os.IsNotExist(err) {
panic(err)
}
defer func() {
if err := os.Remove(outputFilePath); err != nil {
panic(err)
}
}()
f, _ := os.Open(outputFilePath)
defer f.Close()
dataBytes, _ := io.ReadAll(f)
fmt.Println(string(dataBytes))
Output: Hello World!
func PromiseExtractFile ¶ added in v2.3.0
func PromiseExtractFile(fs *embed.FS, srcPath, dstPath string, successFunc func(dst string) error, errFunc func(err error) error, ) (err error)
PromiseExtractFile 與ExtractFile類似,但可以在成功或者失敗的時候在做某些事情
Example ¶
outputFilePath := "./output.txt"
if err := PromiseExtractFile(&embedBuildBat, "testData/hello.txt", outputFilePath,
func(dst string) error {
f, _ := os.Open(dst)
dataBytes, _ := io.ReadAll(f)
_ = f.Close()
fmt.Println(string(dataBytes))
return os.Remove(outputFilePath)
}, nil); err != nil {
panic(err)
}
if err := PromiseExtractFile(&embedBuildBat, "not_exist_file.txt", outputFilePath,
nil, func(err error) error {
fmt.Println("got an error")
return err
}); err == nil {
panic(err)
}
Output: Hello World! got an error
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.