in This Tutorial you will learn "How To install Go ( golang ) and Set Up a Local Programming Environment with Nginx on Debian 11
Go also known as Golang is an open-source procedural programming developed by Google. Some popular applications that are written in Go are Docker, Kubernetes, Dropbox, Openshift, Netflix, Golang. Golang itself is written in Go.
_________________________________________________________________________________________
lsb_release -d
wget https://golang.org/dl/go1.17.linux-amd64.tar.gz
tar -zxvf go1.17.linux-amd64.tar.gz -C /usr/local/
echo "export PATH=/usr/local/go/bin:${PATH}" | sudo tee /etc/profile.d/go.sh
source /etc/profile.d/go.sh
echo "export PATH=/usr/local/go/bin:${PATH}" | sudo tee -a $HOME/.profile
source $HOME/.profile
go version ; go env
Creating a Simple Program-
mkdir $GOPATH/go-web ; cd $GOPATH/go-web
nano main.go
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World")
})
http.HandleFunc("/greet/", func(w http.ResponseWriter, r *http.Request) {
name := r.URL.Path[len("/greet/"):]
fmt.Fprintf(w, "Hello %s\n", name)
})
http.ListenAndServe(":9990", nil)
}
go build main.go
nano /lib/systemd/system/goweb.service
[Unit]
Description=goweb
[Service]
Type=simple
Restart=always
RestartSec=5s
ExecStart=/go-web/main
[Install]
WantedBy=multi-user.target
systemctl daemon-reload ; systemctl start goweb ; systemctl status goweb
apt install nginx -y
cd /etc/nginx/sites-available
nano yourdomain.com
server {
server_name www.yourdomain.com;
location / {
proxy_pass http://localhost:9990;
}
}
ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/yourdomain.com
nginx -s reload
echo "192.168.1.60 www.yourdomain.com" >> /etc/hosts
www.yourdomain.com
________________________________________________________________________________________
Tuesday, February 1, 2022
How To Install Go ( golang ) and Set Up a Local Programming Environment on Debian 11
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment