Packages

A simple and easy to use API created on top of the Mist web server

Current section

Files

Jump to
howdy src howdy@context@url.erl
Raw

src/howdy@context@url.erl

-module(howdy@context@url).
-compile(no_auto_import).
-export([get_string/2, get_int/2, get_float/2, get_uuid/2]).
-spec get_string(howdy@context:context(), binary()) -> {ok, binary()} |
{error, nil}.
get_string(Context, Key) ->
_pipe = erlang:element(2, Context),
_pipe@1 = gleam@list:find(
_pipe,
fun(Segment) -> has_matching_template_key(Segment, Key) end
),
_pipe@6 = gleam@result:map(
_pipe@1,
fun(Segment@1) ->
_pipe@2 = get_value_from_template_segment(Segment@1),
_pipe@4 = gleam@option:map(
_pipe@2,
fun(Dynamic_value) ->
_pipe@3 = gleam@dynamic:string(Dynamic_value),
gleam@result:replace_error(_pipe@3, nil)
end
),
_pipe@5 = gleam@option:to_result(_pipe@4, nil),
gleam@result:flatten(_pipe@5)
end
),
gleam@result:flatten(_pipe@6).
-spec get_int(howdy@context:context(), binary()) -> {ok, integer()} |
{error, nil}.
get_int(Context, Key) ->
_pipe = erlang:element(2, Context),
_pipe@1 = gleam@list:find(
_pipe,
fun(Segment) -> has_matching_template_key(Segment, Key) end
),
_pipe@6 = gleam@result:map(
_pipe@1,
fun(Segment@1) ->
_pipe@2 = get_value_from_template_segment(Segment@1),
_pipe@4 = gleam@option:map(
_pipe@2,
fun(Dynamic_value) ->
_pipe@3 = gleam@dynamic:int(Dynamic_value),
gleam@result:replace_error(_pipe@3, nil)
end
),
_pipe@5 = gleam@option:to_result(_pipe@4, nil),
gleam@result:flatten(_pipe@5)
end
),
gleam@result:flatten(_pipe@6).
-spec get_float(howdy@context:context(), binary()) -> {ok, float()} |
{error, nil}.
get_float(Context, Key) ->
_pipe = erlang:element(2, Context),
_pipe@1 = gleam@list:find(
_pipe,
fun(Segment) -> has_matching_template_key(Segment, Key) end
),
_pipe@6 = gleam@result:map(
_pipe@1,
fun(Segment@1) ->
_pipe@2 = get_value_from_template_segment(Segment@1),
_pipe@4 = gleam@option:map(
_pipe@2,
fun(Dynamic_value) ->
_pipe@3 = gleam@dynamic:float(Dynamic_value),
gleam@result:replace_error(_pipe@3, nil)
end
),
_pipe@5 = gleam@option:to_result(_pipe@4, nil),
gleam@result:flatten(_pipe@5)
end
),
gleam@result:flatten(_pipe@6).
-spec get_uuid(howdy@context:context(), binary()) -> {ok, howdy@uuid:uuid()} |
{error, nil}.
get_uuid(Context, Key) ->
_pipe = erlang:element(2, Context),
_pipe@1 = gleam@list:find(
_pipe,
fun(Segment) -> has_matching_template_key(Segment, Key) end
),
_pipe@8 = gleam@result:map(
_pipe@1,
fun(Segment@1) ->
_pipe@2 = get_value_from_template_segment(Segment@1),
_pipe@6 = gleam@option:map(
_pipe@2,
fun(Dynamic_value) ->
_pipe@3 = gleam@dynamic:string(Dynamic_value),
_pipe@4 = gleam@result:map(
_pipe@3,
fun(Str) -> howdy@uuid:from_string(Str) end
),
_pipe@5 = gleam@result:replace_error(_pipe@4, nil),
gleam@result:flatten(_pipe@5)
end
),
_pipe@7 = gleam@option:to_result(_pipe@6, nil),
gleam@result:flatten(_pipe@7)
end
),
gleam@result:flatten(_pipe@8).
-spec has_matching_template_key(howdy@url_parser:url_segment(), binary()) -> boolean().
has_matching_template_key(Segment, Key) ->
case Segment of
{matching_template_typed_segment, _@1, _@2, Name, _@3} ->
Name =:= Key;
_@4 ->
false
end.
-spec get_value_from_template_segment(howdy@url_parser:url_segment()) -> gleam@option:option(gleam@dynamic:dynamic()).
get_value_from_template_segment(Segment) ->
case Segment of
{matching_template_typed_segment, _@1, _@2, _@3, Value} ->
{some, Value};
_@4 ->
none
end.