func (p *Proxy) Handler(w http.ResponseWriter, r *http.Request) {
	if r.Method != "GET" {
		w.WriteHeader(http.StatusMethodNotAllowed)
	}
	elems := strings.Split(r.URL.Path, "/")
	avatarID := elems[len(elems)-1]
	if !reValidAvatarID.MatchString(avatarID) {
		rest.SendErrorJSON(w, r, p.L, http.StatusForbidden, fmt.Errorf("invalid avatar id from %s", r.URL.Path), "can't load avatar")
		return
	}
	etag := `"` + p.Store.ID(avatarID) + `"`
	w.Header().Set("Etag", etag)
	w.Header().Set("Cache-Control", "max-age=604800")  
	if match := r.Header.Get("If-None-Match"); match != "" {
		etag = strings.TrimPrefix(etag, `"`)
		etag = strings.TrimSuffix(etag, `"`)
		if match == etag {
			w.WriteHeader(http.StatusNotModified)
			return
		}
	}
	avReader, size, err := p.Store.Get(avatarID)
	if err != nil {
		rest.SendErrorJSON(w, r, p.L, http.StatusBadRequest, err, "can't load avatar")
		return
	}
	defer func() {
		if e := avReader.Close(); e != nil {
			p.Logf("[WARN] can't close avatar reader for %s, %s", avatarID, e)
		}
	}()
	w.Header().Set("Content-Type", "image/*")
	w.Header().Set("Content-Length", strconv.Itoa(size))
	w.WriteHeader(http.StatusOK)
	if _, err = io.Copy(w, avReader); err != nil {
		p.Logf("[WARN] can't send response to %s, %s", r.RemoteAddr, err)
	}
}
Handler returns token routes for given provider
package avatar
import (
	"bytes"
	"crypto/md5"  
	"encoding/hex"
	"fmt"
	"image"
	"image/png"
	"io"
	"net/http"
	"strconv"
	"strings"
	"time"
	"github.com/go-pkgz/rest"
	"github.com/nullrocks/identicon"
	"github.com/pkg/errors"
	"golang.org/x/image/draw"
	"github.com/go-pkgz/auth/logger"
	"github.com/go-pkgz/auth/token"
)
type Proxy struct {
	logger.L
	Store       Store
	RoutePath   string
	URL         string
	ResizeLimit int
}
func (p *Proxy) Put(u token.User, client *http.Client) (avatarURL string, err error) {
	genIdenticon := func(userID string) (avatarURL string, err error) {
		b, e := GenerateAvatar(userID)
		if e != nil {
			return "", errors.Wrapf(e, "no picture for %s", userID)
		}
		avatarID, e := p.Store.Put(userID, p.resize(bytes.NewBuffer(b), p.ResizeLimit))
		if e != nil {
			return "", err
		}
		p.Logf("[DEBUG] saved identicon avatar to %s, user %q", avatarID, u.Name)
		return p.URL + p.RoutePath + "/" + avatarID, nil
	}
	if u.Picture == "" {
		return genIdenticon(u.ID)
	}
	body, err := p.load(u.Picture, client)
	if err != nil {
		p.Logf("[DEBUG] failed to fetch avatar from the orig %s, %v", u.Picture, err)
		return genIdenticon(u.ID)
	}
	defer func() {
		if e := body.Close(); e != nil {
			p.Logf("[WARN] can't close response body, %s", e)
		}
	}()
	avatarID, err := p.Store.Put(u.ID, p.resize(body, p.ResizeLimit))  
	if err != nil {
		return "", err
	}
	p.Logf("[DEBUG] saved avatar from %s to %s, user %q", u.Picture, avatarID, u.Name)
	return p.URL + p.RoutePath + "/" + avatarID, nil
}
func (p *Proxy) load(url string, client *http.Client) (rc io.ReadCloser, err error) {
	var resp *http.Response
	err = retry(5, time.Second, func() error {
		var e error
		resp, e = client.Get(url)
		return e
	})
	if err != nil {
		return nil, errors.Wrap(err, "failed to fetch avatar from the orig")
	}
	if resp.StatusCode != http.StatusOK {
		_ = resp.Body.Close()  
		return nil, errors.Errorf("failed to get avatar from the orig, status %s", resp.Status)
	}
	return resp.Body, nil
}