Skip to content

Instantly share code, notes, and snippets.

@pjstadig
Created February 25, 2022 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjstadig/7a66cfd553b93661529f1cc6430274e2 to your computer and use it in GitHub Desktop.
Save pjstadig/7a66cfd553b93661529f1cc6430274e2 to your computer and use it in GitHub Desktop.
Multimethods
(ns stadig.storage.s3
(:require
[aws.sdk.s3 :as s3]
[stadig.storage.methods :as methods]))
(defmethod methods/get :s3
[this bucket key]
(when-not bucket
(throw (ex-info "Expected bucket" {:type ::bucket-error})))
(s3/get-object this bucket key))
(defmethod methods/put :s3
[this bucket key value]
(when-not bucket
(throw (ex-info "Expected bucket" {:type ::bucket-error})))
(s3/put-object this bucket key value))
(defmethod methods/delete :s3
[this bucket key]
(when-not bucket
(throw (ex-info "Expected bucket" {:type ::bucket-error})))
(s3/delete-object this bucket key))
(defmethod methods/close :s3
[this])
(defn connect
[access-key secret-key]
{:backend :s3 :access-key access-key :secret-key secret-key})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment