本文整理匯總了Golang中github.com/pierrre/imageserver.Image類的典型用法代碼示例。如果您正苦於以下問題:Golang Image類的具體用法?Golang Image怎麽用?Golang Image使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Image類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Set
// Set implements Cache.
func (cache *Cache) Set(key string, im *imageserver.Image, params imageserver.Params) error {
data, err := im.MarshalBinary()
if err != nil {
return err
}
return cache.setData(key, data)
}
示例2: parseResponse
func parseResponse(response *http.Response) (*imageserver.Image, error) {
if response.StatusCode != http.StatusOK {
return nil, &imageserver.ParamError{
Param: imageserver.SourceParam,
Message: fmt.Sprintf("http status code %d while downloading", response.StatusCode),
}
}
im := new(imageserver.Image)
contentType := response.Header.Get("Content-Type")
if contentType != "" {
matches := contentTypeRegexp.FindStringSubmatch(contentType)
if matches != nil && len(matches) == 2 {
im.Format = matches[1]
}
}
data, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, &imageserver.ParamError{
Param: imageserver.SourceParam,
Message: fmt.Sprintf("error while downloading: %s", err),
}
}
im.Data = data
return im, nil
}
示例3: Get
// Get implements Cache.
func (cache *Cache) Get(key string, params imageserver.Params) (*imageserver.Image, error) {
data, err := cache.getData(key)
if err != nil {
return nil, err
}
if data == nil {
return nil, nil
}
im := new(imageserver.Image)
err = im.UnmarshalBinaryNoCopy(data)
if err != nil {
return nil, err
}
return im, nil
}
示例4: Get
// Get implements Server.
func (srv *Server) Get(params imageserver.Params) (*imageserver.Image, error) {
ctx := &Context{
Params: params,
}
key := srv.KeyGenerator.GetKey(params)
var data []byte
dest := groupcache.AllocatingByteSliceSink(&data)
err := srv.Group.Get(ctx, key, dest)
if err != nil {
return nil, err
}
im := new(imageserver.Image)
err = im.UnmarshalBinaryNoCopy(data)
if err != nil {
return nil, err
}
return im, nil
}
示例5: TestGetter
func TestGetter(t *testing.T) {
ctx := &Context{
Params: imageserver.Params{},
}
var data []byte
dest := groupcache.AllocatingByteSliceSink(&data)
gt := &Getter{
Server: &imageserver.StaticServer{
Image: testdata.Medium,
},
}
err := gt.Get(ctx, "foo", dest)
if err != nil {
t.Fatal(err)
}
im := new(imageserver.Image)
err = im.UnmarshalBinary(data)
if err != nil {
t.Fatal(err)
}
if !imageserver.ImageEqual(im, testdata.Medium) {
t.Fatal("not equal")
}
}