Exemple #1
0
func printLog(c appengine.Context, v string) {

	if appengine.IsDevAppServer() {
		log.Println(v)
	} else {
		c.Logf("%v", v)
	}

}
Exemple #2
0
func serveError(c appengine.Context, w http.ResponseWriter, err os.Error) {
	w.WriteHeader(http.StatusInternalServerError)
	w.Header().Set("Content-Type", "text/plain")
	io.WriteString(w, "Internal Server Error")
	c.Logf("%v", err)
}
func filterEdges(c appengine.Context, filename string, chrm string, start int, end int, filters []filter) ([]edge, os.Error) {
	out := make([]edge, 0, 2)

	indexname := fmt.Sprintf("%s.index.%s.json", filename, chrm)
	c.Logf("attempting to load %s from m cache", indexname)

	var indexjson []byte
	switch indexitem, err := memcache.Get(c, indexname); {
	case err == memcache.ErrCacheMiss:
		c.Logf("item not in the cache")

		q := datastore.NewQuery("fileNameToKey").Filter("Filename=", indexname)
		blobs := make([]fileNameToKey, 0, 100)
		if _, err := q.GetAll(c, &blobs); err != nil {
			c.Logf("%v", err)

		}
		if len(blobs) == 0 {
			return out, nil
		}

		c.Logf("blobs[0] is %v %v", blobs[0].Filename, blobs[0].BlobKey)
		blobreader := blobstore.NewReader(c, blobs[0].BlobKey)

		c.Logf("reading blob into indexjson")
		c.Logf("indexjson is %v long before", len(indexjson))
		var readerr os.Error
		if indexjson, readerr = ioutil.ReadAll(blobreader); readerr != nil && readerr != os.EOF {

			c.Logf("error loading json from blob: %v", readerr)
			return out, readerr

		}

		item := &memcache.Item{Key: indexname,
			Value: indexjson,
		}

		// Add the item to the memcache, if the key does not already exist
		if err := memcache.Add(c, item); err == memcache.ErrNotStored {
			c.Logf("item with key %q already exists", item.Key)
		} else if err != nil {
			c.Logf("error adding item: %v", err)
		}

	case err != nil:
		c.Logf("error getting item: %v", err)

	case err == nil:
		c.Logf(" indexjson Loaded from memcache.")
		indexjson = indexitem.Value

	}
	c.Logf("indexjson is %v long after", len(indexjson))
	index := make([]edge, 0, 100)
	if err := json.Unmarshal(indexjson, &index); err != nil {
		c.Logf("error parseingjson: %v", err)
		return out, err
	}

	if len(index) > 0 {
		leftbound := bisect_left(index, start, 0, -1)
		rightbound := bisect_right(index, end, 0, -1)
		for i := leftbound; i < rightbound; i++ {
			e := index[i]
			includeme := false
			if len(filters) > 0 {
				for _, filter := range filters {

					switch min, err := strconv.Atof32(filter.Minscore); {
					case err != nil:
						c.Logf("error parseing filter: %v", err)
					case e.Type == filter.Type && e.Score >= min:
						includeme = true
						break
					}
				}
			} else {
				includeme = true
			}

			if includeme {
				out = append(out, e)
			}
		}
	}

	return out, nil
}