summaryrefslogtreecommitdiff
path: root/router.go
blob: c1f5d78d9514da7979c3eb98341ca6dc8d2d5a41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

package main

import (
	"log"
	"net/http"
)

func RunServer(config HttpConfig, db *Database) {

	http.HandleFunc("/", indexMux(db, config.Templates))
	http.HandleFunc("/recipe", recipeMux(db, config.Templates))
	http.HandleFunc("/recipe/edit", recipeEditMux(db, config.Templates))
	http.HandleFunc("/recipe/image", recipeImageMux(config.Storage))
	http.HandleFunc("/add_recipes", addRecipesMux(db, config.Storage, config.Static))
	http.HandleFunc("/static/style.css", staticStyleMux("style.css", config.Static))
	http.HandleFunc("/favicon.ico", faviconMux("favicon.ico", config.Static))

	address := config.Host + ":" + config.Port
	log.Println("Binding to 'http://" + address)
	log.Fatal(http.ListenAndServe(address, nil))
}