Adrià Vilanova MartÃnez | 25e1211 | 2021-08-25 13:48:06 +0200 | [diff] [blame^] | 1 | package db |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "database/sql" |
| 6 | |
| 7 | "google.golang.org/protobuf/proto" |
| 8 | "google.golang.org/protobuf/types/known/timestamppb" |
| 9 | |
| 10 | pb "gomodules.avm99963.com/twpt-server/api_proto" |
| 11 | ) |
| 12 | |
| 13 | func AddKillSwitchAuditLogEntry(tx *sql.Tx, ctx context.Context, logEntry *pb.KillSwitchAuditLogEntry) error { |
| 14 | logEntry.Timestamp = timestamppb.Now() |
| 15 | |
| 16 | logEntryBytes, err := proto.Marshal(logEntry) |
| 17 | if err != nil { |
| 18 | return err |
| 19 | } |
| 20 | |
| 21 | if _, err := tx.ExecContext(ctx, "INSERT INTO KillSwitchAuditLog (data) VALUES (?)", logEntryBytes); err != nil { |
| 22 | return err |
| 23 | } |
| 24 | |
| 25 | return nil |
| 26 | } |