this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

:recycle: parsing providers env

+25 -17
+25 -17
src/rinha_2025.gleam
··· 12 12 import web/server 13 13 import web/web 14 14 15 - pub fn main() -> Nil { 16 - let redis_host = util.get_env_var("REDIS_CONN", "localhost") 17 - let providers_env = util.get_env_var("PROVIDERS", "") 18 - let assert Ok(processor_time) = 19 - util.get_env_var("PROCESSOR_TIME", "100") 20 - |> int.parse 15 + fn get_providers() -> List(provider.ProviderConfig) { 16 + util.get_env_var("PROVIDERS", "") 17 + |> string.split(",") 18 + |> list.filter_map(fn(url) { 19 + use <- bool.guard(when: "" == url, return: Error("invalid")) 21 20 22 - let providers = 23 - providers_env 24 - |> string.split(",") 25 - |> list.filter(fn(url) { "" != url }) 26 - |> list.map(fn(url) { 27 - let provider_name = case string.contains(url, contain: "default") { 28 - True -> "default" 29 - _ -> "fallback" 30 - } 21 + use <- bool.guard( 22 + when: string.contains(url, contain: "default"), 23 + return: Ok(#(url, "default")) 24 + ) 25 + 26 + Ok(#(url, "fallback")) 27 + }) 28 + |> list.map(fn(data) { 29 + let #(url, provider) = data 31 30 provider.ProviderConfig( 32 31 url: url, 33 32 min_response_time: -1, 34 - name: provider_name, 33 + name: provider, 35 34 ) 36 35 }) 37 - let has_providers = list.length(providers) > 0 36 + } 37 + 38 + pub fn main() -> Nil { 39 + let redis_host = util.get_env_var("REDIS_CONN", "localhost") 40 + let assert Ok(processor_time) = 41 + util.get_env_var("PROCESSOR_TIME", "100") 42 + |> int.parse 43 + let providers = get_providers() 44 + 45 + let has_providers = providers != [] 38 46 39 47 let #(valkey_pool_name, valkey_pool) = 40 48 redis.create_supervised_pool(redis_host)