Created a config object and the start of the server
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/client/client.go Wed Aug 08 23:02:04 2018 -0500
@@ -0,0 +1,3 @@
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/irc/irc.go Wed Aug 08 23:02:04 2018 -0500
@@ -0,0 +1,13 @@
+ regexNick = regexp.MustCompile(`^[A-Za-z][A-Za-z0-9-[\]\^{}]*`) +func NickValid(nick string) bool { + return regexNick.MatchString(nick) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/irc/irc_test.go Wed Aug 08 23:02:04 2018 -0500
@@ -0,0 +1,29 @@
+ . "github.com/onsi/gomega" +func TestNickValid(t *testing.T) { + tests := map[string]bool{ + for nick, exp := range tests { + g.Expect(NickValid(nick)).To(Equal(exp)) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/server/config.go Wed Aug 08 23:02:04 2018 -0500
@@ -0,0 +1,32 @@
+ "bitbucket.org/rw_grim/gobnc/irc" +// Config handles the configuration data for a server. It may be marshalled to + ListenAddr string `yaml:"listen-addr"` + Nick string `yaml:"nick"` + Password string `yaml:"password"` +func (c *Config) Valid() error { + if c.ListenAddr == "" { + c.ListenAddr = "127.0.0.1" + if c.Port <= 0 || c.Port > 65535 { + return fmt.Errorf("Invalid port %d: must be between 1 and 65535", c.Port) + if !irc.NickValid(c.Nick) { + return fmt.Errorf("Invalid nick '%s'", c.Nick) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/server/config_test.go Wed Aug 08 23:02:04 2018 -0500
@@ -0,0 +1,33 @@
+ . "github.com/onsi/gomega" +func TestConfigValidListenAddr(t *testing.T) { + g.Expect(cfg.Valid()).To(BeNil()) + g.Expect(cfg.ListenAddr).To(Equal("127.0.0.1")) +func TestConfigValidPort(t *testing.T) { + cfg = &Config{Nick: "foo"} + g.Expect(cfg.Valid()).To(MatchError("Invalid port 0: must be between 1 and 65535")) + cfg = &Config{Port: -1, Nick: "foo"} + g.Expect(cfg.Valid()).To(MatchError("Invalid port -1: must be between 1 and 65535")) + cfg = &Config{Port: 65536, Nick: "foo"} + g.Expect(cfg.Valid()).To(MatchError("Invalid port 65536: must be between 1 and 65535")) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/server/server.go Wed Aug 08 23:02:04 2018 -0500
@@ -0,0 +1,7 @@
+func (s *Server) Listen() {