update tool generet

This commit is contained in:
2025-08-25 17:46:04 +07:00
parent f31924050f
commit fc0575af02
5 changed files with 3823 additions and 2 deletions

2
go.mod
View File

@@ -24,6 +24,7 @@ require (
github.com/rs/zerolog v1.34.0
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.6
github.com/tidwall/gjson v1.18.0
)
@@ -66,7 +67,6 @@ require (
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
github.com/swaggo/swag v1.16.6 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect

View File

@@ -13,7 +13,6 @@ func TestDynamicLogging(t *testing.T) {
t.Run("TestSaveLogText", testSaveLogText)
t.Run("TestSaveLogJSON", testSaveLogJSON)
t.Run("TestSaveLogToDatabase", testSaveLogToDatabase)
t.Run("TestLogAndSave", testLogAndSave)
}
func testSaveLogText(t *testing.T) {

54
pkg/utils/etag.go Normal file
View File

@@ -0,0 +1,54 @@
package utils
import (
"fmt"
"strings"
)
// ParseETag extracts the ETag value from HTTP ETag header
// Handles both strong ETags ("123") and weak ETags (W/"123")
func ParseETag(etag string) string {
if etag == "" {
return ""
}
// Remove W/ prefix for weak ETags
if strings.HasPrefix(etag, "W/") {
etag = etag[2:]
}
// Remove surrounding quotes
if len(etag) >= 2 && strings.HasPrefix(etag, "\"") && strings.HasSuffix(etag, "\"") {
etag = etag[1 : len(etag)-1]
}
return etag
}
// FormatETag formats a version ID into a proper HTTP ETag header value
func FormatETag(versionId string, weak bool) string {
if versionId == "" {
return ""
}
if weak {
return fmt.Sprintf(`W/"%s"`, versionId)
}
return fmt.Sprintf(`"%s"`, versionId)
}
// IsValidETag validates if the given string is a valid ETag format
func IsValidETag(etag string) bool {
if etag == "" {
return false
}
// Check for weak ETag format
if strings.HasPrefix(etag, "W/") {
etag = etag[2:]
}
// Must be quoted
return len(etag) >= 2 && strings.HasPrefix(etag, "\"") && strings.HasSuffix(etag, "\"")
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff