User Tools

Site Tools


язык_программирования_golang

Язык программирования Golang

Web приложение

student@client1:~$ mkdir gowebd

student@client1:~$ cd gowebd/

student@client1:~/gowebd$ cat main.go
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) {
        hostname, err := os.Hostname()
        if err != nil {
                panic(err)
        }
        fmt.Fprint(w, "Hello world from gowebd on " + hostname + " " + ver + "\n")
}
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

golangci-lint

$ go mod init gowebd

$ docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.62.2 golangci-lint run --timeout=10m

main.go:11:7: const `ver2` is unused (unused)
const ver2 = "ver1.3"
      ^
язык_программирования_golang.txt · Last modified: 2024/12/02 09:30 by val