From cfa9172e69b77d7f36c0ea90742803dcac2420d1 Mon Sep 17 00:00:00 2001 From: Mikkel Krautz Date: Fri, 13 May 2011 15:42:06 +0200 Subject: [PATCH] Check for server existance in ctlrpc. --- ctlrpc.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/ctlrpc.go b/ctlrpc.go index 94aafd0..0b930bb 100644 --- a/ctlrpc.go +++ b/ctlrpc.go @@ -13,12 +13,22 @@ type ControlRPC struct { } // Start a server -func (c *ControlRPC) Start(in *int, out *int) os.Error { +func (c *ControlRPC) Start(Id int64, out *int) os.Error { + server, exists := servers[Id] + if !exists { + return os.NewError("no such server") + } + _ = server return nil } // Stop a server -func (c *ControlRPC) Stop(in *int, out *int) os.Error { +func (c *ControlRPC) Stop(Id int64, out *int) os.Error { + server, exists := servers[Id] + if !exists { + return os.NewError("no such server") + } + _ = server return nil } @@ -30,7 +40,11 @@ type ConfigValue struct { // Set a config value func (c *ControlRPC) SetConfig(in *ConfigValue, out *ConfigValue) os.Error { - servers[in.Id].cfg.Set(in.Key, in.Value) + server, exists := servers[in.Id] + if !exists { + return os.NewError("no such server") + } + server.cfg.Set(in.Key, in.Value) out.Id = in.Id out.Key = in.Key out.Value = in.Value @@ -39,8 +53,12 @@ func (c *ControlRPC) SetConfig(in *ConfigValue, out *ConfigValue) os.Error { // Get a config value func (c *ControlRPC) GetConfig(in *ConfigValue, out *ConfigValue) os.Error { + server, exists := servers[in.Id] + if !exists { + return os.NewError("no such server") + } out.Id = in.Id out.Key = in.Key - out.Value = servers[in.Id].cfg.StringValue(in.Key) + out.Value = server.cfg.StringValue(in.Key) return nil }