Ngrok 搭配Golang Web 對外開Port
Mar 5, 2023
— — —
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 了 ^^