Exemplo n.º 1
0
//
// GET /get/<key>
// return: get-url
//
func (s *Service) get(w http.ResponseWriter, req *http.Request) {
	query := strings.Split(req.URL.Path[1:], "/")
	if len(query) < 2 {
		w.WriteHeader(http.StatusMethodNotAllowed)
		return
	}
	key := query[1]
	log.Println("get: key:", key)

	isExist := s.stg.Check(key)
	if !isExist {
		log.Println("get: do not exist")
		w.WriteHeader(404)
		return
	}

	kh := keystore.KeyStore{
		Key:    key,
		Expire: time.Now().Unix() + s.urlExpireTime,
	}
	encodedKeyHandle := keystore.Encode(kh)
	url := s.myhost + "/file/" + encodedKeyHandle
	w.Header().Set("Content-Length", strconv.Itoa(len(url)))
	w.WriteHeader(200)
	io.WriteString(w, url)
}
Exemplo n.º 2
0
//
// GET /put-auth
// return: put-url
//
func (s *Service) putAuth(w http.ResponseWriter, req *http.Request) {
	key := generateKey()
	log.Println("putAuth: key:", key)

	kh := keystore.KeyStore{
		Key:    key,
		Expire: time.Now().Unix() + s.urlExpireTime,
	}
	encodedKeyHandle := keystore.Encode(kh)
	url := s.myhost + "/upload/" + encodedKeyHandle
	w.Header().Set("Content-Length", strconv.Itoa(len(url)))
	w.WriteHeader(200)
	io.WriteString(w, url)
}