Skip to content

Commit

Permalink
change stuct to stuct pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
obgnail committed Feb 9, 2023
1 parent e723184 commit 3e96379
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions audit_log/audit_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ func New(binlogSyncer *syncer.BinlogSynchronizer, txInfoSyncer *syncer.TxInfoSyn
return &AuditLogger{binlogSyncer: binlogSyncer, txInfoSyncer: txInfoSyncer}
}

func (a *AuditLogger) Sync(handler Handler) {
go a.txInfoSyncer.HandleAuditLog(handler.OnAuditLog)
a.binlogSyncer.Sync()
a.txInfoSyncer.Sync()
func (log *AuditLogger) Sync(handler Handler) {
go log.txInfoSyncer.HandleAuditLog(handler.OnAuditLog)
log.binlogSyncer.Sync()
log.txInfoSyncer.Sync()
}

func Init(path string) {
Expand Down
10 changes: 5 additions & 5 deletions audit_log/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import (
)

type Handler interface {
OnAuditLog(auditLog types.AuditLog) error
OnAuditLog(auditLog *types.AuditLog) error
}

type FunctionHandler func(auditLog types.AuditLog) error
type FunctionHandler func(auditLog *types.AuditLog) error

func (f FunctionHandler) OnAuditLog(auditLog types.AuditLog) error {
func (f FunctionHandler) OnAuditLog(auditLog *types.AuditLog) error {
return f(auditLog)
}

type DummyAuditLogHandler func(auditLog types.AuditLog) error
type DummyAuditLogHandler func(auditLog *types.AuditLog) error

func (f DummyAuditLogHandler) OnAuditLog(auditLog types.AuditLog) error {
func (f DummyAuditLogHandler) OnAuditLog(auditLog *types.AuditLog) error {
fmt.Printf("get audit log: %+v", auditLog)
return nil
}
4 changes: 2 additions & 2 deletions example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
func main() {
audit_log.Init("../config/config.toml")

audit_log.Run(audit_log.FunctionHandler(func(auditLog types.AuditLog) error {
fmt.Printf("get audit log: %+v\n", auditLog)
audit_log.Run(audit_log.FunctionHandler(func(auditLog *types.AuditLog) error {
fmt.Printf("get audit log: %+v\n", *auditLog)
return nil
}))

Expand Down
8 changes: 4 additions & 4 deletions syncer/tx_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ const (

type TxInfoSynchronizer struct {
*broker.TxKafkaBroker
auditChan chan types.AuditLog
auditChan chan *types.AuditLog
}

func NewTxInfoSyncer(broker *broker.TxKafkaBroker) *TxInfoSynchronizer {
return &TxInfoSynchronizer{TxKafkaBroker: broker, auditChan: make(chan types.AuditLog, defaultAuditChanSize)}
return &TxInfoSynchronizer{TxKafkaBroker: broker, auditChan: make(chan *types.AuditLog, defaultAuditChanSize)}
}

func (s *TxInfoSynchronizer) HandleAuditLog(fn func(txEvent types.AuditLog) error) {
func (s *TxInfoSynchronizer) HandleAuditLog(fn func(txEvent *types.AuditLog) error) {
for audit := range s.auditChan {
if err := fn(audit); err != nil {
logger.ErrorDetails(errors.Trace(err))
Expand Down Expand Up @@ -187,7 +187,7 @@ func (i *unprocessedInfos) Add(info types.ChTxInfo) {
}

func (i *unprocessedInfos) getToProcess() (
toProcessInfoEvents []types.AuditLog,
toProcessInfoEvents []*types.AuditLog,
toProcessInfo []types.ChTxInfo,
err error,
) {
Expand Down
4 changes: 2 additions & 2 deletions types/binlog_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type AuditLog struct {
BinlogEvents []ChBinlogEvent
}

func NewAuditLog(txInfo ChTxInfo, events []ChBinlogEvent) AuditLog {
txBinlogEvent := AuditLog{
func NewAuditLog(txInfo ChTxInfo, events []ChBinlogEvent) *AuditLog {
txBinlogEvent := &AuditLog{
Time: txInfo.Time,
Context: txInfo.Context,
GTID: txInfo.GTID,
Expand Down

0 comments on commit 3e96379

Please sign in to comment.