_site/cover/msc_uri.COVER.html

1 %% Copyright (c) 2023 Peter Morgan <peter.james.morgan@gmail.com>
2 %%
3 %% Licensed under the Apache License, Version 2.0 (the "License");
4 %% you may not use this file except in compliance with the License.
5 %% You may obtain a copy of the License at
6 %%
7 %% http://www.apache.org/licenses/LICENSE-2.0
8 %%
9 %% Unless required by applicable law or agreed to in writing, software
10 %% distributed under the License is distributed on an "AS IS" BASIS,
11 %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 %% See the License for the specific language governing permissions and
13 %% limitations under the License.
14
15 %% @doc URI handling for the mysql scheme.
16
17 -module(msc_uri).
18
19
20 -export([parse/1]).
21
22
23 parse(URI) when is_list(URI) ->
24 1 ?FUNCTION_NAME(list_to_binary(URI));
25
26 parse(URI) when is_binary(URI) ->
27 4 maps:fold(
28 fun
29 (userinfo, UserInfo, A) ->
30 4 case string:split(UserInfo, ":") of
31 [User, Password] ->
32 4 A#{user => User,
33 password => Password};
34
35 [User] ->
36
:-(
A#{user => User}
37 end;
38
39 (scheme, <<"mysql">>, A) ->
40 4 A;
41
42 (_, <<>>, A) ->
43
:-(
A;
44
45 (path, <<"/", Name/bytes>>, A) ->
46 4 A#{database => Name};
47
48 (K, V, A) ->
49 8 A#{K => V}
50 end,
51 #{},
52 uri_string:parse(URI)).
Line Hits Source