forked from shiftwinting/FastGithub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
115 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
|
||
namespace FastGithub | ||
{ | ||
class GithubOptions | ||
{ | ||
public Uri MetaUri { get; set; } = new Uri("https://gitee.com/jiulang/fast-github/raw/master/FastGithub/meta.json"); | ||
|
||
public int Concurrent { get; set; } = 50; | ||
|
||
public TimeSpan PortScanTimeout { get; set; } = TimeSpan.FromSeconds(1d); | ||
|
||
public TimeSpan HttpTestTimeout { get; set; } = TimeSpan.FromSeconds(5d); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using System; | ||
using System.Net.Http; | ||
using System.Net.Http.Json; | ||
using System.Threading.Tasks; | ||
|
||
namespace FastGithub | ||
{ | ||
sealed class MetaService | ||
{ | ||
private readonly IHttpClientFactory httpClientFactory; | ||
private readonly IOptionsMonitor<GithubOptions> options; | ||
private readonly ILogger<MetaService> logger; | ||
|
||
public MetaService( | ||
IHttpClientFactory httpClientFactory, | ||
IOptionsMonitor<GithubOptions> options, | ||
ILogger<MetaService> logger) | ||
{ | ||
this.httpClientFactory = httpClientFactory; | ||
this.options = options; | ||
this.logger = logger; | ||
} | ||
|
||
public async Task<Meta?> GetMetaAsync() | ||
{ | ||
try | ||
{ | ||
var httpClient = this.httpClientFactory.CreateClient(); | ||
return await httpClient.GetFromJsonAsync<Meta>(this.options.CurrentValue.MetaUri); | ||
} | ||
catch (Exception ex) | ||
{ | ||
this.logger.LogError(ex, "获取meta.json文件失败"); | ||
return default; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"Github": { | ||
"MetaUri": "https://gitee.com/jiulang/fast-github/raw/master/FastGithub/meta.json", // ip资源文件uri | ||
"Concurrent": 50, // 并发作业数,此项需要重启才生效 | ||
"PortScanTimeout": "00:00:01", // 端口扫描超时时间 | ||
"HttpTestTimeout": "00:00:05" // http测试超时时间 | ||
}, | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"System": "Warning", | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
} | ||
} |