コード例 #1
0
ファイル: handler.go プロジェクト: ivan-uskov/meshalka
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
}
コード例 #2
0
ファイル: handler.go プロジェクト: ivan-uskov/meshalka
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())
		}
	})
}