diff --git a/node/doc.go b/node/doc.go index 17645cdd4e10c472798392fa584a0fdaa306145c..d01ccb8927f7122dfe8f29f9b0e64c1225e1abe1 100644 --- a/node/doc.go +++ b/node/doc.go @@ -1,4 +1,6 @@ -// The 'node' supervisor is the daemon that controls the Icecast +// Package node implements the Icecast node supervisor. +// +// The node supervisor is the daemon that controls the Icecast // server, updating its configuration according to what is stored in // the distributed database (etcd). // diff --git a/node/icecast.go b/node/icecast.go index a9c0bc3092d15fb60731cc357ae4ffbf9d74c091..8fe19d8a929c0dd3ffaa26f2cf515e058f9e7d61 100644 --- a/node/icecast.go +++ b/node/icecast.go @@ -47,21 +47,21 @@ type icecastStatusUnparsed struct { Mounts []icecastMountStatusUnparsed `xml:"mount"` } -type IcecastStatus struct { +type icecastStatus struct { Mounts []autoradio.IcecastMountStatus Up bool } type icecastController struct { config *icecastConfig - status *IcecastStatus + status *icecastStatus stop chan bool } -func NewIcecastController(publicIp string, maxClients int) *icecastController { +func newIcecastController(publicIP string, maxClients int) *icecastController { return &icecastController{ - config: newIcecastConfig(publicIp, maxClients), - status: &IcecastStatus{}, + config: newIcecastConfig(publicIP, maxClients), + status: &icecastStatus{}, } } @@ -138,13 +138,13 @@ func (ic *icecastController) Update(conf *clusterConfig, isMaster bool, masterAd return nil } -func (ic *icecastController) GetStatus() *IcecastStatus { +func (ic *icecastController) GetStatus() *icecastStatus { return ic.status } func (ic *icecastController) Run(stop chan bool) { t := time.NewTicker(3 * time.Second) - downStatus := &IcecastStatus{} + downStatus := &icecastStatus{} for { select { case <-t.C: @@ -162,7 +162,7 @@ func (ic *icecastController) Run(stop chan bool) { } } -func (ic *icecastController) fetchStatus() (*IcecastStatus, error) { +func (ic *icecastController) fetchStatus() (*icecastStatus, error) { resp, err := http.Get(fmt.Sprintf("http://localhost:%d%s", autoradio.IcecastPort, statusPage)) if err != nil { return nil, err @@ -171,7 +171,7 @@ func (ic *icecastController) fetchStatus() (*IcecastStatus, error) { return ic.parseStatusPage(resp.Body) } -func (ic *icecastController) parseStatusPage(input io.Reader) (*IcecastStatus, error) { +func (ic *icecastController) parseStatusPage(input io.Reader) (*icecastStatus, error) { var ustatus icecastStatusUnparsed if err := xml.NewDecoder(input).Decode(&ustatus); err != nil { return nil, err @@ -191,7 +191,7 @@ func (ic *icecastController) parseStatusPage(input io.Reader) (*IcecastStatus, e return 0 } - status := IcecastStatus{ + status := icecastStatus{ Up: true, Mounts: make([]autoradio.IcecastMountStatus, 0, len(ustatus.Mounts)), } diff --git a/node/icecast_config.go b/node/icecast_config.go index be8553632c1ecbe656a3ee34eecc5562aa481a71..c080de2dece14de5a9a038c82fd38189f51c5452 100644 --- a/node/icecast_config.go +++ b/node/icecast_config.go @@ -136,7 +136,7 @@ type icecastConfig struct { // to a file for persistence. It is not really meant to be used by the // operator. // -func newIcecastConfig(publicIp string, maxClients int) *icecastConfig { +func newIcecastConfig(publicIP string, maxClients int) *icecastConfig { // We don't use the global source password, but icecast is // happier if it's set, so we just use a random password every // time. @@ -159,7 +159,7 @@ func newIcecastConfig(publicIp string, maxClients int) *icecastConfig { AdminUser: "admin", AdminPassword: adminPw, }, - Hostname: publicIp, + Hostname: publicIP, Fileserve: 1, Paths: icePathsConfig{ Basedir: "/usr/share/icecast2", @@ -270,7 +270,7 @@ func (l mountList) Less(i, j int) bool { // masterelection state. This will clear the Mounts and Relays fields // and set them to new values. The mounts are sorted by name so that // the XML representation generated by Encode() is consistent. -func (ic *icecastConfig) Update(config *clusterConfig, isMaster bool, masterAddr string) { +func (c *icecastConfig) Update(config *clusterConfig, isMaster bool, masterAddr string) { var mounts []iceMountConfig var relays []iceRelayConfig @@ -290,6 +290,6 @@ func (ic *icecastConfig) Update(config *clusterConfig, isMaster bool, masterAddr } } - ic.Mounts = mounts - ic.Relays = relays + c.Mounts = mounts + c.Relays = relays } diff --git a/node/icecast_test.go b/node/icecast_test.go index 983dc507afb86765bcc12b8d7c8cd86f91b8807f..16b87e662ffcb40e3db663254931306aa9d38426 100644 --- a/node/icecast_test.go +++ b/node/icecast_test.go @@ -9,7 +9,7 @@ func TestIcecast_TestParseStatusPage(t *testing.T) { xml := `<?xml version="1.0"?> <status><mount name="/test.ogg"><listeners>3</listeners><bitrate/><quality/><video-quality/><frame-size/><frame-rate/></mount></status>` - ic := NewIcecastController("1.2.3.4", 1000) + ic := newIcecastController("1.2.3.4", 1000) result, err := ic.parseStatusPage(strings.NewReader(xml)) if err != nil { t.Fatal(err) diff --git a/node/node.go b/node/node.go index dfdc0f74f2d41d954165af521e0f8c29844dc14a..4af9f0ef09de67b1b402907892fce6658966bad9 100644 --- a/node/node.go +++ b/node/node.go @@ -134,7 +134,7 @@ func (c *configWatcher) Delete(key string) { // replace real processes with mocks while testing. type controller interface { Update(*clusterConfig, bool, net.IP) error - GetStatus() *IcecastStatus + GetStatus() *icecastStatus Run(chan bool) } @@ -229,7 +229,7 @@ func NewRadioNode(name string, ips []net.IP, netDev string, bwLimit float64, max uint64(*masterElectionTTL), mech), syncer: newConfigWatcher(client, config, upch), - icecast: NewIcecastController(name, maxListeners*2), + icecast: newIcecastController(name, maxListeners*2), transcoderFn: func(p *liquidsoapParams) (transcodingController, error) { return newLiquidsoap(p) }, diff --git a/node/node_test.go b/node/node_test.go index 856e1cc2caa58cfe74308bd8e234a4f11d498f8c..1d91318b771d5b52ddb13eea9f5243637ace1ced 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -30,8 +30,8 @@ func (m *mockController) Update(conf *clusterConfig, isMaster bool, masterAddr n return nil } -func (m *mockController) GetStatus() *IcecastStatus { - return &IcecastStatus{Up: true} +func (m *mockController) GetStatus() *icecastStatus { + return &icecastStatus{Up: true} } type mockTranscoder struct {