//Main function for Client, if Client is to be run as a Simple Standalone GO application func mainStandAlone() { MyRESTServers = []string{"127.0.0.1:3000", "127.0.0.1:3001", "127.0.0.1:3002"} Ring = consistentHashing.New(MyRESTServers) //Generate seed-data to be distributed across the servers GenerateSeedData() //Distribute keys for key, value := range DataMap { fmt.Println("Distributing/Saving this <key-valye> pair : <", key, "-", value, ">") PutOperation(key, value) } //Try to retrive few keys fmt.Println("Retrieving FEW keys now!") GetOperation("2") GetOperation("4") GetOperation("6") //Try to retrive few keys fmt.Println("Retrieving ALL keys now!") GetAllOperation("127.0.0.1:3000") GetAllOperation("127.0.0.1:3001") GetAllOperation("127.0.0.1:3002") }
//Main Function func main() { fmt.Println("Starting the client") MyRESTServers = []string{"127.0.0.1:3000", "127.0.0.1:3001", "127.0.0.1:3002"} Ring = consistentHashing.New(MyRESTServers) mux := httprouter.New() //handler to service GET ALL request mux.GET("/keys", GetAllKeys) //handler to service GET request mux.GET("/keys/:id", GetKey) //handler to service PUT request mux.PUT("/keys/:id/:value", PutKey) server := http.Server{ Addr: "0.0.0.0:8080", Handler: mux, } server.ListenAndServe() }