D
D
di2019-04-08 10:45:04
go
di, 2019-04-08 10:45:04

Why is the go run command not working?

Installed go on Ubuntu 18.
Followed this example
https://tecadmin.net/install-go-on-ubuntu/
Everything seems to be correct. version shows

[email protected]:~/go/example1$ go version
go version go1.12.2 linux/amd64

The environment is set up like this
[email protected]:~/go/example1$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/aa/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/aa/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build932288149=/tmp/go-build -gno-record-gcc-switches"

In the go/example1 folder, the main.go script
package main

import (
  "fmt"
  "net/http"
)

func main() {
  http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello, you've requested: %s\n", r.URL.Path)
  })

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

run in console
[email protected]:~/go/example1$ go run main.go
[email protected]:~/go/example1$

response 0, no errors, nothing on port 80. I don't understand what to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav, 2019-04-08
@Delgus

You need to check the error that ListenAndServe returns, there will be an error that the port could not be taken, since without root rights you cannot listen to ports less than 1024.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question