Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/vendor/github.com/anacrolix/missinggo/certdir.go
akuma06 a41f938cec Add Godep support (#758)
As we have seen, dependencies version can prevent the build. We should
user lock versions on dependencies that we know work:
* Packages are vendored
* Add Godep support
* Added addtional install step in readme
* Fix travis build error
2017-05-26 13:07:22 +02:00

46 lignes
909 o
Go

package missinggo
import (
"crypto/tls"
"log"
"os"
"path/filepath"
"strings"
)
func LoadCertificateDir(dir string) (certs []tls.Certificate, err error) {
d, err := os.Open(dir)
if err != nil {
return
}
defer d.Close()
const defaultPEMFile = "default.pem"
if p := filepath.Join(dir, defaultPEMFile); FilePathExists(p) {
cert, err := tls.LoadX509KeyPair(p, p)
if err == nil {
certs = append(certs, cert)
} else {
log.Printf("error loading default certicate: %s", err)
}
}
files, err := d.Readdir(-1)
if err != nil {
return
}
for _, f := range files {
if f.Name() == defaultPEMFile {
continue
}
if !strings.HasSuffix(f.Name(), ".pem") {
continue
}
p := filepath.Join(dir, f.Name())
cert, err := tls.LoadX509KeyPair(p, p)
if err != nil {
log.Printf("error loading key pair from %q: %s", p, err)
continue
}
certs = append(certs, cert)
}
return
}