Skip to content

Commit

Permalink
change go.mod
Browse files Browse the repository at this point in the history
  • Loading branch information
obgnail committed Feb 9, 2023
1 parent 3e96379 commit b30eccc
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
21 changes: 12 additions & 9 deletions audit_log/audit_log.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package audit_log

import (
"fmt"
"github.com/obgnail/audit-log/clickhouse"
"github.com/obgnail/audit-log/config"
"github.com/obgnail/audit-log/logger"
Expand All @@ -24,17 +25,19 @@ func (log *AuditLogger) Sync(handler Handler) {
}

func Init(path string) {
checkErr(config.InitConfig(path))
checkErr(logger.InitLogger())
checkErr(syncer.InitBinlogSyncer())
checkErr(syncer.InitTxInfoSyncer())
checkErr(mysql.InitDBM())
checkErr(clickhouse.InitClickHouse())
if err := config.InitConfig(path); err != nil {
panic(err)
}
onStart(logger.InitLogger)
onStart(syncer.InitBinlogSyncer)
onStart(syncer.InitTxInfoSyncer)
onStart(mysql.InitDBM)
onStart(clickhouse.InitClickHouse)
}

func checkErr(err error) {
if err != nil {
panic(err)
func onStart(fn func() error) {
if err := fn(); err != nil {
panic(fmt.Sprintf("Error at onStart: %s\n", err))
}
}

Expand Down
13 changes: 13 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,20 @@ var (
ClickHouse *ClickHouseConfig
)

func FindConfigPath(configPath string) string {
// 向上找5层, 满足在一些单元测试中加载不了配置文件的问题
for i := 0; i < 5; i++ {
if _, err := os.Stat(configPath); err == nil {
return configPath
} else {
configPath = "../" + configPath
}
}
panic("not found config file in path")
}

func InitConfig(path string) error {
path = FindConfigPath(path)
var cfg MainConfig
f, err := os.Open(path)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func main() {
audit_log.Init("../config/config.toml")
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)
Expand Down
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ module github.com/obgnail/audit-log

go 1.18

replace github.com/obgnail/audit-log/go-mysql-driver => ./mysql/go-mysql-driver

require (
github.com/BurntSushi/toml v1.2.1
github.com/ClickHouse/clickhouse-go/v2 v2.0.12
github.com/Shopify/sarama v1.37.0
github.com/juju/errors v0.0.0-20220203013757-bd733f3c86b9
github.com/obgnail/audit-log/go-mysql-driver v0.0.0-00010101000000-000000000000
github.com/obgnail/mysql-river v0.0.0-20230209124253-5cfe7a909806
github.com/satori/go.uuid v1.2.0
gopkg.in/gorp.v1 v1.7.2
Expand Down
3 changes: 0 additions & 3 deletions mysql/go-mysql-driver/go.mod

This file was deleted.

2 changes: 1 addition & 1 deletion mysql/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"github.com/juju/errors"
"github.com/obgnail/audit-log/config"
_ "github.com/obgnail/audit-log/go-mysql-driver"
_ "github.com/obgnail/audit-log/mysql/go-mysql-driver"
"gopkg.in/gorp.v1"
"time"
)
Expand Down

0 comments on commit b30eccc

Please sign in to comment.