K
K
kvaks2020-10-25 20:21:20
go
kvaks, 2020-10-25 20:21:20

Golang script won't run on Raspberry?

Installed on raspberry GO scripts like

package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}

work fine, but the template script with the web server hangs without errors.

package main

import (
  "fmt"
  "log"
  "net/http"
)

func main()  {
  http.HandleFunc("/",page)
  port := ":8080"
  fmt.Println("server start/ port:",port)
  err := http.ListenAndServe(port,nil)
  if err != nil {
    log.Fatal("ListenAndServe",err)
  }
}
func page(w http.ResponseWriter, r *http.Request)  {
  fmt.Println("open Main")
}


PS I run from the console like this "go run server.go"

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question