20 lines
930 B
C#
20 lines
930 B
C#
namespace Store.Management.Api;
|
|
|
|
public sealed class ApiClientOptions
|
|
{
|
|
public required Uri BaseUrl { get; init; }
|
|
public string Version { get; init; } = "v1";
|
|
public TimeSpan Timeout { get; init; } = TimeSpan.FromSeconds(30);
|
|
|
|
internal void Validate()
|
|
{
|
|
if (BaseUrl is null || !BaseUrl.IsAbsoluteUri ||
|
|
(BaseUrl.Scheme != "https" && BaseUrl.Scheme != "http") ||
|
|
!string.IsNullOrEmpty(BaseUrl.UserInfo) || !string.IsNullOrEmpty(BaseUrl.Query) || !string.IsNullOrEmpty(BaseUrl.Fragment))
|
|
throw new ArgumentException("BaseUrl 必须是无凭据、查询参数和片段的 HTTP(S) 绝对地址。");
|
|
if (!System.Text.RegularExpressions.Regex.IsMatch(Version, @"^v\d+(\.\d+)?$"))
|
|
throw new ArgumentException("Version 格式应为 v1 或 v1.0。");
|
|
if (Timeout <= TimeSpan.Zero) throw new ArgumentOutOfRangeException(nameof(Timeout));
|
|
}
|
|
}
|