(new): rich message support
Golang lint / lint (pull_request) Successful in 1m20s
Golang lint / lint (push) Successful in 4m8s

(fix): runtime reliability
(tests): regression coverage
(doc): v1.1 release notes
This commit is contained in:
2026-08-12 16:34:44 +03:00
parent 48ddf66540
commit f03a081ed6
83 changed files with 6122 additions and 1925 deletions
+57
View File
@@ -0,0 +1,57 @@
package tgapi
import (
"encoding/json"
"fmt"
"strings"
)
const redactedLogValue = "<REDACTED>"
var sensitiveLogFields = map[string]struct{}{
"callback_data": {},
"credentials": {},
"data": {},
"invoice_payload": {},
"payload": {},
"provider_data": {},
"provider_token": {},
"secret": {},
"secret_token": {},
"token": {},
"web_app_query_id": {},
}
func redactRequestLog(data []byte) string {
var value any
if err := json.Unmarshal(data, &value); err != nil {
return fmt.Sprintf("<invalid JSON omitted: %d bytes>", len(data))
}
redactLogValue(value)
redacted, err := json.Marshal(value)
if err != nil {
return fmt.Sprintf("<unavailable JSON omitted: %d bytes>", len(data))
}
return string(redacted)
}
func redactLogValue(value any) {
switch value := value.(type) {
case map[string]any:
for key, item := range value {
if _, sensitive := sensitiveLogFields[strings.ToLower(key)]; sensitive {
value[key] = redactedLogValue
continue
}
redactLogValue(item)
}
case []any:
for _, item := range value {
redactLogValue(item)
}
}
}
func responseLogSummary(method string, size int) string {
return fmt.Sprintf("method=%s bytes=%d body=omitted", method, size)
}