Tests[RequestLogSimple]

This commit is contained in:
2023-05-27 23:54:14 +02:00
parent b2df0a5a02
commit 03f60ff316
15 changed files with 378 additions and 36 deletions

View File

@@ -18,7 +18,7 @@ type RequestLog struct {
RequestBodySize int64
RequestContentType string
RemoteIP string
TokenID *KeyTokenID
KeyID *KeyTokenID
UserID *UserID
Permissions *string
ResponseStatuscode *int64
@@ -45,7 +45,7 @@ func (c RequestLog) JSON() RequestLogJSON {
RequestBodySize: c.RequestBodySize,
RequestContentType: c.RequestContentType,
RemoteIP: c.RemoteIP,
TokenID: c.TokenID,
KeyID: c.KeyID,
UserID: c.UserID,
Permissions: c.Permissions,
ResponseStatuscode: c.ResponseStatuscode,
@@ -73,7 +73,7 @@ func (c RequestLog) DB() RequestLogDB {
RequestBodySize: c.RequestBodySize,
RequestContentType: c.RequestContentType,
RemoteIP: c.RemoteIP,
TokenID: c.TokenID,
KeyID: c.KeyID,
UserID: c.UserID,
Permissions: c.Permissions,
ResponseStatuscode: c.ResponseStatuscode,
@@ -100,7 +100,7 @@ type RequestLogJSON struct {
RequestBodySize int64 `json:"request_body_size"`
RequestContentType string `json:"request_content_type"`
RemoteIP string `json:"remote_ip"`
TokenID *KeyTokenID `json:"token_id"`
KeyID *KeyTokenID `json:"key_id"`
UserID *UserID `json:"userid"`
Permissions *string `json:"permissions"`
ResponseStatuscode *int64 `json:"response_statuscode"`
@@ -117,7 +117,7 @@ type RequestLogJSON struct {
}
type RequestLogDB struct {
RequestID RequestID `db:"requestLog_id"`
RequestID RequestID `db:"request_id"`
Method string `db:"method"`
URI string `db:"uri"`
UserAgent *string `db:"user_agent"`
@@ -126,13 +126,13 @@ type RequestLogDB struct {
RequestBodySize int64 `db:"request_body_size"`
RequestContentType string `db:"request_content_type"`
RemoteIP string `db:"remote_ip"`
TokenID *KeyTokenID `db:"token_id"`
KeyID *KeyTokenID `db:"key_id"`
UserID *UserID `db:"userid"`
Permissions *string `db:"permissions"`
ResponseStatuscode *int64 `db:"response_statuscode"`
ResponseBodySize *int64 `db:"response_body_size"`
ResponseBody *string `db:"response_body"`
ResponseContentType string `db:"request_content_type"`
ResponseContentType string `db:"response_content_type"`
RetryCount int64 `db:"retry_count"`
Panicked int64 `db:"panicked"`
PanicStr *string `db:"panic_str"`
@@ -153,6 +153,7 @@ func (c RequestLogDB) Model() RequestLog {
RequestBodySize: c.RequestBodySize,
RequestContentType: c.RequestContentType,
RemoteIP: c.RemoteIP,
KeyID: c.KeyID,
UserID: c.UserID,
Permissions: c.Permissions,
ResponseStatuscode: c.ResponseStatuscode,

View File

@@ -0,0 +1,45 @@
package models
import (
"crypto/sha512"
"encoding/hex"
"gogs.mikescher.com/BlackForestBytes/goext/dataext"
"gogs.mikescher.com/BlackForestBytes/goext/mathext"
"gogs.mikescher.com/BlackForestBytes/goext/sq"
"strings"
)
type RequestLogFilter struct {
}
func (f RequestLogFilter) SQL() (string, string, sq.PP, error) {
joinClause := ""
// ...
sqlClauses := make([]string, 0)
params := sq.PP{}
// ...
sqlClause := ""
if len(sqlClauses) > 0 {
sqlClause = strings.Join(sqlClauses, " AND ")
} else {
sqlClause = "1=1"
}
return sqlClause, joinClause, params, nil
}
func (f RequestLogFilter) Hash() string {
bh, err := dataext.StructHash(f, dataext.StructHashOptions{HashAlgo: sha512.New()})
if err != nil {
return "00000000"
}
str := hex.EncodeToString(bh)
return str[0:mathext.Min(8, len(bh))]
}