How to run golang in live Domain name (linux hosting)?

I want to run this Sample code in my linux hosting with domain name www.my-domain.com
the code :-

package main
import (
"fmt"
"net/http"
 )
func main() {
http.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Welcome to my website!")
})

fs := http.FileServer(http.Dir("static/"))
http.Handle("/static/", http.StripPrefix("/static/", fs))

http.ListenAndServe(":80", nil)
}

How to run this code in live website with domain name , So when i press www.my-domain.com it displays “welcome to my website”.
please share how to install or copy and placing Guide with me.

1 Like

Compile and put the binary on your server, start it, connect.

But that’s only sufficient for quick testing.

Personally, I’d put a traefik in front of it, taking care of letsencrypt and reverse proxying to the application.

Also I’d keep both managed by systemd or whatever init system your server uses.

Last but not least, hosting something on a server is a responsible task. Setting up firewall and stuff… You should prefer to find someone who helps you securing the server, if not using a managed service (PaaS).

2 Likes

thanks for information, But truly need a video or full guide…searched in google but no results.

1 Like

If you need a tutorial or guide (written explanation), you in fact need a guide (a person guiding you), or some managed service that does the work for you.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.