예제 #1
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()
}
예제 #2
0
// Sets the partitioner and registers the necessary
// controllers
func setupPartitionControllers(man *Manager) {
	manager = man

	//register the controllers.
	cheshire.RegisterApi(ROUTERTABLE_GET, "GET", GetRouterTable)
	cheshire.RegisterApi(ROUTERTABLE_SET, "POST", SetRouterTable)
	cheshire.RegisterApi(PARTITION_LOCK, "POST", Lock)
	cheshire.RegisterApi(PARTITION_UNLOCK, "POST", Unlock)
	cheshire.RegisterApi(CHECKIN, "GET", Checkin)
	cheshire.RegisterApi(DATA_PULL, "GET", DataPull)
}
예제 #3
0
// init function. use for registering controllers
func init() {
	//register the ping controller.
	cheshire.RegisterApi("/ping", "GET", Ping)
	cheshire.RegisterApi("/firehose", "GET", Firehose)
}
예제 #4
0
func init() {
	cheshire.RegisterApi("/api/log", "GET", ConsoleLog)
	cheshire.RegisterApi("/api/service", "GET", ServiceGet)
	cheshire.RegisterApi("/api/shard/new", "PUT", ShardNew)
}