git.iko.soy/typeable/minio-hs
on master help sign in
Move runResourceT into Minio monad (#50)
commitdca4462879df7b415f25716bcd5444fc5f746403 authorKrishnan Parthasarathi <krisis@users.noreply.github.com> dateSat 15 Jul 2017, 17:07 (9 years ago) parent2e7984b
17 files changed+35−41
README.md+1−1 docs/API.md+12−15 examples/BucketExists.hs+2−2 examples/CopyObject.hs+1−1 examples/FileUploader.hs+1−1 examples/GetObject.hs+1−1 examples/HeadObject.hs+3−3 examples/ListBuckets.hs+2−2 examples/ListIncompleteUploads.hs+1−1 examples/ListObjects.hs+1−1 examples/Makebucket.hs+1−1 examples/PutObject.hs+4−4 examples/RemoveObject.hs+1−1 examples/Removebucket.hs+1−2 src/Network/Minio.hs−2 src/Network/Minio/Data.hs+2−2 test/LiveServer.hs+1−1
README.md+1−1
@@ -91,7 +91,7 @@ main = do
9191 filepath <- execParser cmdParser
9292 let object = pack $ takeBaseName filepath
9393
94− res <- runResourceT $ runMinio minioPlayCI $ do
94+ res <- runMinio minioPlayCI $ do
9595 -- Make a bucket; catch bucket already exists exception if thrown.
9696 catchIf (== BucketAlreadyOwnedByYou) (makeBucket bucket Nothing) ignoreMinioErr
9797
docs/API.md+12−15
@@ -117,7 +117,7 @@ performs connection pooling, bucket location caching (if enabled) and
117117error handling.
118118
119119The `runMinio` function performs the provided action in the `Minio`
120−monad and returns a `ResourceT IO (Either MinioErr a)` value:
120+monad and returns a `IO (Either MinioErr a)` value:
121121
122122``` haskell
123123{-# Language OverloadedStrings #-}
@@ -126,7 +126,7 @@ import Network.Minio
126126
127127main :: IO ()
128128main = do
129− result <- runResourceT $ runMinio def $ do
129+ result <- runMinio def $ do
130130 buckets <- listBuckets
131131 return $ length buckets
132132
@@ -139,9 +139,6 @@ The above performs a `listBuckets` operation and returns the number of
139139buckets in the server. If there were any errors, they will be returned
140140as values of type `MinioErr` as a `Left` value.
141141
142−`runResourceT` takes a value from `ResourceT IO a` to `IO a`. It takes
143−care of running finalizers to free resources.
144−
145142## 2. Bucket operations
146143
147144<a name="listBuckets"></a>
@@ -185,7 +182,7 @@ __Example__
185182
186183main :: IO ()
187184main = do
188− res <- runResourceT $ runMinio minioPlayCI $ do
185+ res <- runMinio minioPlayCI $ do
189186 makeBucket bucketName (Just "us-east-1")
190187
191188 case res of
@@ -216,7 +213,7 @@ __Example__
216213
217214main :: IO ()
218215main = do
219− res <- runResourceT $ runMinio minioPlayCI $ do
216+ res <- runMinio minioPlayCI $ do
220217 removeBucket "mybucket"
221218
222219 case res of
@@ -272,7 +269,7 @@ main = do
272269
273270 -- Performs a recursive listing of all objects under bucket "test"
274271 -- on play.minio.io.
275− res <- runResourceT $ runMinio minioPlayCI $ do
272+ res <- runMinio minioPlayCI $ do
276273 listObjects bucket Nothing True $$ sinkList
277274 print res
278275
@@ -323,7 +320,7 @@ main = do
323320
324321 -- Performs a recursive listing of all incompletely uploaded objects
325322 -- under bucket "test" on play.minio.io.
326− res <- runResourceT $ runMinio minioPlayCI $ do
323+ res <- runMinio minioPlayCI $ do
327324 listIncompleteUploads bucket Nothing True $$ sinkList
328325 print res
329326
@@ -372,7 +369,7 @@ main = do
372369
373370 -- Lists the parts in an incompletely uploaded object identified by
374371 -- bucket, object and upload ID.
375− res <- runResourceT $ runMinio minioPlayCI $ do
372+ res <- runMinio minioPlayCI $ do
376373 source <- getObject bucket object
377374 source $$+- sinkLbs
378375
@@ -413,7 +410,7 @@ main = do
413410 object = "myobject"
414411 kb15 = 15 * 1024
415412
416− res <- runResourceT $ runMinio minioPlayCI $ do
413+ res <- runMinio minioPlayCI $ do
417414 putObject bucket object (CC.repeat "a") (Just kb15)
418415
419416 case res of
@@ -459,7 +456,7 @@ main = do
459456 object = "my-object"
460457 localFile = "/etc/lsb-release"
461458
462− res <- runResourceT $ runMinio minioPlayCI $ do
459+ res <- runMinio minioPlayCI $ do
463460 src <- fGetObject bucket object localFile
464461 (src $$+- sinkLbs)
465462
@@ -497,7 +494,7 @@ main = do
497494 object = "myobject"
498495 localFile = "/etc/lsb-release"
499496
500− res <- runResourceT $ runMinio minioPlayCI $ do
497+ res <- runMinio minioPlayCI $ do
501498 fPutObject bucket object localFile
502499
503500 case res of
@@ -545,7 +542,7 @@ main = do
545542 object = "myobject"
546543 srcObject = "/mybucket/srcObject"
547544
548− res <- runResourceT $ runMinio minioPlayCI $ do
545+ res <- runMinio minioPlayCI $ do
549546 copyObject bucket object def { cpSource = srcObject }
550547
551548 case res of
@@ -579,7 +576,7 @@ main = do
579576 bucket = "mybucket"
580577 object = "myobject"
581578
582− res <- runResourceT $ runMinio minioPlayCI $ do
579+ res <- runMinio minioPlayCI $ do
583580 removeObject bucket object
584581
585582 case res of
examples/BucketExists.hs+2−2
@@ -34,10 +34,10 @@ main :: IO ()
3434main = do
3535 let bucket = "missingbucket"
3636
37− res1 <- runResourceT $ runMinio minioPlayCI $ do
37+ res1 <- runMinio minioPlayCI $ do
3838 foundBucket <- bucketExists bucket
3939 liftIO $ putStrLn $ "Does " ++ show bucket ++ " exist? - " ++ show foundBucket
4040
4141 case res1 of
42− Left e -> putStrLn $ "bucketExists failed." ++ (show e)
42+ Left e -> putStrLn $ "bucketExists failed." ++ show e
4343 Right () -> return ()
examples/CopyObject.hs+1−1
@@ -42,7 +42,7 @@ main = do
4242 objectCopy = "obj-copy"
4343 localFile = "/etc/lsb-release"
4444
45− res1 <- runResourceT $ runMinio minioPlayCI $ do
45+ res1 <- runMinio minioPlayCI $ do
4646 -- 1. Make a bucket; Catch BucketAlreadyOwnedByYou exception.
4747 catchIf (== BucketAlreadyOwnedByYou) (makeBucket bucket Nothing) ignoreMinioErr
4848
examples/FileUploader.hs+1−1
@@ -61,7 +61,7 @@ main = do
6161 filepath <- execParser cmdParser
6262 let object = pack $ takeBaseName filepath
6363
64− res <- runResourceT $ runMinio minioPlayCI $ do
64+ res <- runMinio minioPlayCI $ do
6565 -- Make a bucket; catch bucket already exists exception if thrown.
6666 catchIf (== BucketAlreadyOwnedByYou) (makeBucket bucket Nothing) ignoreMinioErr
6767
examples/GetObject.hs+1−1
@@ -36,7 +36,7 @@ main = do
3636 let
3737 bucket = "my-bucket"
3838 object = "my-object"
39− res <- runResourceT $ runMinio minioPlayCI $ do
39+ res <- runMinio minioPlayCI $ do
4040 src <- getObject bucket object
4141 (src $$+- sinkLbs)
4242
examples/HeadObject.hs+3−3
@@ -35,9 +35,9 @@ main = do
3535 let
3636 bucket = "test"
3737 object = "passwd"
38− res <- runResourceT $ runMinio minioPlayCI $ do
38+ res <- runMinio minioPlayCI $
3939 headObject bucket object
4040
4141 case res of
42− Left e -> putStrLn $ "headObject failed." ++ (show e)
43− Right objInfo -> putStrLn $ "headObject succeeded." ++ (show objInfo)
42+ Left e -> putStrLn $ "headObject failed." ++ show e
43+ Right objInfo -> putStrLn $ "headObject succeeded." ++ show objInfo
examples/ListBuckets.hs+2−2
@@ -34,8 +34,8 @@ import Prelude
3434-- region of the first bucket returned.
3535main :: IO ()
3636main = do
37− firstRegionE <- runResourceT $ runMinio minioPlayCI $ do
37+ firstRegionE <- runMinio minioPlayCI $ do
3838 buckets <- listBuckets
39− liftIO $ print $ "Top 5 buckets: " ++ (show $ take 5 buckets)
39+ liftIO $ print $ "Top 5 buckets: " ++ show (take 5 buckets)
4040 getLocation $ biName $ head buckets
4141 print firstRegionE
examples/ListIncompleteUploads.hs+1−1
@@ -38,7 +38,7 @@ main = do
3838
3939 -- Performs a recursive listing of incomplete uploads under bucket "test"
4040 -- on a local minio server.
41− res <- runResourceT $ runMinio minioPlayCI $ do
41+ res <- runMinio minioPlayCI $
4242 listIncompleteUploads bucket Nothing True $$ sinkList
4343 print res
4444
examples/ListObjects.hs+1−1
@@ -39,7 +39,7 @@ main = do
3939
4040 -- Performs a recursive listing of all objects under bucket "test"
4141 -- on play.minio.io.
42− res <- runResourceT $ runMinio minioPlayCI $ do
42+ res <- runMinio minioPlayCI $
4343 listObjects bucket Nothing True C.$$ CC.sinkList
4444 print res
4545
examples/Makebucket.hs+1−1
@@ -34,7 +34,7 @@ main :: IO ()
3434main = do
3535 let
3636 bucket = "my-bucket"
37− res <- runResourceT $ runMinio minioPlayCI $ do
37+ res <- runMinio minioPlayCI $
3838 -- N B the region provided for makeBucket is optional.
3939 makeBucket bucket (Just "us-east-1")
4040 print res
examples/PutObject.hs+4−4
@@ -39,16 +39,16 @@ main = do
3939 kb15 = 15 * 1024
4040
4141 -- Eg 1. Upload a stream of repeating "a" using putObject.
42− res1 <- runResourceT $ runMinio minioPlayCI $ do
42+ res1 <- runMinio minioPlayCI $
4343 putObject bucket object (CC.repeat "a") (Just kb15)
4444 case res1 of
45− Left e -> putStrLn $ "putObject failed." ++ (show e)
45+ Left e -> putStrLn $ "putObject failed." ++ show e
4646 Right () -> putStrLn "putObject succeeded."
4747
4848
4949 -- Eg 2. Upload a file using fPutObject.
50− res2 <- runResourceT $ runMinio minioPlayCI $ do
50+ res2 <- runMinio minioPlayCI $
5151 fPutObject bucket object localFile
5252 case res2 of
53− Left e -> putStrLn $ "fPutObject failed." ++ (show e)
53+ Left e -> putStrLn $ "fPutObject failed." ++ show e
5454 Right () -> putStrLn "fPutObject succeeded."
examples/RemoveObject.hs+1−1
@@ -28,7 +28,7 @@ main = do
2828 bucket = "mybucket"
2929 object = "myobject"
3030
31− res <- runResourceT $ runMinio minioPlayCI $ do
31+ res <- runMinio minioPlayCI $
3232 removeObject bucket object
3333
3434 case res of
examples/Removebucket.hs+1−2
@@ -34,6 +34,5 @@ main :: IO ()
3434main = do
3535 let
3636 bucket = "my-bucket"
37− res <- runResourceT $ runMinio minioPlayCI $ do
38− removeBucket bucket
37+ res <- runMinio minioPlayCI $ removeBucket bucket
3938 print res
src/Network/Minio.hs−2
@@ -25,7 +25,6 @@ module Network.Minio
2525
2626 , Minio
2727 , runMinio
28− , runResourceT
2928 , def
3029
3130 -- * Error handling
@@ -77,7 +76,6 @@ module Network.Minio
7776This module exports the high-level Minio API for object storage.
7877-}
7978
80−import Control.Monad.Trans.Resource (runResourceT)
8179import qualified Data.Conduit as C
8280import qualified Data.Conduit.Binary as CB
8381import Data.Default (def)
src/Network/Minio/Data.hs+2−2
@@ -342,10 +342,10 @@ connect ci = do
342342 return $ MinioConn ci mgr
343343
344344-- | Run the Minio action and return the result or an error.
345−runMinio :: ConnectInfo -> Minio a -> ResourceT IO (Either MinioErr a)
345+runMinio :: ConnectInfo -> Minio a -> IO (Either MinioErr a)
346346runMinio ci m = do
347347 conn <- liftIO $ connect ci
348− flip evalStateT Map.empty . flip runReaderT conn . unMinio $
348+ runResourceT . flip evalStateT Map.empty . flip runReaderT conn . unMinio $
349349 fmap Right m `MC.catches`
350350 [ MC.Handler handlerServiceErr
351351 , MC.Handler handlerHE
test/LiveServer.hs+1−1
@@ -83,7 +83,7 @@ funTestWithBucket t minioTest = testCaseSteps t $ \step -> do
8383 let b = T.concat [funTestBucketPrefix, T.pack bktSuffix]
8484 liftStep = liftIO . step
8585 connInfo <- maybe minioPlayCI (const def) <$> lookupEnv "MINIO_LOCAL"
86− ret <- runResourceT $ runMinio connInfo $ do
86+ ret <- runMinio connInfo $ do
8787 liftStep $ "Creating bucket for test - " ++ t
8888 foundBucket <- bucketExists b
8989 liftIO $ foundBucket @?= False