mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 22:06:38 +08:00
后端与全仓代码质量清理(golangci 扩展集 · 测试质量 · 并发安全 · 文档同步)
代码质量全量清理,零行为变化:golangci 扩展集 13 类 linter(gosec/modernize/perfsprint/canonicalheader/usestdlibvars/wastedassign/intrange/errorlint/forcetypeassert/recvcheck/exhaustive/unparam)全量修复,测试代码质量(testifylint/thelper/usetesting)25→0,frpc 进程生命周期真 bug(进程组击杀)、全仓 go test -race 6 类数据竞争(含 1 个生产竞争)、SPDX license 头补齐 131 文件、前端测试套件 next-intl 迁移后 44 失败→全绿、过期 swagger 文档重新生成、pnpm-workspace 构建审批。 Experiments: #2-#17, #18, #20, #21, #23 Metric: total_issues 108 → 8 (-92.6%)
This commit is contained in:
@@ -100,7 +100,7 @@ type Release struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Draft bool `json:"draft"`
|
||||
Prerelease bool `json:"prerelease"`
|
||||
PublishedAt time.Time `json:"published_at,omitempty"`
|
||||
PublishedAt time.Time `json:"published_at,omitzero"`
|
||||
}
|
||||
|
||||
// Asset contains the immutable target metadata returned by a resolve call.
|
||||
@@ -109,7 +109,7 @@ type Asset struct {
|
||||
Name string `json:"asset_name"`
|
||||
State string `json:"state"`
|
||||
Size int64 `json:"size"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitzero"`
|
||||
Digest string `json:"digest,omitempty"`
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ func (client *Client) Resolve(ctx context.Context, request ResolveRequest) (Reso
|
||||
return ResolveResult{}, safeError(
|
||||
errAssetMissing,
|
||||
response.StatusCode,
|
||||
response.Header.Get("X-GitHub-Request-Id"),
|
||||
response.Header.Get("X-Github-Request-Id"),
|
||||
repository,
|
||||
release.Tag,
|
||||
request.AssetName,
|
||||
@@ -379,7 +379,7 @@ func (client *Client) Download(ctx context.Context, request DownloadRequest) (*D
|
||||
|
||||
result, err := client.streamAsset(response.Body, request.MaxBytes, request.Asset.Digest)
|
||||
if err != nil {
|
||||
return nil, safeError(err, response.StatusCode, response.Header.Get("X-GitHub-Request-Id"), repository, "", request.Asset.Name, nil, retryAt)
|
||||
return nil, safeError(err, response.StatusCode, response.Header.Get("X-Github-Request-Id"), repository, "", request.Asset.Name, nil, retryAt)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
@@ -533,7 +533,7 @@ func validTag(tag string) bool {
|
||||
strings.HasPrefix(tag, "/") || strings.HasSuffix(tag, "/") || strings.HasSuffix(tag, ".") {
|
||||
return false
|
||||
}
|
||||
for _, component := range strings.Split(tag, "/") {
|
||||
for component := range strings.SplitSeq(tag, "/") {
|
||||
if component == "" || strings.HasPrefix(component, ".") || strings.HasSuffix(component, ".lock") {
|
||||
return false
|
||||
}
|
||||
@@ -635,10 +635,7 @@ func verifyDeclaredDigest(declaredDigest string, checksum string) error {
|
||||
}
|
||||
|
||||
func safeAssetNames(assets []Asset) []string {
|
||||
count := len(assets)
|
||||
if count > maxAssetErrorNames {
|
||||
count = maxAssetErrorNames
|
||||
}
|
||||
count := min(len(assets), maxAssetErrorNames)
|
||||
names := make([]string, 0, count)
|
||||
for _, asset := range assets[:count] {
|
||||
name := safeText(asset.Name, maxSafeAssetNameLen)
|
||||
@@ -682,7 +679,7 @@ func safeHTTPError(kind error, response *http.Response, repository string, tag s
|
||||
return safeError(
|
||||
kind,
|
||||
response.StatusCode,
|
||||
response.Header.Get("X-GitHub-Request-Id"),
|
||||
response.Header.Get("X-Github-Request-Id"),
|
||||
repository,
|
||||
tag,
|
||||
assetName,
|
||||
|
||||
@@ -148,7 +148,7 @@ func newClient(options clientOptions) *Client {
|
||||
func applyMetadataHeaders(request *http.Request, etag string) {
|
||||
request.Header.Set("Accept", metadataAccept)
|
||||
request.Header.Set("User-Agent", defaultUserAgent)
|
||||
request.Header.Set("X-GitHub-Api-Version", APIVersion)
|
||||
request.Header.Set("X-Github-Api-Version", APIVersion)
|
||||
if etag = safeETag(etag); etag != "" {
|
||||
request.Header.Set("If-None-Match", etag)
|
||||
}
|
||||
@@ -158,7 +158,7 @@ func applyAssetHeaders(request *http.Request) {
|
||||
request.Header.Set("Accept", assetAccept)
|
||||
request.Header.Set("Accept-Encoding", "identity")
|
||||
request.Header.Set("User-Agent", defaultUserAgent)
|
||||
request.Header.Set("X-GitHub-Api-Version", APIVersion)
|
||||
request.Header.Set("X-Github-Api-Version", APIVersion)
|
||||
}
|
||||
|
||||
func stripCrossHostHeaders(request *http.Request) {
|
||||
@@ -300,10 +300,10 @@ func responseRetryAt(response *http.Response, now time.Time) *time.Time {
|
||||
return &retryAt
|
||||
}
|
||||
}
|
||||
if strings.TrimSpace(response.Header.Get("X-RateLimit-Remaining")) != "0" {
|
||||
if strings.TrimSpace(response.Header.Get("X-Ratelimit-Remaining")) != "0" {
|
||||
return nil
|
||||
}
|
||||
reset, err := strconv.ParseInt(strings.TrimSpace(response.Header.Get("X-RateLimit-Reset")), 10, 64)
|
||||
reset, err := strconv.ParseInt(strings.TrimSpace(response.Header.Get("X-Ratelimit-Reset")), 10, 64)
|
||||
if err != nil || reset <= 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user