Commit 2387bf11 authored by Sushant Mahajan's avatar Sushant Mahajan

added error function

parent 377f8447
...@@ -27,6 +27,10 @@ type ClusterConfig struct { ...@@ -27,6 +27,10 @@ type ClusterConfig struct {
Servers []ServerConfig // All servers in this cluster Servers []ServerConfig // All servers in this cluster
} }
type ErrRedirect int
var cluster_config *ClusterConfig
func NewServerConfig(server_id int) (*ServerConfig, error) { func NewServerConfig(server_id int) (*ServerConfig, error) {
this_server := new(ServerConfig) this_server := new(ServerConfig)
this_server.Id = server_id this_server.Id = server_id
...@@ -37,16 +41,20 @@ func NewServerConfig(server_id int) (*ServerConfig, error) { ...@@ -37,16 +41,20 @@ func NewServerConfig(server_id int) (*ServerConfig, error) {
} }
func NewClusterConfig(num_servers int) (*ClusterConfig, error) { func NewClusterConfig(num_servers int) (*ClusterConfig, error) {
cluster_config := new(ClusterConfig) config := new(ClusterConfig)
cluster_config.Path = "" config.Path = ""
cluster_config.Servers = make([]ServerConfig, num_servers) config.Servers = make([]ServerConfig, num_servers)
for i := 1; i <= num_servers; i++ { for i := 1; i <= num_servers; i++ {
curr_server, _ := NewServerConfig(i) curr_server, _ := NewServerConfig(i)
cluster_config.Servers[i-1] = *(curr_server) config.Servers[i-1] = *(curr_server)
} }
return cluster_config, nil return config, nil
}
func (e ErrRedirect) Error() string {
return "Redirect to server " + strconv.Itoa(cluster_config.Servers[0].Id)
} }
func main() { func main() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment