mirror of
https://github.com/yudai/gotty.git
synced 2025-09-21 21:40:49 +02:00
Refactor
This commit is contained in:
parent
54403dd678
commit
a6133f34b7
54 changed files with 2140 additions and 1334 deletions
13
pkg/homedir/expand.go
Normal file
13
pkg/homedir/expand.go
Normal 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
|
||||
}
|
||||
}
|
18
pkg/randomstring/generate.go
Normal file
18
pkg/randomstring/generate.go
Normal 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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue