-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
34 lines (29 loc) · 756 Bytes
/
Copy pathmain.go
File metadata and controls
34 lines (29 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import (
"fmt"
"io"
"log"
"net/http"
"github.com/gorilla/mux"
)
func handler(w http.ResponseWriter, r *http.Request) {
yavatar := NewYavatar()
img, err := yavatar.GetImg(r)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer img.Body.Close()
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Length", fmt.Sprint(img.ContentLength))
w.Header().Set("Content-Type", img.Header.Get("Content-Type"))
if _, err = io.Copy(w, img.Body); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
func main() {
r := mux.NewRouter()
r.HandleFunc("/{folder}/{key}", handler)
http.Handle("/", r)
log.Fatalln(http.ListenAndServe(":8010", nil))
}