Serving Files Error

package main

import (

func main() {
http.HandleFunc("/", dog)
http.HandleFunc("/toby.jpg", dogPic)
http.ListenAndServe(":8080", nil)

func dog(w http.ResponseWriter, req *http.Request) {

w.Header().Set("Content-Type", "text/html; charset=utf-8")

io.WriteString(w, `<img src="/toby.jpg">`)


func dogPic(w http.ResponseWriter, req *http.Request) {
f, err := os.Open(“toby.jpg”)
if err != nil {
http.Error(w, “file not found”, 404)
defer f.Close()

io.Copy(w, f)



Perhaps get a bit into details what the problem is that you have.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.