blog_backend_api/utils/base.go

40 lines
692 B
Go

package utils
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
func ByteSliceToString(b []byte) string {
var ret string
for i := 0; i < len(b); i++ {
s := fmt.Sprintf("%02x", b[i])
ret += string(s)
}
return ret
}
func GetCurrentDirectory() string {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
return "./"
}
return strings.Replace(dir, "\\", "/", -1)
}
func GetPathFileName(pathname string) (error) {
rd, err := ioutil.ReadDir(pathname)
for _, fi := range rd {
if fi.IsDir() {
fmt.Printf("[%s]\n", pathname+"\\"+fi.Name())
GetPathFileName(pathname + fi.Name() + "\\")
} else {
fmt.Println(fi.Name())
}
}
return err
}