grim/gobnc

Just cleaning up old incomplete commits
draft
2020-04-27, Gary Kramlich
289b2d7f32b6
Just cleaning up old incomplete commits
package server
import (
"fmt"
"bitbucket.org/rw_grim/gobnc/irc"
)
// Config handles the configuration data for a server. It may be marshalled to
// yaml.
type Config struct {
Addr string `yaml:"addr"`
Port int `yaml:"port"`
Nick irc.Nick `yaml:"nick"`
Password string `yaml:"password"`
}
func (c *Config) Valid() error {
if c.Addr == "" {
c.Addr = "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 !c.Nick.Valid() {
return fmt.Errorf("Invalid nick '%s'", c.Nick)
}
return nil
}
func (c *Config) ListenAddress() string {
return fmt.Sprintf("%s:%d", c.Addr, c.Port)
}