-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_log.go
43 lines (35 loc) · 1.32 KB
/
api_log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package flamework
import (
"encoding/json"
"fmt"
"log/slog"
)
type ApiLog struct {
Id int64 `json:"id"`
ApiKeyId int64 `json:"api_key_id"`
ApiKeyUserId int64 `json:"api_key_user_id"`
ApiKeyRoleId uint8 `json:"api_key_role_id"`
AccessTokenId int64 `json:"access_token_id"`
AccessTokenUserId int64 `json:"access_token_user_id"`
AccessTokenHash string `json:"access_token_hash"`
Method string `json:"method"`
Hostname string `json:"hostname"`
RemoteAddr int `json:"remote_addr"`
Stat uint8 `json:"stat"`
Error *ApiError `json:"error,omitempty"`
Params map[string]interface{} `json:"params,omitempty"`
Created int64 `json:"created"`
}
type ApiError struct {
Code int `json:"code"`
Message string `json:"message"`
}
func UnmarshalApiLog(msg string) (*ApiLog, error) {
var log *ApiLog
err := json.Unmarshal([]byte(msg), &log)
if err != nil {
slog.Info("Failed to unmarshal message", "message", msg)
return nil, fmt.Errorf("Failed to unmarshal message, %w", err)
}
return log, nil
}