本文整理匯總了Golang中github.com/golang/groupcache.Sink類的典型用法代碼示例。如果您正苦於以下問題:Golang Sink類的具體用法?Golang Sink怎麽用?Golang Sink使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Sink類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: layerGetter
func layerGetter(ctx groupcache.Context, key string, dest groupcache.Sink) error {
m, err := fromKey(key)
if err != nil {
return err
}
land, err := m.nePolySVG(m.zoom, 0)
if err != nil {
return err
}
lakes, err := m.nePolySVG(m.zoom, 1)
if err != nil {
return err
}
l, err := m.labels()
if err != nil {
return err
}
var b bytes.Buffer
b.WriteString(fmt.Sprintf("<path fill=\"whitesmoke\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke=\"lightslategrey\" d=\"%s\"/>", land))
b.WriteString(fmt.Sprintf("<path fill=\"azure\" stroke-width=\"1\" stroke=\"lightslategrey\" d=\"%s\"/>", lakes))
b.WriteString(labelsToSVG(l))
return dest.SetString(b.String())
}
示例2: Get
// Get implements Getter.
func (gt *Getter) Get(ctx groupcache.Context, key string, dest groupcache.Sink) error {
myctx, ok := ctx.(*Context)
if !ok {
return fmt.Errorf("invalid context type: %T", ctx)
}
if myctx == nil {
return fmt.Errorf("context is nil")
}
if myctx.Params == nil {
return fmt.Errorf("context has nil Params")
}
im, err := gt.Server.Get(myctx.Params)
if err != nil {
return err
}
data, err := im.MarshalBinary()
if err != nil {
return err
}
err = dest.SetBytes(data)
if err != nil {
return err
}
return nil
}
示例3: radosGetter
func radosGetter(ctx groupcache.Context, key string, dest groupcache.Sink) error {
rr := ctx.(*RadosReaderAt)
k := &Key{}
err := k.FromString(key)
if err != nil {
return err
}
buf := chunkPool.Get().([]byte)
defer chunkPool.Put(buf)
readP := buf
readN := 0
off := k.offset
for readN < cap(buf) {
count, err := rr.striper.Read(rr.filename, readP, uint64(off))
if err != nil {
return fmt.Errorf("Timeout or Read Error: %s", err.Error())
}
if count == 0 {
break
}
readN += count
off += int64(count)
readP = buf[count:]
}
return dest.SetBytes(buf[:readN])
}
示例4: Get
func (g widthLimitedImageGetter) Get(ctx groupcache.Context, key string, dest groupcache.Sink) error {
files, ok := ctx.(map[string]string)
if !ok {
return errors.New("Context type wrong. (expecting map[string]string)")
}
filePath, ok := files[key]
if !ok {
return errors.New(fmt.Sprintf("Requested key (%s) does not exist.", key))
}
file, err := os.Open(filePath)
if err != nil {
return err
}
img, _, err := image.Decode(file)
file.Close()
if err != nil {
return err
}
resized := resize.Resize(uint(g), 0, img, resize.NearestNeighbor)
buf := bytes.NewBuffer(nil)
err = jpeg.Encode(buf, resized, nil)
if err != nil {
return err
}
return dest.SetBytes(buf.Bytes())
}
示例5: getter
func getter(ctx groupcache.Context, key string, dest groupcache.Sink) error {
resp, _ := http.Get(key)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
log.Printf("asking for %s from solr\n", key)
dest.SetString(string(body))
return nil
}
示例6: Get
func (g fetcherGetter) Get(_ groupcache.Context, key string, dest groupcache.Sink) error {
q, err := url.ParseQuery(key)
if err != nil {
return err
}
bytes, err := g.Generate(q)
if err != nil {
return err
}
return dest.SetBytes(bytes)
}
示例7: lakeGetter
func lakeGetter(ctx groupcache.Context, key string, dest groupcache.Sink) error {
m, err := fromKey(key)
if err != nil {
return err
}
lakes, err := m.nePolySVG(m.zoom, 1)
if err != nil {
return err
}
return dest.SetString(lakes)
}
示例8: Get
func (g zoomedImageGetter) Get(ctx groupcache.Context, key string, dest groupcache.Sink) error {
bfz := &BuildingFloorZoom{}
if err := json.Unmarshal([]byte(key), bfz); err != nil {
return err
}
floor := g.s.GetBuildingFloor(bfz.Building, bfz.Floor)
var err error
floor.ImageOnce.Do(func() {
var img, origImg draw.Image
floor.ImageWG.Add(1)
defer floor.ImageWG.Done()
origImg, err = floor.LoadImage()
if err != nil {
return
}
img = origImg
if floor.Rotation != 0 {
rotatedWidth, rotatedHeight := newImageDimentions(origImg, floor.Rotation)
img = image.NewNRGBA64(image.Rect(0, 0, rotatedWidth, rotatedHeight))
if err = graphics.Rotate(img, origImg, &graphics.RotateOptions{Angle: floor.Rotation}); err != nil {
return
}
}
floor.RotatedImage = img
})
floor.ImageWG.Wait()
if err != nil {
return err
}
img := floor.RotatedImage
coords := ctx.(*models.Coords)
pixelsPerLongitude := TileSize / coords.DLng()
pixelsPerLatitude := TileSize / coords.DLat()
newWidth := floor.Coords.DLng() * pixelsPerLongitude
newHeight := floor.Coords.DLat() * pixelsPerLatitude
log.Printf("Generating resized image %f %f", newWidth, newHeight)
resizedImg := resize.Resize(uint(newWidth), uint(newHeight), img, resize.NearestNeighbor)
var buf bytes.Buffer
if err := tileEncoder.Encode(&buf, resizedImg); err != nil {
return err
}
return dest.SetBytes(buf.Bytes())
}
示例9: generatorFunc
func generatorFunc(ctx groupcache.Context, key string, sink groupcache.Sink) error {
siteURL := ctx.(string)
icons, err := FetchIcons(siteURL)
if err != nil {
// Don't cache errors
return err
}
res := result{Icons: icons}
if err != nil {
res.Error = err.Error()
}
bytes, err := json.Marshal(res)
if err != nil {
panic(err)
}
sink.SetBytes(bytes)
return nil
}
示例10: layerGetter
func layerGetter(ctx groupcache.Context, key string, dest groupcache.Sink) error {
m, err := fromKey(key)
if err != nil {
return err
}
land, err := m.nePolySVG(m.zoom, 0)
if err != nil {
return err
}
lakes, err := m.nePolySVG(m.zoom, 1)
if err != nil {
return err
}
stdDev := 4
coast := 10
if m.width > 150 {
stdDev = 10
coast = 30
}
l, err := m.labels()
if err != nil {
return err
}
var b bytes.Buffer
b.WriteString(fmt.Sprintf("<defs><filter id=\"f1\"><feGaussianBlur in=\"SourceGraphic\" stdDeviation=\"%d\" /></filter></defs>", stdDev))
b.WriteString(fmt.Sprintf("<path stroke-width=\"%d\" stroke-linejoin=\"round\" filter=\"url(#f1)\" stroke=\"azure\" d=\"%s\"/>", coast, land))
b.WriteString(fmt.Sprintf("<path fill=\"whitesmoke\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke=\"lightslategrey\" d=\"%s\"/>", land))
b.WriteString(fmt.Sprintf("<path fill=\"azure\" stroke-width=\"1\" stroke=\"lightslategrey\" d=\"%s\"/>", lakes))
b.WriteString(labelsToSVG(l))
return dest.SetString(b.String())
}