aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/server/handle.go
blob: afe65ce12d23d7d7867d26417e224d8e825d5e58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package server

import (
	"fmt"
	"net/http"

	"github.com/LMBishop/scrapbook/pkg/index"
)

func ServeSite(siteIndex *index.SiteIndex) func(w http.ResponseWriter, r *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		site := siteIndex.GetSiteByHost(r.Host)
		if site == nil {
			w.WriteHeader(http.StatusNotFound)
			fmt.Fprintf(w, "unknown host %s", r.Host)
			return
		}

		site.Handler.ServeHTTP(w, r)
	}
}