aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFeuerfuchs <git@feuerfuchs.dev>2019-06-17 12:28:31 +0200
committerFeuerfuchs <git@feuerfuchs.dev>2019-06-17 12:28:31 +0200
commit0337f3c56cd075e4f522b58f5dd7880d78938f12 (patch)
treedab762106e3cfe9bf5262382459882ff7bcb738d
parentSlightly larger font size (diff)
downloadgopherproxy-0337f3c56cd075e4f522b58f5dd7880d78938f12.tar.gz
gopherproxy-0337f3c56cd075e4f522b58f5dd7880d78938f12.tar.bz2
gopherproxy-0337f3c56cd075e4f522b58f5dd7880d78938f12.zip
Add Favicon
-rw-r--r--assets/favicon.icobin0 -> 5430 bytes
-rw-r--r--gopherproxy.go18
2 files changed, 18 insertions, 0 deletions
diff --git a/assets/favicon.ico b/assets/favicon.ico
new file mode 100644
index 0000000..b6d0998
--- /dev/null
+++ b/assets/favicon.ico
Binary files differ
diff --git a/gopherproxy.go b/gopherproxy.go
index b65418d..f034cb9 100644
--- a/gopherproxy.go
+++ b/gopherproxy.go
@@ -166,6 +166,18 @@ func RobotsTxtHandler(robotstxtdata []byte) http.HandlerFunc {
166 } 166 }
167} 167}
168 168
169func FaviconHandler(favicondata []byte) http.HandlerFunc {
170 return func(w http.ResponseWriter, req *http.Request) {
171 if favicondata == nil {
172 http.Error(w, "Not Found", http.StatusNotFound)
173 return
174 }
175
176 w.Header().Set("Content-Type", "image/vnd.microsoft.icon")
177 w.Write(favicondata)
178 }
179}
180
169func FontHandler(woff2 bool, fontdata []byte) http.HandlerFunc { 181func FontHandler(woff2 bool, fontdata []byte) http.HandlerFunc {
170 return func(w http.ResponseWriter, req *http.Request) { 182 return func(w http.ResponseWriter, req *http.Request) {
171 if fontdata == nil { 183 if fontdata == nil {
@@ -225,6 +237,11 @@ func ListenAndServe(bind, robotsfile, uri string) error {
225 styletext = "" 237 styletext = ""
226 } 238 }
227 239
240 favicondata, err := box.Find("favicon.ico")
241 if err != nil {
242 favicondata = []byte{}
243 }
244
228 tpldata, err := ioutil.ReadFile(".template") 245 tpldata, err := ioutil.ReadFile(".template")
229 if err == nil { 246 if err == nil {
230 tpltext = string(tpldata) 247 tpltext = string(tpldata)
@@ -246,6 +263,7 @@ func ListenAndServe(bind, robotsfile, uri string) error {
246 263
247 http.HandleFunc("/", GopherHandler(tpl, robotsdata, styletext, uri)) 264 http.HandleFunc("/", GopherHandler(tpl, robotsdata, styletext, uri))
248 http.HandleFunc("/robots.txt", RobotsTxtHandler(robotstxtdata)) 265 http.HandleFunc("/robots.txt", RobotsTxtHandler(robotstxtdata))
266 http.HandleFunc("/favicon.ico", FaviconHandler(favicondata))
249 http.HandleFunc("/iosevka-term-ss03-regular.woff", FontHandler(false, fontdataw)) 267 http.HandleFunc("/iosevka-term-ss03-regular.woff", FontHandler(false, fontdataw))
250 http.HandleFunc("/iosevka-term-ss03-regular.woff2", FontHandler(true, fontdataw2)) 268 http.HandleFunc("/iosevka-term-ss03-regular.woff2", FontHandler(true, fontdataw2))
251 //http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("assets/")))) 269 //http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("assets/"))))