https://linen.dev logo
How to share shuttle Secrets?
# help
l
I want to use shuttle Secrets in arbitrary Workspace crates/files but it seems like I can only access them from the
#[shuttle_service::main]
entry point. This makes me have to pass them around instead of just getting them as-needed (like dotenvy offers). What is the recommended strategy for this? Thanks!
a
Hey there, this isn't really something that's explained explicitly in the docs but Axum works really well with tower-http, so you could use something like an AppState struct to hold your shareable values then bind it to the router (inserting the value as an
Arc
of the value) - you can find more information about this here https://docs.rs/axum/latest/axum/index.html#sharing-state-with-handlers
l
Thanks for the reply! Yeah, that’s my current solution. It’s a different solution than I was hoping for but it works for the time being. Hopefully there’s a way to access the values in an arbitrary manner (or at least that feature is on the roadmap)!
3 Views