mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-14 16:17:17 +03:00
Replace first ~ with user.HomeDir, if possible
This commit is contained in:
parent
9a00714632
commit
7d8e5146b1
11
cmd.go
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user