Skip to content

Instantly share code, notes, and snippets.

@pjstadig
pjstadig / storage.clj
Created February 25, 2022 14:17
Protocol + client
(ns stadig.storage
(:refer-clojure :exclude [get])
(:require
[stadig.storage.protocol :as proto]))
(defn get
[conn bucket key]
(when-not bucket
(throw (ex-info "Expected bucket" {:type ::bucket-error})))
(proto/get conn bucket key))
@pjstadig
pjstadig / s3.clj
Created February 25, 2022 14:16
Protocol + client
(ns stadig.storage.s3
(:require
[aws.sdk.s3 :as s3]
[stadig.storage.protocol :as proto]))
(defrecord S3Storage
[access-key secret-key]
proto/IStorage
(get [this bucket key]
(s3/get-object this bucket key))
@pjstadig
pjstadig / protocol.clj
Created February 25, 2022 14:05
Protocol + client
(ns stadig.storage.protocol
(:refer-clojure :exclude [get]))
(defprotocol IStorage
(get [this bucket key])
(put [this bucket key value])
(delete [this bucket key])
(close [this]))
@pjstadig
pjstadig / main.clj
Created February 25, 2022 14:03
Multimethods
(ns stadig.main
(:require
[stadig.storage.methods :as storage]
[stadig.storage.s3 :as s3]))
(defn -main
[& args]
;; ... initialize some things ...
(let [access-key (System/getenv "AWS_ACCESS_KEY_ID")
secret-key (System/getenv "AWS_SECRET_ACCESS_KEY")
@pjstadig
pjstadig / widget.clj
Created February 25, 2022 14:02
Multimethods
(ns stadig.widget
(:require
[stadig.storage.methods :as storage]))
(defn store-widget
[storage-conn widget-name]
(storage/put storage-conn
"widgets"
widget-name
(pr-str {:type :widget :name widget-name})))
@pjstadig
pjstadig / s3.clj
Created February 25, 2022 14:02
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))
@pjstadig
pjstadig / methods.clj
Created February 25, 2022 14:01
Multimethods
(ns stadig.storage.methods
(:refer-clojure :exclude [get]))
(defmulti get :backend)
(defmulti put :backend)
(defmulti delete :backend)
(defmulti close :backend)
@pjstadig
pjstadig / main.clj
Created February 25, 2022 14:01
Plain functions
(ns stadig.main
(:require
[stadig.storage.azure :as storage]))
(defn -main
[& args]
;; ... initialize some things ...
(let [shared-key (System/getenv "AZURE_SHARED_KEY")
storage-conn (storage/connect shared-key)]
(try
@pjstadig
pjstadig / widget.clj
Created February 25, 2022 14:00
Plain functions
(ns stadig.widget
(:require
[stadig.storage.azure :as storage]))
(defn store-widget
[storage-conn widget-name]
(storage/put storage-conn
"widgets"
widget-name
(pr-str {:type :widget :name widget-name})))
@pjstadig
pjstadig / main.clj
Created February 25, 2022 13:59
Plain functions
(ns stadig.main
(:require
[stadig.storage.s3 :as storage]))
(defn -main
[& args]
;; ... initialize some things ...
(let [access-key (System/getenv "AWS_ACCESS_KEY_ID")
secret-key (System/getenv "AWS_SECRET_ACCESS_KEY")
storage-conn (storage/connect access-key secret-key)]