This commit is contained in:
Iwasaki Yudai 2017-02-26 07:37:07 +09:00
parent 54403dd678
commit a6133f34b7
54 changed files with 2140 additions and 1334 deletions

13
pkg/homedir/expand.go Normal file
View file

@ -0,0 +1,13 @@
package homedir
import (
"os"
)
func Expand(path string) string {
if path[0:2] == "~/" {
return os.Getenv("HOME") + path[1:]
} else {
return path
}
}

View file

@ -0,0 +1,18 @@
package randomstring
import (
"crypto/rand"
"math/big"
"strconv"
)
func Generate(length int) string {
const base = 36
size := big.NewInt(base)
n := make([]byte, length)
for i, _ := range n {
c, _ := rand.Int(rand.Reader, size)
n[i] = strconv.FormatInt(c.Int64(), base)[0]
}
return string(n)
}