1

I am doing a simple web server using Go and it will be deployed to AWS using docker. I want to enable HTTPS so I guess I need to read TLS certs from the golang image I am using. Wonder how to check where the certs are in the go image so that I can read them in my code, in a form of something like:

s := http.Server{
        Addr:         443,//fmt.Sprintf(":%s", port),
        ReadTimeout:  5 * time.Second,
        WriteTimeout: 10 * time.Second,
        IdleTimeout:  20 * time.Second,
        Handler:      myHandler,
    }
    log.Println("Go proxy server is running on port:" + port)
    err := s.ListenAndServeTLS("cert.crt", "private-key.key") // read from where?
    if err != nil {
        log.Fatal(err)
    }
Patrick Mevzek
  • 10,995
  • 16
  • 38
  • 54
dragonfly02
  • 3,403
  • 32
  • 55
  • you go code will be compiled into an executable, then that executable will be run from whatever context. The paths you mention will be resolved when your program is run. So they will refer to paths within the filesystem where it is run (e.g: your container if you run your program in a container), if the paths are relative, they will be relative to the "current working directory" at run time (this depends on how you start your program). – LeGEC Mar 13 '23 at 06:57
  • You need to inject the certificates with a Docker mount of some sort. [This answer to "How to use Let's Encrypt with Docker container based on the Node.js image"](https://stackoverflow.com/questions/39846649/how-to-use-lets-encrypt-with-docker-container-based-on-the-node-js-image/40114717#40114717) is very complete and talks about Let's Encrypt, but the part where it launches the Nginx reverse proxy with the certificates injected is the same mechanism you'd need here. – David Maze Mar 13 '23 at 13:02

0 Answers0