This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
язык_программирования_golang [2023/05/04 09:24] val |
язык_программирования_golang [2023/07/08 13:39] 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.digitalocean.com/community/tutorials/how-to-build-and-install-go-programs|How To Build and Install Go Programs]] | ||
- | * [[https://habr.com/ru/articles/647255/|Рекомендации по работе с Docker для Golang-разработчиков (Multistage Building)]] | ||
* [[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://www.systutorials.com/how-to-get-the-hostname-of-the-node-in-go/|How to get the hostname of the node in Go?]] | ||
<code> | <code> | ||
- | client1:~/gowebd# cat main.go | + | student@client1:~$ sudo apt install golang-go |
+ | |||
+ | student@client1:~$ mkdir gowebd | ||
+ | |||
+ | student@client1:~$ cd ~/gowebd | ||
+ | |||
+ | student@client1:~/gowebd$ cat main.go | ||
</code><code> | </code><code> | ||
package main | package main | ||
Line 20: | Line 26: | ||
func main() { | func main() { | ||
http.HandleFunc("/", HelloServer) | http.HandleFunc("/", HelloServer) | ||
- | fmt.Printf("Starting server at port 8080\n") | + | fmt.Printf("Starting server at port 80\n") |
- | if err := http.ListenAndServe(":8080", nil); err != nil { | + | if err := http.ListenAndServe(":80", nil); err != nil { |
log.Fatal(err) | log.Fatal(err) | ||
} | } | ||
Line 31: | Line 37: | ||
panic(err) | panic(err) | ||
} | } | ||
- | fmt.Fprint(w, "Hello world from " + name + "\n") | + | fmt.Fprint(w, "Hello world from " + name + " ver1.1\n") |
} | } | ||
</code><code> | </code><code> | ||
- | client1:~/gowebd# cat Dockerfile | + | student@client1:~/gowebd$ sudo go run main.go |
- | </code><code> | + | |
- | FROM golang | + | |
- | #FROM golang as builder | + | |
- | WORKDIR /build | + | student@client1:~/gowebd$ go mod init gowebd |
- | COPY main.go . | + | |
- | RUN go mod init gowebd | + | |
- | RUN go build -o /gowebd | + | |
- | #FROM alpine | + | student@client1:~/gowebd$ sudo go build -o /usr/local/sbin/gowebd |
- | #COPY --from=builder /gowebd /gowebd | + | |
- | ENTRYPOINT ["/gowebd"] | + | student@client1:~/gowebd$ sudo /usr/local/sbin/gowebd |
</code> | </code> |