Files
goview/_examples/go-chi/main.go
2019-04-16 19:10:06 +08:00

45 lines
915 B
Go

/*
* Copyright 2018 Foolin. All rights reserved.
*
* Use of this source code is governed by a MIT style
* license that can be found in the LICENSE file.
*
*/
package main
import (
"fmt"
"github.com/foolin/goview"
"github.com/go-chi/chi"
"net/http"
)
func main() {
r := chi.NewRouter()
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
err := goview.Render(w, http.StatusOK, "index", goview.M{
"title": "Index title!",
"add": func(a int, b int) int {
return a + b
},
})
if err != nil {
fmt.Fprintf(w, "Render index error: %v!", err)
}
})
r.Get("/page", func(w http.ResponseWriter, r *http.Request) {
err := goview.Render(w, http.StatusOK, "page.html", goview.M{"title": "Page file title!!"})
if err != nil {
fmt.Fprintf(w, "Render page.html error: %v!", err)
}
})
fmt.Println("Listening and serving HTTP on :9090")
http.ListenAndServe(":9090", r)
}