packages feed

ngx-export-tools 0.3.0.0 → 0.3.1.0

raw patch · 3 files changed

+61/−57 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Changelog.md view
@@ -1,3 +1,9 @@+### 0.3.1.0++- Names of the storages for custom types now contain the name of the service+  which makes it possible to use the same configuration type in multiple+  services.+ ### 0.3.0.0  - Added readers of custom types consuming the Nginx request pointer at first.
NgxExport/Tools.hs view
@@ -174,6 +174,9 @@ -- import           Data.Aeson -- import           GHC.Generics --+-- showAsLazyByteString :: Show a => a -> L.ByteString+-- showAsLazyByteString = C8L.pack . show+-- -- newtype Conf = Conf Int deriving (Read, Show) -- -- data ConfJSON = ConfJSONCon1 Int@@ -181,29 +184,28 @@ -- instance FromJSON ConfJSON -- -- testReadIntHandler :: ByteString -> L.ByteString--- __/testReadIntHandler/__ = C8L.pack . show .+-- __/testReadIntHandler/__ = showAsLazyByteString . --     (readFromByteString :: ByteString -> Maybe Int) -- 'ngxExportYY' \'testReadIntHandler -- -- testReadConfHandler :: ByteString -> L.ByteString--- __/testReadConfHandler/__ = C8L.pack . show .+-- __/testReadConfHandler/__ = showAsLazyByteString . --     (readFromByteString :: ByteString -> Maybe Conf) -- 'ngxExportYY' \'testReadConfHandler -- -- testReadConfJSONHandler :: ByteString -> IO L.ByteString--- __/testReadConfJSONHandler/__ = return . C8L.pack . show .+-- __/testReadConfJSONHandler/__ = return . showAsLazyByteString . --     (readFromByteStringAsJSON :: ByteString -> Maybe ConfJSON) -- 'ngxExportAsyncIOYY' \'testReadConfJSONHandler -- -- testReadConfWithRPtrHandler :: ByteString -> L.ByteString--- __/testReadConfWithRPtrHandler/__ = C8L.pack . show .+-- __/testReadConfWithRPtrHandler/__ = showAsLazyByteString . --     (readFromByteStringWithRPtr :: ByteString -> (Ptr (), Maybe Conf)) -- 'ngxExportYY' \'testReadConfWithRPtrHandler -- -- testReadConfWithRPtrJSONHandler :: ByteString -> L.ByteString--- __/testReadConfWithRPtrJSONHandler/__ = C8L.pack . show .---     (readFromByteStringWithRPtrAsJSON ::---         ByteString -> (Ptr (), Maybe ConfJSON))+-- __/testReadConfWithRPtrJSONHandler/__ = showAsLazyByteString .+--     (readFromByteStringWithRPtrAsJSON :: ByteString -> (Ptr (), Maybe ConfJSON)) -- 'ngxExportYY' \'testReadConfWithRPtrJSONHandler -- @ --@@ -257,18 +259,12 @@ --                     \'; -- --             echo \"Handler variables:\";---             echo \"  hs_testReadIntHandler:\";---             echo \"    $hs_testReadIntHandler\";---             echo \"  hs_testReadConfHandler:\";---             echo \"    $hs_testReadConfHandler\";---             echo \"  hs_testReadConfJSONHandler:\";---             echo \"    $hs_testReadConfJSONHandler\";---             echo \"  hs_testReadConfJSONHandlerBadInput:\";---             echo \"    $hs_testReadConfJSONHandlerBadInput\";---             echo \"  hs_testReadConfWithRPtrHandler:\";---             echo \"    $hs_testReadConfWithRPtrHandler\";---             echo \"  hs_testReadConfWithRPtrJSONHandler:\";---             echo \"    $hs_testReadConfWithRPtrJSONHandler\";+--             echo \"  hs_testReadIntHandler: $hs_testReadIntHandler\";+--             echo \"  hs_testReadConfHandler: $hs_testReadConfHandler\";+--             echo \"  hs_testReadConfJSONHandler: $hs_testReadConfJSONHandler\";+--             echo \"  hs_testReadConfJSONHandlerBadInput: $hs_testReadConfJSONHandlerBadInput\";+--             echo \"  hs_testReadConfWithRPtrHandler: $hs_testReadConfWithRPtrHandler\";+--             echo \"  hs_testReadConfWithRPtrJSONHandler: $hs_testReadConfWithRPtrJSONHandler\"; --         } --     } -- }@@ -278,18 +274,12 @@ -- -- > $ curl 'http://localhost:8010/' -- > Handler variables:--- >   hs_testReadIntHandler:--- >     Just (-456)--- >   hs_testReadConfHandler:--- >     Just (Conf 21)--- >   hs_testReadConfJSONHandler:--- >     Just ConfJSONCon2--- >   hs_testReadConfJSONHandlerBadInput:--- >     Nothing--- >   hs_testReadConfWithRPtrHandler:--- >     (0x00000000016fc790,Just (Conf 21))--- >   hs_testReadConfWithRPtrJSONHandler:--- >     (0x00000000016fc790,Just (ConfJSONCon1 4))+-- >   hs_testReadIntHandler: Just (-456)+-- >   hs_testReadConfHandler: Just (Conf 21)+-- >   hs_testReadConfJSONHandler: Just ConfJSONCon2+-- >   hs_testReadConfJSONHandlerBadInput: Nothing+-- >   hs_testReadConfWithRPtrHandler: (0x00000000016fc790,Just (Conf 21))+-- >   hs_testReadConfWithRPtrJSONHandler: (0x00000000016fc790,Just (ConfJSONCon1 4))  -- | Reads an object of a custom type deriving 'Read' from a 'ByteString'. --@@ -349,12 +339,14 @@ -- -- module TestTools where --+-- import           NgxExport -- import           NgxExport.Tools -- -- import           Data.ByteString (ByteString) -- import qualified Data.ByteString.Lazy as L -- import qualified Data.ByteString.Lazy.Char8 as C8L -- import           Data.Aeson+-- import           Data.IORef -- import           Control.Monad -- import           GHC.Generics --@@ -363,9 +355,12 @@ -- 'ngxExportSimpleService' \'test $ --     'PersistentService' $ Just $ 'Sec' 10 ----- testRead :: (Read a, Show a) => a -> IO L.ByteString--- testRead = return . C8L.pack . show+-- showAsLazyByteString :: Show a => a -> L.ByteString+-- showAsLazyByteString = C8L.pack . show --+-- testRead :: Show a => a -> IO L.ByteString+-- testRead = return . showAsLazyByteString+-- -- testReadInt :: Int -> Bool -> IO L.ByteString -- __/testReadInt/__ = const . testRead -- 'ngxExportSimpleServiceTyped' \'testReadInt \'\'Int $@@ -378,6 +373,11 @@ -- 'ngxExportSimpleServiceTyped' \'testReadConf \'\'Conf $ --     'PersistentService' $ Just $ 'Sec' 10 --+-- testConfStorage :: ByteString -> IO L.ByteString+-- __/testConfStorage/__ = const $+--     showAsLazyByteString \<$\> readIORef __/storage_Conf_/__testReadConf+-- 'ngxExportIOYY' \'testConfStorage+-- -- data ConfWithDelay = ConfWithDelay { delay :: 'TimeInterval' --                                    , value :: Int --                                    } deriving (Read, Show)@@ -389,30 +389,22 @@ -- 'ngxExportSimpleServiceTyped' \'testReadConfWithDelay \'\'ConfWithDelay $ --     'PersistentService' Nothing ----- testReadJSON :: (FromJSON a, Show a) => a -> IO L.ByteString--- testReadJSON = return . C8L.pack . show--- -- data ConfJSON = ConfJSONCon1 Int --               | ConfJSONCon2 deriving (Generic, Show) -- instance FromJSON ConfJSON -- -- testReadConfJSON :: ConfJSON -> Bool -> IO L.ByteString--- __/testReadConfJSON/__ = const . testReadJSON+-- __/testReadConfJSON/__ = const . testRead -- 'ngxExportSimpleServiceTypedAsJSON' \'testReadConfJSON \'\'ConfJSON --     'SingleShotService' -- @ -- -- Here five simple services of various types are defined: /test/, -- /testReadInt/, /testReadConf/, /testReadConfWithDelay/, and--- /testReadConfJSON/. Service /testReadInt/ is not a good example though.--- The problem is that /typed/ simple services build 'IORef' /storages/ to save--- their configurations for faster access in future iterations. The name of a--- storage consists of the name of its type prefixed with __/storage_/__, which--- means that it's wiser to use custom types or wrappers of well-known types--- (such as /Conf/ and /ConfWithDelay/) in order to avoid exhaustion of--- top-level names. In general, this also means that it's not possible to--- declare in a single Nginx configuration script two or more typed simple--- services with identical names of their configuration types.+-- /testReadConfJSON/. /Typed/ services hold 'IORef' /storages/ to save their+-- configurations for faster access in future iterations. The name of a storage+-- consists of the name of its type and the name of the service connected by an+-- underscore and prefixed as a whole word with __/storage_/__. -- -- As soon as all the services in the example merely echo their configurations -- into their service variables, they must sleep for a while between iterations.@@ -478,12 +470,16 @@ --         access_log   \/tmp\/nginx-test-haskell-access.log; -- --         location \/ {+--             haskell_run __/testConfStorage/__ $hs_testConfStorage \'\';+-- --             echo \"Service variables:\"; --             echo \"  hs_test: $hs_test\"; --             echo \"  hs_testReadInt: $hs_testReadInt\"; --             echo \"  hs_testReadConf: $hs_testReadConf\"; --             echo \"  hs_testReadConfWithDelay: $hs_testReadConfWithDelay\"; --             echo \"  hs_testReadConfJSON: $hs_testReadConfJSON\";+--             echo \"Storages of service variables:\";+--             echo \"  hs_testConfStorage: $hs_testConfStorage\"; --         } --     } -- }@@ -501,6 +497,8 @@ -- >   hs_testReadConf: Conf 20 -- >   hs_testReadConfWithDelay: ConfWithDelay {delay = Sec 10, value = 12} -- >   hs_testReadConfJSON: ConfJSONCon1 56+-- > Storages of service variables:+-- >   hs_testConfStorage: Just (Conf 20)  -- | Defines a sleeping strategy. --@@ -516,20 +514,18 @@ ngxExportSimpleService' f c m = do     confBs <- newName "confBs_"     fstRun <- newName "fstRun_"-    let nameSsf = mkName $ "simpleService_" ++ nameBase f+    let nameF = nameBase f+        nameSsf = mkName $ "simpleService_" ++ nameF         hasConf = isJust c         (sNameC, typeC, isJSON) =             if hasConf                 then let c' = fromJust c                          tName = nameBase $ fst c'-                     in (mkName $ "storage_" ++ tName+                     in (mkName $ "storage_" ++ tName ++ '_' : nameF                         ,conT $ mkName tName                         ,snd c'                         )-                else (mkName "storage_dummy__"-                     ,conT $ mkName "Dummy__"-                     ,False-                     )+                else undefined         initConf =             let eConfBs = varE confBs             in if hasConf@@ -586,7 +582,7 @@                                            |]                                        )                                        []-                                  ]+                                   ]                       ,pragInlD sNameC NoInline FunLike AllPhases                       ]                  else []@@ -617,7 +613,8 @@ -- first argument. For the sake of efficiency, this object gets deserialized -- into a global 'IORef' data storage on the first service run to be further -- accessed directly from this storage. The storage can be accessed from--- elsewhere by name comprised of the name of the custom type prefixed with+-- elsewhere by a name comprised of the name of the custom type and the name of+-- the service connected by an underscore and prefixed as a whole word with -- __/storage_/__. The stored data is wrapped in 'Maybe' container. ngxExportSimpleServiceTyped :: Name         -- ^ Name of the service                             -> Name         -- ^ Name of the custom type@@ -632,7 +629,8 @@ -- first argument. For the sake of efficiency, this object gets deserialized -- into a global 'IORef' data storage on the first service run to be further -- accessed directly from this storage. The storage can be accessed from--- elsewhere by name comprised of the name of the custom type prefixed with+-- elsewhere by a name comprised of the name of the custom type and the name of+-- the service connected by an underscore and prefixed as a whole word with -- __/storage_/__. The stored data is wrapped in 'Maybe' container. ngxExportSimpleServiceTypedAsJSON :: Name         -- ^ Name of the service                                   -> Name         -- ^ Name of the custom type
ngx-export-tools.cabal view
@@ -1,8 +1,8 @@ name:                       ngx-export-tools-version:                    0.3.0.0+version:                    0.3.1.0 synopsis:                   Extra tools for Nginx haskell module description:                Extra tools for-        <http://github.com/lyokha/nginx-haskell-module Nginx haskell module>+        <http://github.com/lyokha/nginx-haskell-module Nginx haskell module>. homepage:                   http://github.com/lyokha/nginx-haskell-module license:                    BSD3 license-file:               LICENSE