Exemplo n.º 1
0
func init() {
	cheshire.RegisterHtml("/", "GET", Index)
	cheshire.RegisterHtml("/new", "POST", NewService)
	cheshire.RegisterHtml("/rt/edit", "GET", Service)
	cheshire.RegisterHtml("/service", "GET", Service2)
	cheshire.RegisterHtml("/log", "GET", Log)
}
Exemplo n.º 2
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	log.Println(cheshire.RandString(32))

	//this one will get executed on every request.
	globalFilter := &DummyFilter{"global"}
	//this one will only get executed on ping requests.
	pingFilter := &DummyFilter{"ping"}

	bootstrap := cheshire.NewBootstrapFile("example_config.yaml")

	//Setup our cache.  this uses the local cache
	//you will need
	//github.com/pmylund/go-cache
	cache := gocache.New(10, 10)
	bootstrap.AddFilters(globalFilter, cheshire.NewSession(cache, 3600))

	//a ping controller api controller.
	pinger := func(txn *cheshire.Txn) {
		// log.Printf("PING! %s", request.Strest.Params)
		response := cheshire.NewResponse(txn)
		response.Put("data", "PONG")
		// log.Printf("Sending REsponse: %s", response.TxnId())
		txn.Write(response)
	}
	//now register the api call
	cheshire.RegisterApi("/ping", "GET", pinger, pingFilter)

	//an example html page
	four04 := func(txn *cheshire.Txn) {
		context := make(map[string]interface{})
		context["message"] = "this is a 404 page"
		cheshire.Render(txn, "/404.html", context)
	}
	cheshire.RegisterHtml("/404", "GET", four04)

	//an example redirect page
	redirect := func(txn *cheshire.Txn) {
		cheshire.Redirect(txn, "/ping")
	}
	cheshire.RegisterHtml("/redirect", "GET", redirect)

	//an example of session usage
	sess := func(txn *cheshire.Txn) {
		log.Println(txn.Session)
		txn.Session.Put("mymessage", "this is my message")
		context := make(map[string]interface{})
		cheshire.Render(txn, "/index.html", context)
	}
	cheshire.RegisterHtml("/", "GET", sess)

	log.Println("Starting")
	//starts listening on all configured interfaces
	bootstrap.Start()
}
Exemplo n.º 3
0
func init() {
	cheshire.RegisterHtml("/", "GET", Index)
}