Ngrok 搭配Golang Web 對外開Port

--

— — —

package main

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

func tryHandle(writer http.ResponseWriter, req *http.Request){

writer.WriteHeader(http.StatusOK)
fmt.Print(" hello .\n")
// fmt.Fprintf("hello %s")
fmt.Fprintf(writer,"hello"); // 是個interface 把資料帶到畫面上
}
func main() {
http.HandleFunc("/", tryHandle)
err := http.ListenAndServe(":8080", nil)
// port 號要符合規範
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}

localhost:8080

ngrok http 8080

在itern 提供的網址上 ctrl + 點擊

就可以在外部瀏覽寫好的golang web 了 ^^

--

--

Sunny.Cat :: 😸
Sunny.Cat :: 😸

Written by Sunny.Cat :: 😸

Hi there , My name is Sunny.cat ʕ•̫͡•ʔ I am a Web developer PHP🐘Typescript🐤Golang🐻‍❄️Python🦎

No responses yet