This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
язык_программирования_golang [2023/05/03 12:07] val created |
язык_программирования_golang [2023/10/31 10:08] (current) val |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Язык программирования Golang ====== | ====== Язык программирования Golang ====== | ||
+ | * [[http://golang-book.ru/|Введение в программирование на Go]] | ||
+ | * [[https://www.digitalocean.com/community/tutorials/how-to-build-and-install-go-programs|How To Build and Install Go Programs]] | ||
+ | * [[https://www.systutorials.com/how-to-get-the-hostname-of-the-node-in-go/|How to get the hostname of the node in Go?]] | ||
+ | |||
+ | * [[https://min.io/docs/minio/linux/developers/go/minio-go.html|MinIO Go Client SDK for Amazon S3 Compatible Cloud Storage]] | ||
+ | |||
+ | <code> | ||
+ | student@client1:~$ sudo apt install golang-go | ||
+ | |||
+ | student@client1:~$ mkdir gowebd | ||
+ | |||
+ | student@client1:~$ cd gowebd/ | ||
+ | |||
+ | student@client1:~/gowebd$ cat main.go | ||
+ | </code><code> | ||
+ | package main | ||
+ | |||
+ | import ( | ||
+ | "fmt" | ||
+ | "log" | ||
+ | "net/http" | ||
+ | "os" | ||
+ | ) | ||
+ | |||
+ | const ver = "ver1.1" | ||
+ | |||
+ | func main() { | ||
+ | http.HandleFunc("/", HelloServer) | ||
+ | fmt.Printf("Starting server at port 80\n") | ||
+ | if err := http.ListenAndServe(":80", nil); err != nil { | ||
+ | log.Fatal(err) | ||
+ | } | ||
+ | } | ||
+ | |||
+ | func HelloServer(w http.ResponseWriter, r *http.Request) { | ||
+ | name, err := os.Hostname() | ||
+ | if err != nil { | ||
+ | panic(err) | ||
+ | } | ||
+ | fmt.Fprint(w, "Hello world from " + name + " " + ver + "\n") | ||
+ | } | ||
+ | </code><code> | ||
+ | student@client1:~/gowebd$ sudo go run main.go | ||
+ | |||
+ | student@client1:~/gowebd$ go mod init gowebd | ||
+ | |||
+ | student@client1:~/gowebd$ sudo go build -o /usr/local/sbin/gowebd | ||
+ | |||
+ | student@client1:~/gowebd$ sudo /usr/local/sbin/gowebd | ||
+ | </code> |