44
33

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Golang で Let's Encrypt の証明書を発行して使用する

Posted at

Golang で ACME プロトコルがサポートされてたみたいなので試してみた。

Document のとおりなんだけれど、以下のコードだけで証明書を発行してListenまでしてくれる。

golang.org/x/crypto/acme/autocert


package main

import (
        "fmt"
        "log"
        "net/http"

        "golang.org/x/crypto/acme/autocert"
)

func main() {
        mux := http.NewServeMux()
        mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
                fmt.Fprintf(w, "Hello, TLS user! Your config: %+v", r.TLS)
        })
        log.Fatal(http.Serve(autocert.NewListener("www.example.jp"), mux))
}

autocert.Manager{} を使えば、もっと細かく制御できるっぽい。

44
33
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
44
33

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?