Пример #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
func main() {

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

	matcher := router.NewMatcher()
	bootstrap.Conf.Router = matcher

	//now add the services.
	matcher.AddService("http://localhost:8010")

	log.Println("Starting")
	//starts listening on all configured interfaces
	bootstrap.Start()
}
Пример #3
0
func main() {
	flag.Parse()
	bootstrap := cheshire.NewBootstrapFile(*configFilename)

	//Setup our cache.  this uses the local cache
	cache := gocache.New(10, 10)
	bootstrap.AddFilters(cheshire.NewSession(cache, 3600))

	balancer.Servs.DataDir = *dataDir
	balancer.Servs.Load()

	testrt := shards.NewRouterTable("Test")
	balancer.Servs.SetRouterTable(testrt)

	//try creating entry
	entry := &shards.RouterEntry{
		Address:    "localhost",
		JsonPort:   8009,
		HttpPort:   8010,
		Partitions: make([]int, 0),
	}

	log.Println("********************* ADD ENTRY")
	testrt.AddEntries(entry)

	//
	log.Println("Starting")
	// go func() {
	//     c := time.Tick(5 * time.Second)
	//     for now := range c {
	//         str := fmt.Sprintf("%v %s\n", now, "Something something")
	//         balancer.Servs.Logger.Emit("test", str)
	//         balancer.Servs.Logger.Println("TESTING LOG")
	//     }
	// }()

	//starts listening on all configured interfaces
	bootstrap.Start()

}
Пример #4
0
func main() {

	//parse the command line args
	flag.Parse()

	bootstrap := cheshire.NewBootstrapFile(config)

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

	//make sure the linker includes our controllers and runs inits
	//this is mandatory
	controllers.Load()

	//tell everyone we started up
	log.Println("starting app with config=" + config)

	//starts listening on all configured interfaces
	bootstrap.Start()
}