github.com/gogf/gf@v1.16.9/.example/os/gfile/gfile.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/gogf/gf/os/gfile"
     7  	"github.com/gogf/gf/util/gutil"
     8  )
     9  
    10  var dirpath1 = "/home/john/Workspace/temp/"
    11  var dirpath2 = "/home/john/Workspace/temp/1"
    12  var filepath1 = "/home/john/Workspace/temp/test.php"
    13  var filepath2 = "/tmp/tmp.test"
    14  
    15  type BinData struct {
    16  	name string
    17  	age  int
    18  }
    19  
    20  func info() {
    21  	fmt.Println(gfile.Info(dirpath1))
    22  }
    23  
    24  func scanDir() {
    25  	gutil.Dump(gfile.ScanDir(dirpath1, "*"))
    26  }
    27  
    28  func getContents() {
    29  	fmt.Printf("%s\n", gfile.GetContents(filepath1))
    30  }
    31  
    32  func putContents() {
    33  	fmt.Println(gfile.PutContentsAppend(filepath2, "123"))
    34  }
    35  
    36  func putBinContents() {
    37  	fmt.Println(gfile.PutBytes(filepath2, []byte("abc")))
    38  }
    39  
    40  func main() {
    41  	//info()
    42  	//getContents()
    43  	//putContents()
    44  	putBinContents()
    45  	//scanDir()
    46  }