Add monorepo structure for NexaVPN WireGuard control plane including: - .gitignore for node_modules, build artifacts, and environment files - README with project overview, monorepo layout, and quick start guide - Admin web UI with React, Vite, TypeScript, and nginx reverse proxy - API client with type definitions for users, devices, policies, gateways, and audit logs - Admin pages for dashboard, users, devices, policies, g
48 lines
912 B
Go
48 lines
912 B
Go
package audit
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type Entry struct {
|
|
ActorUserID *uuid.UUID
|
|
EntityType string
|
|
EntityID *uuid.UUID
|
|
EventType string
|
|
Status string
|
|
Message string
|
|
Metadata map[string]any
|
|
}
|
|
|
|
type Repository interface {
|
|
Write(ctx context.Context, entry Entry) error
|
|
List(ctx context.Context, limit int) ([]map[string]any, error)
|
|
}
|
|
|
|
type Service struct {
|
|
repo Repository
|
|
}
|
|
|
|
func NewService(repo Repository) *Service {
|
|
return &Service{repo: repo}
|
|
}
|
|
|
|
func (s *Service) Record(ctx context.Context, entry Entry) error {
|
|
if entry.Metadata == nil {
|
|
entry.Metadata = map[string]any{}
|
|
}
|
|
return s.repo.Write(ctx, entry)
|
|
}
|
|
|
|
func (s *Service) List(ctx context.Context, limit int) ([]map[string]any, error) {
|
|
return s.repo.List(ctx, limit)
|
|
}
|
|
|
|
func MarshalMetadata(metadata map[string]any) []byte {
|
|
raw, _ := json.Marshal(metadata)
|
|
return raw
|
|
}
|