This commit is contained in:
aafetisov committed 2026-11-20 17:14:41 +03:00
1 parent ee7a8ebb55
commit 3b0a73c424
17 files changed
+218 -20

No files matched your search

+36 -2
View File
@@ -1,8 +1,10 @@
package audit
import "encoding/json"
// Main info about audit
type RecordAudit struct {
// Arguments
// Arguments as JSON text
Arguments string `json:"args"`
// Call
@@ -14,7 +16,7 @@ type RecordAudit struct {
// Correlation ID
CorrelationID string `json:"correlation_id"`
// Kwargs
// Keyword arguments as JSON text
Kwargs string `json:"kwargs"`
// RemoteAddr
@@ -43,6 +45,38 @@ type RecordAudit struct {
// Public Session ID
PublicSessionID string `json:"public_session_id"`
// TTL
TTL string `json:"_ttl"`
}
// UnmarshalJSON accepts both JSON-encoded strings and structured arguments.
func (r *RecordAudit) UnmarshalJSON(data []byte) error {
type recordAudit RecordAudit
response := struct {
*recordAudit
Arguments auditJSONText `json:"args"`
Kwargs auditJSONText `json:"kwargs"`
}{
recordAudit: (*recordAudit)(r),
Arguments: auditJSONText{value: &r.Arguments, opening: '['},
Kwargs: auditJSONText{value: &r.Kwargs, opening: '{'},
}
return json.Unmarshal(data, &response)
}
type auditJSONText struct {
value *string
opening byte
}
func (f *auditJSONText) UnmarshalJSON(data []byte) error {
if len(data) > 0 && data[0] == f.opening {
*f.value = string(data)
return nil
}
return json.Unmarshal(data, f.value)
}
// Main info about audit