github.com/searKing/golang/go@v1.2.74/os/example_test.go (about) 1 // Copyright 2022 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package os_test 6 7 import ( 8 "time" 9 ) 10 import os_ "github.com/searKing/golang/go/os" 11 12 func ExampleNewRotateFile() { 13 file := os_.NewRotateFile("log/test.2006-01-02-15-04-05.log") 14 defer file.Close() 15 file.MaxCount = 5 16 file.RotateInterval = 5 * time.Second 17 file.MaxAge = time.Hour 18 file.FileLinkPath = "log/s.log" 19 for i := 0; i < 10000; i++ { 20 time.Sleep(1 * time.Millisecond) 21 file.WriteString(time.Now().String()) 22 //if err := file.Rotate(false); err != nil { 23 // fmt.Printf("%d, err: %v", i, err) 24 //} 25 } 26 // Output: 27 } 28 29 func ExampleNewRotateFileWithStrftime() { 30 file := os_.NewRotateFileWithStrftime("log/test.%Y-%m-%d-%H-%M-%S.log") 31 file.MaxCount = 5 32 file.RotateInterval = 5 * time.Second 33 file.MaxAge = time.Hour 34 file.FileLinkPath = "log/s.log" 35 for i := 0; i < 10000; i++ { 36 time.Sleep(1 * time.Millisecond) 37 file.WriteString(time.Now().String()) 38 //if err := file.Rotate(false); err != nil { 39 // fmt.Printf("%d, err: %v", i, err) 40 //} 41 } 42 // Output: 43 } 44 45 func ExampleDiskUsage() { 46 total, free, avail, inodes, inodesFree, err := os_.DiskUsage("/tmp") 47 if err != nil { 48 return 49 } 50 51 _, _, _, _, _ = total, free, avail, inodes, inodesFree 52 //fmt.Printf("total :%d B, free: %d B, avail: %d B, inodes: %d, inodesFree: %d", total, free, avail, inodes, inodesFree) 53 // total :499963174912 B, free: 57534603264 B, avail: 57534603264 B, inodes: 566386444, inodesFree: 561861360 54 55 // Output: 56 }