Skip to content

Instantly share code, notes, and snippets.

@anvodev
Created April 5, 2024 05:29
Show Gist options
  • Save anvodev/19c1402b93258bb4272ecf4dd64ba6bc to your computer and use it in GitHub Desktop.
Save anvodev/19c1402b93258bb4272ecf4dd64ba6bc to your computer and use it in GitHub Desktop.
Serving HTTP requests using a Go binary file and Supervisor in Ubuntu
package main
import (
"fmt"
"net/http"
"os"
)
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "8000"
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(fmt.Sprintf("Hello from port %s", port)))
})
fmt.Printf("Listening on :%s\n", port)
http.ListenAndServe(fmt.Sprintf(":%s", port), nil)
}
[program:hello1]
command=/home/ubuntu/hello/hello_bin
directory=/home/ubuntu/hello
user=ubuntu
autostart=true
autorestart=true
stderr_logfile=/var/log/hello1.err.log
stdout_logfile=/var/log/hello1.out.log
[program:hello2]
command=/home/ubuntu/hello/hello_bin
directory=/home/ubuntu/hello
user=ubuntu
autostart=true
autorestart=true
stderr_logfile=/var/log/hello2.err.log
stdout_logfile=/var/log/hello2.out.log
environment=PORT=8001
[group:hello]
programs=hello1,hello2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment