From a5e8ffcf3483086de648ecca40956c40507fffc4 Mon Sep 17 00:00:00 2001 From: grj1046 Date: Thu, 1 Apr 2021 13:17:56 +0800 Subject: [PATCH] completed http server --- index.html | 33 ++++++++++++++++++--------------- main.go | 15 ++++++++++----- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/index.html b/index.html index 38387b6..62dc97e 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@
-

LookCos榜单聚合-实时更新

+

LookCos榜单聚合 - 实时更新


@@ -99,23 +99,26 @@
知乎热榜
> \ No newline at end of file diff --git a/main.go b/main.go index 0f2a1f2..07070dc 100644 --- a/main.go +++ b/main.go @@ -234,7 +234,12 @@ func GetHotspot() { /************** Http **************/ func handlerHome(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) + byteHtml, err := ioutil.ReadFile("index.html") + if err != nil { + fmt.Fprintf(w, "get index.html failed. "+err.Error()) + return + } + w.Write(byteHtml) } func handlerHotspot(w http.ResponseWriter, r *http.Request) { @@ -253,10 +258,10 @@ func handlerHotspot(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") jsonEncoder := json.NewEncoder(w) jsonEncoder.SetEscapeHTML(false) - err := jsonEncoder.Encode(result) - if err != nil { - log.Fatal("Encode result failed" + err.Error()) - } + _ = jsonEncoder.Encode(result) + // if err != nil { + // log.Fatal("Encode result failed " + err.Error()) + // } } /************** main func **************/