dumb/proxy.go

29 lines
524 B
Go
Raw Normal View History

2022-10-11 13:23:10 +00:00
package main
import (
"fmt"
"io"
"net/http"
"github.com/gorilla/mux"
)
func proxyHandler(w http.ResponseWriter, r *http.Request) {
f := mux.Vars(r)["filename"]
url := fmt.Sprintf("https://images.genius.com/%s.jpg", f)
res, err := http.Get(url)
if err != nil {
2022-10-11 13:25:07 +00:00
write(w, http.StatusInternalServerError, []byte("can't reach genius servers"))
2022-10-11 13:23:10 +00:00
return
}
if res.StatusCode != http.StatusOK {
write(w, res.StatusCode, []byte{})
return
}
w.Header().Add("Content-type", "image/jpeg")
io.Copy(w, res.Body)
}