diff --git a/os/gfile/gfile_z_example_cache_test.go b/os/gfile/gfile_z_example_cache_test.go index 2088b3b66..3ca819779 100644 --- a/os/gfile/gfile_z_example_cache_test.go +++ b/os/gfile/gfile_z_example_cache_test.go @@ -24,12 +24,14 @@ func ExampleGetContentsWithCache() { // write contents gfile.PutContents(tempFile, "goframe example content") - // read contents + // It reads the file content with cache duration of one minute, + // which means it reads from cache after then without any IO operations within on minute. fmt.Println(gfile.GetContentsWithCache(tempFile, time.Minute)) // write new contents will clear its cache gfile.PutContents(tempFile, "new goframe example content") + // There's some delay for cache clearing after file content change. time.Sleep(time.Second * 1) // read contents diff --git a/os/gfile/gfile_z_example_contents_test.go b/os/gfile/gfile_z_example_contents_test.go index 62b70880d..7f13c6ae5 100644 --- a/os/gfile/gfile_z_example_contents_test.go +++ b/os/gfile/gfile_z_example_contents_test.go @@ -23,7 +23,8 @@ func ExampleGetContents() { // write contents gfile.PutContents(tempFile, "goframe example content") - // read contents + // It reads and returns the file content as string. + // It returns empty string if it fails reading, for example, with permission or IO error. fmt.Println(gfile.GetContents(tempFile)) // Output: @@ -41,7 +42,8 @@ func ExampleGetBytes() { // write contents gfile.PutContents(tempFile, "goframe example content") - // read contents + // It reads and returns the file content as []byte. + // It returns nil if it fails reading, for example, with permission or IO error. fmt.Println(gfile.GetBytes(tempFile)) // Output: @@ -56,7 +58,8 @@ func ExamplePutContents() { tempFile = gfile.Join(tempDir, fileName) ) - // write contents + // It creates and puts content string into specifies file path. + // It automatically creates directory recursively if it does not exist. gfile.PutContents(tempFile, "goframe example content") // read contents diff --git a/os/gfile/gfile_z_example_replace_test.go b/os/gfile/gfile_z_example_replace_test.go index 9ca547aec..d9c6935b7 100644 --- a/os/gfile/gfile_z_example_replace_test.go +++ b/os/gfile/gfile_z_example_replace_test.go @@ -50,7 +50,7 @@ func ExampleReplaceFileFunc() { // read contents fmt.Println(gfile.GetContents(tempFile)) - // replace by yourself + // It replaces content directly by file path and callback function. gfile.ReplaceFileFunc(func(path, content string) string { // Replace with regular match reg, _ := regexp.Compile(`\d{3}`) @@ -78,6 +78,7 @@ func ExampleReplaceDir() { // read contents fmt.Println(gfile.GetContents(tempFile)) + // It replaces content of all files under specified directory recursively. gfile.ReplaceDir("content", "replace word", tempDir, "gflie_example.txt", true) // read contents @@ -102,7 +103,7 @@ func ExampleReplaceDirFunc() { // read contents fmt.Println(gfile.GetContents(tempFile)) - // replace by yourself + // It replaces content of all files under specified directory with custom callback function recursively. gfile.ReplaceDirFunc(func(path, content string) string { // Replace with regular match reg, _ := regexp.Compile(`\d{3}`) diff --git a/os/gfile/gfile_z_example_scan_test.go b/os/gfile/gfile_z_example_scan_test.go index b5e91eb72..0238dbbb0 100644 --- a/os/gfile/gfile_z_example_scan_test.go +++ b/os/gfile/gfile_z_example_scan_test.go @@ -55,7 +55,7 @@ func ExampleScanDirFile() { gfile.PutContents(tempSubFile, "goframe example content") // scans directory recursively exclusive of directories - list, _ := gfile.ScanDirFile(tempDir, "*", true) + list, _ := gfile.ScanDirFile(tempDir, "*.txt", true) for _, v := range list { fmt.Println(gfile.Basename(v)) } @@ -116,7 +116,7 @@ func ExampleScanDirFileFunc() { gfile.PutContents(tempSubFile, "goframe example content") // scans directory recursively exclusive of directories - list, _ := gfile.ScanDirFileFunc(tempDir, "*", true, func(path string) string { + list, _ := gfile.ScanDirFileFunc(tempDir, "*.txt", true, func(path string) string { // ignores some files if gfile.Basename(path) == "gflie_example_ignores.txt" { return ""