-
Notifications
You must be signed in to change notification settings - Fork 0
/
favicon.go
49 lines (42 loc) · 1.26 KB
/
favicon.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package server
import (
_ "embed"
"fmt"
"github.com/cwkr/auth-server/internal/httputil"
"log"
"net/http"
"time"
)
//go:embed assets/favicon.ico
var favicon []byte
//go:embed assets/favicon-16x16.png
var favicon16x16 []byte
//go:embed assets/favicon-32x32.png
var favicon32x32 []byte
func FaviconHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Printf("%s %s", r.Method, r.URL)
w.Header().Set("Content-Type", "image/vnd.microsoft.icon")
w.Header().Set("Content-Length", fmt.Sprint(len(favicon)))
httputil.Cache(w, 120*time.Hour)
w.Write(favicon)
})
}
func Favicon16x16Handler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Printf("%s %s", r.Method, r.URL)
w.Header().Set("Content-Type", "image/png")
w.Header().Set("Content-Length", fmt.Sprint(len(favicon16x16)))
httputil.Cache(w, 120*time.Hour)
w.Write(favicon16x16)
})
}
func Favicon32x32Handler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Printf("%s %s", r.Method, r.URL)
w.Header().Set("Content-Type", "image/png")
w.Header().Set("Content-Length", fmt.Sprint(len(favicon32x32)))
httputil.Cache(w, 120*time.Hour)
w.Write(favicon32x32)
})
}