google app engine - martini & appengine/golang, return memcached JSON data -


Now I'm coding with Martini and Appenne / Go.

I want to use memcache for JSON service information. But the response is invalid JSON format. Why "tap" in the answer?

  null {"results": [{"title": "nicki 225", "price time": "2014-" "," value ":" 14,429.26 "," different ": "¼ 24. 27 (0.1%)"}, {"Title": "USD / JPY", "Price Time": "2014-04-25 20:49:00 UTC", "Price": "102.12- 102.16 "," Diff ":" ¼? 0.15 (-0.1%) "}, {" title ":" Euro / JPY "," Price time ":" 2014-04-25 20:49:00 UTC "," value ":" 141.28-141.32 "," Diff ":" I? 0.19 (-0.1%) "}, {" Title ":" Euro / USD "," Price Time ":" 2014-04-25 20:48:00 UTC "," Value ":" 1.3833-1.3836 " "Diff": "I ¼ 0.0002 (0.0%)"}, {"Title": "USD / CNY", "Value Time": "2014-04-25 20:48:00 UTC", "Price": " 6.2536-6.2546 "," Diff ":" ¼ ?? 0.0063 (0.1%) "}, {title}:" DJIA "," Price time ":" 2014-04-25 07:29:00 UTC "," Price ":" 16,361.46 "," Diff ":" I ¼ ?? 140.19 (-0.8%) "}, {title}:" Nasdaq "," Price time ":" 2014-04-25 07:00:00 UTC "," Price ":" 4,075.561 "," Diff ":" ¼ "72.777 (-1.7%)"}, {"Title": "FTSE 100", "Pricing Time": "2014-04-25 07:35:00 UTC", "Price": "6,685.69", "Diff" : "¼ ?? 17.31 (-0.2%)"}]}   

And the console says like the following:

  http: multiple responses Writing call   

My code is similar to the one below.
Recover from the cache:

  c: = appengine.NewContext (request) memcacheKey: = "market" results: = [] results {} cachedItem, getCacheErr: = memcache.JSON. Get (c, memcacheKey, & map [string] interface {} {"result": result}) if you meet! = Nil & amp; Amp; ! GetCacheErr = memcache.ErrCacheMiss {c.Infof ("get cache error")} if getCacheErr == zero {c.Infof ("cached data not found") c.Infof ("Cached data:% V", cachedItem.Value )   

Set to memcache:

  RJSON (200, cached item object)} and {c. Info ("Cached data not found")}   

Customer: urlfetch.Client (c) resp, err: = client.get ("http://www.nikkei.com/ Markets / kaigai / worldidx.aspx ") If mistake! = Zero {http.Error (w, err.Error (), http.StatusInternalServerError)} indexed: = index (), document _:. = Goquery.NewDocumentFromResponse (resp) doc.Find ("div.mk-world_market div table TR") each (function (_ integer (title, "one ??" »," ", - 1)," s "," ") If Val, ok: = indexed [title]; ok {value: = s.Find (" th ") Next () .text (diff: = s.Find (" td: nth-child (3 ) ". Text.) Pricetime: = s.Find (" td: nth-child (4) "). Text () t: = time.Now () pricetime = StringToTime (pricetime, t) result: = results { Val, pricetime, price, diff} result = sum (result S, result)}}} item: = & amp; memcache.Item {key: memcacheKey, object: & map [string] interface {} {"result" : Result},} setErr: = memcache.JSON.Set (c, Item) if setErr! = Nil {c.infof ("set error:% v", setErr)}

What's wrong with my code? < P>

Self-resolution:

What I have to do is down.

  m Get result result: "Get" ("API / market", function (w http.ResponseWriter, r.render.Render, request * http.Request) {c: = appengine.NewContext (request) memcache_key: = "market" var item_list [] = [] Result {} _, get_cache_err: = memcache.JSON.Get (c, memcache_key, and item_list) if get_cache_err! = Nil & amp; Get_cache_err = memcache.ErrCacheMiss {c.Infof ("get cache error")} if get_cache_err == zero {c.Infof ("cached data not found") c.Infof ("Cached Data:% V", item_list)! Results = Item_list} else {c.Infof ("Cached data not found") Customers: urlfetch.Client (c) resp, err: = client.Get ("http://www.nikkei.com/markets/kaigai/ Worldidx .aspx ") if mistake = zero {http.Error (err.Error (W), http.StatusInternalServerError)} indexed: = index (), document _: = goquery.NewDocumentFromResponse (resp) doc.Find (" Div.mk-world_market div table tr "). Each (func (_ int, s * goquery.Selection) {title: = s.Find ("th"). Text () title = wired trident (wire "left": "value" = s.Find (" Th "). Text () diff: = S.Find (" td: nth-child (3) "). Text () pricetime: = s.Find (" td: nth-child (4) " Results: = {{results}} =} () result = result (result, result)}}}}}} =} item = = & Amp; memcache.Item {key: Setc = map [string] interface {} {"result": item_list})})    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -