pull/6/head
Yax 7 years ago
parent 4ca60c9f7d
commit 4b54b97b16

@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"github.com/patrickmn/go-cache" "github.com/patrickmn/go-cache"
"io/ioutil" "io/ioutil"
"log"
"net/http" "net/http"
"os" "os"
"time" "time"
@ -42,12 +41,13 @@ func commentsCount(w http.ResponseWriter, r *http.Request) {
// get cached value // get cached value
cachedBody, found := countCache.Get(r.URL.String()) cachedBody, found := countCache.Get(r.URL.String())
if found { if found {
//log.Printf("return cached value") //fmt.Printf("return cached value")
w.Write([]byte(cachedBody.(string))) w.Write([]byte(cachedBody.(string)))
return return
} }
// relay request to stacosys // relay request to stacosys
//fmt.Println("QUERY: " + config.Stacosys + r.URL.String())
response, err := http.Get(config.Stacosys + r.URL.String()) response, err := http.Get(config.Stacosys + r.URL.String())
if err != nil { if err != nil {
http.NotFound(w, r) http.NotFound(w, r)
@ -62,7 +62,7 @@ func commentsCount(w http.ResponseWriter, r *http.Request) {
// cache body and return response // cache body and return response
countCache.Set(r.URL.String(), string(body), cache.DefaultExpiration) countCache.Set(r.URL.String(), string(body), cache.DefaultExpiration)
log.Printf(string(body)) fmt.Printf(string(body))
w.Write(body) w.Write(body)
} }
@ -77,10 +77,8 @@ func main() {
if e != nil { if e != nil {
die("File error: %v", e) die("File error: %v", e)
} }
fmt.Printf("config: %s\n", string(file))
config := ConfigType{}
json.Unmarshal(file, &config) json.Unmarshal(file, &config)
fmt.Printf("config: %s\n", string(file))
http.HandleFunc("/comments/count", commentsCount) http.HandleFunc("/comments/count", commentsCount)
http.ListenAndServe(config.HostPort, nil) http.ListenAndServe(config.HostPort, nil)

Loading…
Cancel
Save