Created
April 5, 2024 05:29
-
-
Save anvodev/19c1402b93258bb4272ecf4dd64ba6bc to your computer and use it in GitHub Desktop.
Serving HTTP requests using a Go binary file and Supervisor in Ubuntu
This file contains 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 ( | |
"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) | |
} |
This file contains 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
[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 |
This file contains 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
[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