Last active
          September 11, 2020 03:05 
        
      - 
      
- 
        Save clarkezone/0000a9057bd973000057e31f1085ccfc to your computer and use it in GitHub Desktop. 
    Hello World for a SSH using Let's Encrypt in GoLang using nGrok and acme autocert
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package main | |
| import ( | |
| "crypto/tls" | |
| "log" | |
| "net/http" | |
| "fmt" | |
| "golang.org/x/crypto/acme/autocert" | |
| ) | |
| func main() { | |
| http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
| fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:]) | |
| }) | |
| //let's encrypt | |
| certManager := autocert.Manager{ | |
| Prompt: autocert.AcceptTOS, | |
| HostPolicy: autocert.HostWhitelist("example.com"), //Your domain here | |
| Cache: autocert.DirCache("certs"), //Folder for storing certificates | |
| } | |
| server := &http.Server{ | |
| Addr: ":8443", | |
| TLSConfig: &tls.Config{ | |
| GetCertificate: certManager.GetCertificate, | |
| }, | |
| } | |
| go http.ListenAndServe(":8080", certManager.HTTPHandler(nil)) | |
| log.Fatal(server.ListenAndServeTLS("", "")) | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | authtoken: <ngrok_token> | |
| tunnels: | |
| myapp-http: | |
| addr: 8080 | |
| proto: http | |
| hostname: example.com | |
| bind_tls: false | |
| mypp-https: | |
| addr: 8443 | |
| proto: tls | |
| hostname: example.com | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | ngrok start -config=ngrokconfig.yaml --all | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment