我正在尝试访问 HackerNews API 来练习围棋。
每当我去我的本地主机尝试查看 Firebase 数据库(存储数据的地方)的输出时,我都会遇到一个 Google 帐户身份验证表单。
对此的任何帮助将不胜感激。在我的终端中,我使用 curl 检查是否收到了来自服务器的响应。我收到了 200 OK 的内容响应。
我以为我可能缺少 Firebase 客户端库,但我不确定这是否是现在的问题。
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
response, err := http.Get("https://hacker-news.firebaseio.com/v0/item/8863.json")
if err != nil {
fmt.Printf("The http request failed with the error %s\n", err)
} else {
data, _ := ioutil.ReadAll(response.Body)
fmt.Fprintf(w, string(data))
}
}
func main() {
fmt.Println("Starting the applicaiton")
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
}