Commit f67cdadd authored by ale's avatar ale

golint fixes

parent 5fd13b53
......@@ -14,12 +14,12 @@ import (
)
const (
// Path to the mount configuration in etcd. This should never
// change, upgrades to the configuration format should be
// backwards-compatible.
// MountPrefix stores the path to the mount configuration in
// etcd. This should never change between releases, upgrades
// to the configuration format should be backwards-compatible.
MountPrefix = "/icecast/mounts/"
// Path for the cluster runtime data. Whenever the format of
// Paths for the cluster runtime data. Whenever the format of
// this data changes, the ABIVersion should be increased. A
// rolling restart of the cluster will then seamlessly cause a
// transition to the new consensus (the cluster will be
......@@ -33,13 +33,16 @@ const (
)
var (
// IcecastPort is the port that the Icecast server will listen
// on. Since we fully manage the system-wide Icecast instance,
// there's not much point in making this configurable.
IcecastPort = 8000
ErrIsDirectory = errors.New("key is a directory")
ErrIsFile = errors.New("key is a file")
)
// Encoding parameters used to re-encode a stream.
// EncodingParams used to re-encode a stream.
type EncodingParams struct {
// Path to the source mountpoint.
SourceName string
......@@ -55,7 +58,8 @@ type EncodingParams struct {
Quality float64
}
// NewEncodingParams sets some default values.
// NewEncodingParams creates an EncodingParams object with the right
// default values.
func NewEncodingParams() *EncodingParams {
return &EncodingParams{
SampleRate: 44100,
......@@ -85,6 +89,8 @@ func (p *EncodingParams) String() string {
return strings.Join(out, ", ")
}
// Valid returns true if the EncodingParams seem to make sense. We try
// to be as close to the liquidsoap capabilities as possible.
func (p *EncodingParams) Valid() error {
switch p.Format {
case "mp3", "mp3.cbr", "mp3.abr", "vorbis.cbr", "vorbis.abr":
......@@ -120,7 +126,7 @@ func (p *EncodingParams) Valid() error {
return nil
}
// A mountpoint for a stream.
// Mount stores the configuration for a stream (mount, in Icecast lingo).
type Mount struct {
// Name (path to the mountpoint).
Name string
......@@ -145,6 +151,8 @@ type Mount struct {
Transcoding *EncodingParams
}
// Valid performs a consistency check and returns true if the
// configuration for the stream is correct.
func (m *Mount) Valid() error {
if !strings.HasPrefix(m.Name, "/") {
return errors.New("name does not start with a slash")
......@@ -166,14 +174,18 @@ func (m *Mount) Valid() error {
return nil
}
// Equal returns true if the two mounts have the same configuration.
func (m *Mount) Equal(other *Mount) bool {
return (m.Name == other.Name) && (m.Username == other.Username) && (m.Password == other.Password) && (m.RelayUrl == other.RelayUrl) && (m.Fallback == other.Fallback) && ((m.Transcoding == nil && other.Transcoding == nil) || (m.Transcoding != nil && other.Transcoding != nil && *m.Transcoding == *other.Transcoding))
}
// IsRelay returns true if the stream is configured as a relay of an
// external source.
func (m *Mount) IsRelay() bool {
return m.RelayUrl != ""
}
// HasTranscoder returns true if the stream has transcoding sub-streams.
func (m *Mount) HasTranscoder() bool {
return m.Transcoding != nil
}
......@@ -183,17 +195,22 @@ func mountEtcdPath(mountName string) string {
return MountPrefix + mountName[1:]
}
// Return the Icecast mount path for the given public mount name.
// MountNameToIcecastPath returns the Icecast mount path for the given
// public mount name.
func MountNameToIcecastPath(mountName string) string {
return IcecastMountPrefix + mountName
}
// Return the public mount name from an Icecast mount path.
// IcecastPathToMountName returns the public mount name from an
// Icecast mount path. If 'path' does not start with
// IcecastMountPrefix, it is returned unchanged (though arguably this
// should be an error).
func IcecastPathToMountName(path string) string {
return strings.TrimPrefix(path, IcecastMountPrefix)
}
// Status of a mount on an individual Icecast server.
// IcecastMountStatus has information about a mount on an individual
// Icecast server, as provided by Icecast itself.
type IcecastMountStatus struct {
Name string
Listeners int
......@@ -204,7 +221,8 @@ type IcecastMountStatus struct {
FrameRate float64
}
// Status of a node. This is used to report load and stream status.
// NodeStatus stores runtime information about an autoradio node. This
// is used to report load and stream status.
type NodeStatus struct {
// Short name of this node.
Name string
......@@ -278,6 +296,7 @@ type Client struct {
activeNodesCache *nodesCache
}
// NewClient creates and returns a new Client.
func NewClient(client EtcdClient) *Client {
return &Client{client, newNodesCache()}
}
......@@ -341,15 +360,15 @@ func (r *Client) ListMounts() ([]*Mount, error) {
return result, nil
}
// Location data for the master node. Having the IP address here saves
// another round-trip to etcd to retrieve the node info in the most
// common case.
// MasterNodeInfo stores location data for the master node. Having the
// IP address here saves another round-trip to etcd to retrieve the
// node info in the most common case.
type MasterNodeInfo struct {
Name string
IP []net.IP
}
// GetMasterAddr returns the address of the current master server.
// GetMasterInfo returns the address of the current master server.
func (r *Client) GetMasterInfo() (*MasterNodeInfo, error) {
response, err := r.client.Get(MasterElectionPath, false, false)
if err != nil || response.Node == nil {
......@@ -365,7 +384,6 @@ func (r *Client) GetMasterInfo() (*MasterNodeInfo, error) {
return &m, nil
}
// GetNodes returns the list of active cluster nodes.
func (r *Client) doGetNodes() ([]*NodeStatus, error) {
response, err := r.client.Get(NodePrefix, false, false)
if err != nil || response.Node == nil {
......@@ -384,6 +402,7 @@ func (r *Client) doGetNodes() ([]*NodeStatus, error) {
return result, nil
}
// GetNodes returns the list of active cluster nodes.
func (r *Client) GetNodes() ([]*NodeStatus, error) {
return r.activeNodesCache.Get(r.doGetNodes)
}
......
......@@ -27,7 +27,7 @@ func mustLoadFile(path string) string {
// Resolve a list of etcd host:port specs, returning URLs.
func resolveAll(input []string, proto string) []string {
result := make([]string, 0)
var result []string
for _, hostport := range input {
host, port, err := net.SplitHostPort(hostport)
if err != nil {
......@@ -45,6 +45,8 @@ func resolveAll(input []string, proto string) []string {
return result
}
// NewEtcdClient creates a new etcd client. It uses command-line flags
// to find servers and connection parameters.
func NewEtcdClient(strongReads bool) EtcdClient {
proto := "http"
if *etcdCertFile != "" && *etcdKeyFile != "" {
......@@ -81,8 +83,8 @@ func NewEtcdClient(strongReads bool) EtcdClient {
return c
}
// Etcd client interface. Used to decouple our code from the actual
// etcd API, for testing purposes.
// EtcdClient is the etcd client interface used by autoradio. Used to
// decouple our code from the actual etcd API, for testing purposes.
type EtcdClient interface {
Create(string, string, uint64) (*etcd.Response, error)
CompareAndSwap(string, string, uint64, string, uint64) (*etcd.Response, error)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment