1 {-# LANGUAGE DeriveDataTypeable #-}
3 -- | A newtype around a list of Strings which represent the feed
4 -- hosts. This is all to avoid an orphan instance of Configured for
5 -- [String] if we had defined one in e.g. OptionalConfiguration.
7 -- This was placed under the "TSN" namespace because its Default
8 -- instance is specific to TSN, even though otherwise it's just a
14 -- DC is needed only for the DCT.Configured instance of String.
15 import qualified Data.Configurator as DC()
16 import qualified Data.Configurator.Types as DCT (
20 import Data.Data (Data)
21 import System.Console.CmdArgs.Default (Default(..))
22 import Data.Typeable (Typeable)
26 FeedHosts { get_feed_hosts :: [String] }
27 deriving (Data, Show, Typeable)
29 instance Default FeedHosts where
30 -- | The default list of feed hosts. These were found by checking
31 -- PTR records in the neighborhood of the IP address in use. There
32 -- is a feed4.sportsnetwork.com, but it was not operational when
34 def = FeedHosts ["feed1.sportsnetwork.com",
35 "feed2.sportsnetwork.com",
36 "feed3.sportsnetwork.com"]
39 instance DCT.Configured FeedHosts where
40 -- | This allows us to read a FeedHosts object out of a Configurator
41 -- config file. By default Configurator wouldn't know what to do,
42 -- so we have to tell it that we expect a list, and if that list
43 -- has strings in it, we can apply the FeedHosts constructor to
45 convert (DCT.List xs) =
46 -- mapM gives us a Maybe [String] here.
47 fmap FeedHosts (mapM convert_string xs)
49 convert_string :: DCT.Value -> Maybe String
50 convert_string = DCT.convert
52 -- If we read anything other than a list of values out of the file,