|
2 | 2 | // Copyright (c) bfren - licensed under https://mit.bfren.dev/2023
|
3 | 3 |
|
4 | 4 | using System;
|
5 |
| -using System.Collections.Generic; |
6 | 5 | using System.Net.Http;
|
7 | 6 | using Microsoft.Extensions.Logging;
|
8 | 7 | using Microsoft.Extensions.Options;
|
9 | 8 | using Rqlite.Client.Exceptions;
|
| 9 | +using Wrap; |
10 | 10 |
|
11 | 11 | namespace Rqlite.Client;
|
12 | 12 |
|
@@ -58,29 +58,24 @@ public IRqliteClient CreateClient() =>
|
58 | 58 |
|
59 | 59 | /// <inheritdoc/>
|
60 | 60 | public IRqliteClient CreateClient(string httpClientName) =>
|
61 |
| - Options.Clients.GetValueOrDefault(httpClientName) switch |
62 |
| - { |
63 |
| - RqliteOptions.Client client => |
64 |
| - new RqliteClient( |
65 |
| - httpClient: HttpClientFactory.CreateClient(httpClientName), |
66 |
| - includeTimings: client.IncludeTimings ?? Options.IncludeTimings, |
67 |
| - logger: Logger |
68 |
| - ), |
69 |
| - |
70 |
| - _ => |
71 |
| - throw new UnknownClientException($"Client '{httpClientName}' cannot be found in Rqlite settings.") |
72 |
| - }; |
| 61 | + Options.Clients.GetValueOrNone(httpClientName).Match( |
| 62 | + none: () => throw new UnknownClientException($"Client '{httpClientName}' cannot be found in Rqlite settings."), |
| 63 | + some: x => new RqliteClient( |
| 64 | + httpClient: HttpClientFactory.CreateClient(httpClientName), |
| 65 | + includeTimings: x.IncludeTimings ?? Options.IncludeTimings, |
| 66 | + logger: Logger |
| 67 | + ) |
| 68 | + ); |
73 | 69 |
|
74 | 70 | /// <inheritdoc/>
|
75 | 71 | public IRqliteClient CreateClientWithDefaults()
|
76 | 72 | {
|
77 | 73 | // get default options
|
78 | 74 | var options = new RqliteOptions();
|
79 |
| - var clientOptions = new RqliteOptions.Client(); |
80 | 75 |
|
81 | 76 | // create and configure the HttpClient
|
82 | 77 | var httpClient = HttpClientFactory.CreateClient();
|
83 |
| - httpClient.BaseAddress = new(clientOptions.BaseAddress); |
| 78 | + httpClient.BaseAddress = new(options.BaseAddress); |
84 | 79 | httpClient.Timeout = TimeSpan.FromSeconds(options.TimeoutInSeconds);
|
85 | 80 |
|
86 | 81 | // return default RqliteClient
|
|
0 commit comments