Exemple #1
0
func getPageWithArgs(page config.Page, matches []string) config.Page {
	newPage := page.Copy()
	i := 1
	for arg := range page.Args.Con {
		newPage.Args.Con[arg] = matches[i]
		i++
	}

	return newPage
}
Exemple #2
0
func AddHandler(page config.Page, fn config.Handler) {
	http.HandleFunc(page.Path, func(w http.ResponseWriter, r *http.Request) {
		if page.Args.Use {
			fmt.Println(page.Path)
			m := getUrlMatches(page, r.URL.Path)
			if m == nil {
				http.NotFound(w, r)
				return
			}
			fn(w, r, getPageWithArgs(page, m))
		} else {
			fn(w, r, page.Copy())
		}
	})
}