added players
This commit is contained in:
@@ -7,15 +7,18 @@ import (
|
||||
)
|
||||
|
||||
type AuditMeta struct {
|
||||
r *http.Request
|
||||
u *User
|
||||
ipAddress string
|
||||
userAgent string
|
||||
u *User
|
||||
}
|
||||
|
||||
func NewAudit(r *http.Request, u *User) *AuditMeta {
|
||||
if u == nil {
|
||||
u = CurrentUser(r.Context())
|
||||
}
|
||||
return &AuditMeta{r, u}
|
||||
func NewAudit(ipAdd, agent string, user *User) *AuditMeta {
|
||||
return &AuditMeta{ipAdd, agent, user}
|
||||
}
|
||||
|
||||
func NewAuditFromRequest(r *http.Request) *AuditMeta {
|
||||
u := CurrentUser(r.Context())
|
||||
return &AuditMeta{r.RemoteAddr, r.UserAgent(), u}
|
||||
}
|
||||
|
||||
// AuditInfo contains metadata for audit logging
|
||||
@@ -45,7 +48,10 @@ func extractTableName[T any]() string {
|
||||
if bunTag != "" {
|
||||
// Parse tag: "table:seasons,alias:s" -> "seasons"
|
||||
for part := range strings.SplitSeq(bunTag, ",") {
|
||||
part, _ := strings.CutPrefix(part, "table:")
|
||||
part, match := strings.CutPrefix(part, "table:")
|
||||
if match {
|
||||
return part
|
||||
}
|
||||
return part
|
||||
}
|
||||
}
|
||||
@@ -56,6 +62,38 @@ func extractTableName[T any]() string {
|
||||
return strings.ToLower(t.Name()) + "s"
|
||||
}
|
||||
|
||||
// extractTableName gets the bun table alias from a model type using reflection
|
||||
// Example: Season with `bun:"table:seasons,alias:s"` returns "s"
|
||||
func extractTableAlias[T any]() string {
|
||||
var model T
|
||||
t := reflect.TypeOf(model)
|
||||
|
||||
// Handle pointer types
|
||||
if t.Kind() == reflect.Pointer {
|
||||
t = t.Elem()
|
||||
}
|
||||
|
||||
// Look for bun.BaseModel field with table tag
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
field := t.Field(i)
|
||||
if field.Type.Name() == "BaseModel" {
|
||||
bunTag := field.Tag.Get("bun")
|
||||
if bunTag != "" {
|
||||
// Parse tag: "table:seasons,alias:s" -> "seasons"
|
||||
for part := range strings.SplitSeq(bunTag, ",") {
|
||||
part, match := strings.CutPrefix(part, "alias:")
|
||||
if match {
|
||||
return part
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: use struct name in lowercase + "s"
|
||||
return strings.ToLower(t.Name()) + "s"
|
||||
}
|
||||
|
||||
// extractResourceType converts a table name to singular resource type
|
||||
// Example: "seasons" -> "season", "users" -> "user"
|
||||
func extractResourceType(tableName string) string {
|
||||
|
||||
Reference in New Issue
Block a user