Skip to content
Snippets Groups Projects
Commit 2bea900a authored by ale's avatar ale
Browse files

do not export internal types

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