工具包
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

file.go 516 B

12345678910111213141516171819202122
  1. package utils
  2. import (
  3. "os"
  4. "path"
  5. "strings"
  6. "time"
  7. )
  8. // 获取文件后缀
  9. func FileExt(fname string) string {
  10. return strings.ToLower(strings.TrimLeft(path.Ext(fname), "."))
  11. }
  12. func FilePutContents(fileName string, content string) {
  13. fd, _ := os.OpenFile("./tmp/"+fileName+".log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
  14. fd_time := time.Now().Format("2006-01-02 15:04:05")
  15. fd_content := strings.Join([]string{"[", fd_time, "] ", content, "\n"}, "")
  16. buf := []byte(fd_content)
  17. fd.Write(buf)
  18. fd.Close()
  19. }