Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "html/template"
- "io"
- "net/http"
- "os"
- )
- var tpl *template.Template
- func init() {
- tpl = template.Must(template.ParseGlob("templates/*.gohtml"))
- }
- func main() {
- http.HandleFunc("/", index)
- http.HandleFunc("/chair.jpeg", chair)
- http.Handle("/favicon.ico", http.NotFoundHandler())
- http.ListenAndServe(":8080", nil)
- }
- func index(res http.ResponseWriter, req *http.Request) {
- tpl.ExecuteTemplate(res, "index.gohtml", nil)
- }
- func chair(res http.ResponseWriter, req *http.Request) {
- f, err := os.Open("chair.jpeg")
- if err != nil {
- http.Error(res, "Image not found", 404)
- return
- }
- defer f.Close()
- io.Copy(res, f)
- }
- =======================================
- <html>
- <body>
- <a href="/chair.jpeg">pic</a>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement