1
0
mirror of https://github.com/shazow/ssh-chat.git synced 2025-04-23 04:00:31 +03:00

Merge pull request from peterhellberg/master

Replace first ~ with user.HomeDir, if possible
This commit is contained in:
Andrey Petrov 2014-12-14 19:26:42 -08:00
commit b8c3106fdd

11
cmd.go

@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"os/signal"
"os/user"
"strings"
"net/http"
@ -61,7 +62,15 @@ func main() {
logLevel := logLevels[numVerbose]
logger = golog.New(os.Stderr, logLevel)
privateKey, err := ioutil.ReadFile(options.Identity)
privateKeyPath := options.Identity
if strings.HasPrefix(privateKeyPath, "~") {
user, err := user.Current()
if err == nil {
privateKeyPath = strings.Replace(privateKeyPath, "~", user.HomeDir, 1)
}
}
privateKey, err := ioutil.ReadFile(privateKeyPath)
if err != nil {
logger.Errorf("Failed to load identity: %v", err)
return