连接超时访问外部IP Google计算引擎

I'm new in GCP environment and tried to create go running on VM. External IP is 35.247.137.122.

below is the go code, giving response code:200, message: "OK"

package main

import (
    "encoding/json"
    "fmt"
    "net/http"
)

func main() {
    fmt.Println("ready to dig in...")
    http.HandleFunc("/", handle)

    fmt.Println(http.ListenAndServe(":8989", nil))
}

func handle(w http.ResponseWriter, r *http.Request) {
    w.Header().Set("Content-Type", "application/json")

    m, _ := json.Marshal(struct {
        Code    int
        Message string
    }{
        Code:    200,
        Message: "OK",
    })

    w.WriteHeader(http.StatusOK)
    w.Write([]byte(m))
}

When I run the go files, I can get the response from the internal sources here.

For the external test, set the firewall rules herebut I still got the connection time out when access the external Anybody willing to tell me how to resolve the issues Thanks.

nb: I already installed nginx, so access the external IP will result in nginx home, but I tried to access my go code without Proxy Pass from nginx.

What you did is exactly what's needed in order to achieve what you asked for. I've tried reproducing exactly what you've got and I've received a 200 OK from the server on the given port on the external IP.

Probably it was a temporary problem, or maybe there is another firewall rule blocking the one you need. Try lowering the "Priority" number, in order to raise the rule's priority.