7 stable releases

2.1.0 May 21, 2024
2.0.4 May 28, 2023
2.0.3 Jul 29, 2022
2.0.2 Feb 1, 2022
1.0.1 Nov 30, 2021

#1158 in Procedural macros

Download history 6/week @ 2024-07-22 104/week @ 2024-07-29 21/week @ 2024-08-05 20/week @ 2024-08-12 6/week @ 2024-08-19 39/week @ 2024-08-26 13/week @ 2024-09-02 26/week @ 2024-09-09 25/week @ 2024-09-16 45/week @ 2024-09-23 15/week @ 2024-09-30 18/week @ 2024-10-07 22/week @ 2024-10-14 3/week @ 2024-10-21 5/week @ 2024-10-28 27/week @ 2024-11-04

58 downloads per month
Used in 6 crates (via env-url)

MIT license

9KB
117 lines

ENV Url

License Cargo Documentation

Env-composable service urls complete with key overrides as to facilitate maximum flexibility and to simplify integration with kubernetes.

Env mapping behaviors

ENV
{PREFIX}_URL set service url, disregarding other overrides
{PREFIX}_URL_ENV override {PREFIX}_URL env mapping
{PREFIX}_SCHEME set url scheme component
{PREFIX}_SCHEME_ENV override {PREFIX}_SCHEME env mapping
{PREFIX}_HOST set url host component
{PREFIX}_HOST_ENV override {PREFIX}_HOST env mapping
{PREFIX}_PATH set url path component
{PREFIX}_PATH_ENV override {PREFIX}_PATH env mapping
{PREFIX}_QUERY set url query component
{PREFIX}_QUERY_ENV override {PREFIX}_QUERY env mapping
{PREFIX}_USERINFO set url userinfo component
{PREFIX}_USERINFO_ENV override {PREFIX}_USERINFO env mapping

Example

use env_url::*;

#[derive(EnvURL)]
#[env_url(env_prefix = "REDIS", default = "redis://127.0.0.1:6379")]
pub struct RedisDB;

let service_url = RedisDB::service_url();

Kubernetes usage

As kubernetes can set services to env variables for service discovery, it's very useful to be able to override the env mappings like so

REDIS_HOST_ENV: STAGE_REDIS_MASTER_PORT_6379_TCP_ADDR
REDIS_PORT_ENV: STAGE_REDIS_MASTER_SERVICE_PORT_REDIS

Dependencies

~2.5–3.5MB
~63K SLoC