项目作者: adrianosela

项目描述 :
A layer of abstraction the around acme/autocert certificate manager (Golang)
高级语言: Go
项目地址: git://github.com/adrianosela/sslmgr.git
创建时间: 2019-04-02T17:35:38Z
项目社区:https://github.com/adrianosela/sslmgr

开源协议:MIT License

下载


Simple Secure Server

Go Report Card
Documentation
GitHub issues
license
Mentioned in Awesome Go

Prerequisites:

  • Your server must be reachable through the provided domain name, this is how LetsEncrypt verifies domain ownership and grants your server a trusted certificate

With Default Values:

  1. ss, err := sslmgr.NewSecureServer(handler, "yourhostname.com")
  2. if err != nil {
  3. log.Fatal(err)
  4. }
  5. ss.ListenAndServe()

Note: This option uses the file system as the certificate cache. If your use case does not have a persistent file system, you should provide a value for CertCache in the ServerConfig as shown below.

With Optional Values:

(Using the certcache library to define a cache)

  1. ss, err := sslmgr.NewServer(sslmgr.ServerConfig{
  2. Hostnames: []string{os.Getenv("CN_FOR_CERTIFICATE")},
  3. HTTPPort: ":80",
  4. HTTPSPort: ":443",
  5. Handler: h,
  6. ServeSSLFunc: func() bool {
  7. return strings.ToLower(os.Getenv("PROD")) == "true"
  8. },
  9. CertCache: certcache.NewLayered(
  10. certcache.NewLogger(),
  11. autocert.DirCache("."),
  12. ),
  13. ReadTimeout: 5 * time.Second,
  14. WriteTimeout: 5 * time.Second,
  15. IdleTimeout: 25 * time.Second,
  16. GracefulnessTimeout: 5 * time.Second,
  17. GracefulShutdownErrHandler: func(e error) {
  18. log.Fatal(e)
  19. },
  20. })
  21. if err != nil {
  22. log.Fatal(err)
  23. }
  24. ss.ListenAndServe()