From 1ea65e0c9abfc3d5292e8c9d2c0887f0de7da8ca Mon Sep 17 00:00:00 2001 From: "honwen.chan" Date: Wed, 25 May 2016 21:56:41 +0800 Subject: [PATCH] fix cant find pem problem --- tls.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tls.go b/tls.go index 9c7ffc2..859c03b 100644 --- a/tls.go +++ b/tls.go @@ -3,6 +3,8 @@ package main import ( "crypto/tls" "github.com/golang/glog" + "os" + "path/filepath" ) const ( @@ -54,9 +56,19 @@ nh/BAoGBAMY5z2f1pmMhrvtPDSlEVjgjELbaInxFaxPLR4Pdyzn83gtIIU14+R8X -----END RSA PRIVATE KEY-----` ) +func getCurrentDirectory() string { + dir, err := filepath.Abs(filepath.Dir(os.Args[0])) + if err != nil { + return "" + } + return dir +} + func init() { var err error - if tlsCert, err = tls.LoadX509KeyPair("cert.pem", "key.pem"); err != nil { + cert := filepath.Join(getCurrentDirectory(), "cert.pem") + key := filepath.Join(getCurrentDirectory(), "key.pem") + if tlsCert, err = tls.LoadX509KeyPair(cert, key); err != nil { glog.V(LWARNING).Infoln(err) tlsCert, err = tls.X509KeyPair([]byte(rawCert), []byte(rawKey))