diff options
Diffstat (limited to 'src/payload-processor')
-rw-r--r-- | src/payload-processor/processor/BUILD.bazel | 3 | ||||
-rw-r--r-- | src/payload-processor/processor/db.go | 5 | ||||
-rw-r--r-- | src/payload-processor/processor/mock_db.go | 3 | ||||
-rw-r--r-- | src/payload-processor/processor/model.go | 10 | ||||
-rw-r--r-- | src/payload-processor/processor/processor.go | 3 | ||||
-rw-r--r-- | src/payload-processor/processor/processor_test.go | 3 |
6 files changed, 11 insertions, 16 deletions
diff --git a/src/payload-processor/processor/BUILD.bazel b/src/payload-processor/processor/BUILD.bazel index d8d8afe..411300d 100644 --- a/src/payload-processor/processor/BUILD.bazel +++ b/src/payload-processor/processor/BUILD.bazel @@ -5,12 +5,12 @@ go_library( srcs = [ "db.go", "mock_db.go", - "model.go", "processor.go", ], importpath = "github.com/Baitinq/fs-tracer-backend/src/payload-processor/processor", visibility = ["//visibility:public"], deps = [ + "//lib", "@com_github_google_uuid//:uuid", "@com_github_jmoiron_sqlx//:sqlx", "@com_github_segmentio_kafka_go//:kafka-go", @@ -23,6 +23,7 @@ go_test( srcs = ["processor_test.go"], embed = [":processor"], deps = [ + "//lib", "@com_github_segmentio_kafka_go//:kafka-go", "@com_github_stretchr_testify//require", "@org_uber_go_mock//gomock", diff --git a/src/payload-processor/processor/db.go b/src/payload-processor/processor/db.go index ce7d5bb..45ec484 100644 --- a/src/payload-processor/processor/db.go +++ b/src/payload-processor/processor/db.go @@ -3,12 +3,13 @@ package processor import ( "context" + "github.com/Baitinq/fs-tracer-backend/lib" "github.com/jmoiron/sqlx" ) //go:generate mockgen -source=$GOFILE -package=$GOPACKAGE -destination=mock_$GOFILE type DB interface { - InsertFile(ctx context.Context, file File) error + InsertFile(ctx context.Context, file lib.File) error } type DBImpl struct { @@ -21,7 +22,7 @@ func NewDB(db *sqlx.DB) DB { return &DBImpl{db: db} } -func (db DBImpl) InsertFile(ctx context.Context, file File) error { +func (db DBImpl) InsertFile(ctx context.Context, file lib.File) error { _, err := db.db.NamedExecContext(ctx, "INSERT INTO private.file (user_id, absolute_path, contents, timestamp) VALUES (:user_id, :absolute_path, :contents, :timestamp)", file) return err } diff --git a/src/payload-processor/processor/mock_db.go b/src/payload-processor/processor/mock_db.go index 53e5491..1b283bd 100644 --- a/src/payload-processor/processor/mock_db.go +++ b/src/payload-processor/processor/mock_db.go @@ -13,6 +13,7 @@ import ( context "context" reflect "reflect" + lib "github.com/Baitinq/fs-tracer-backend/lib" gomock "go.uber.org/mock/gomock" ) @@ -40,7 +41,7 @@ func (m *MockDB) EXPECT() *MockDBMockRecorder { } // InsertFile mocks base method. -func (m *MockDB) InsertFile(ctx context.Context, file File) error { +func (m *MockDB) InsertFile(ctx context.Context, file lib.File) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "InsertFile", ctx, file) ret0, _ := ret[0].(error) diff --git a/src/payload-processor/processor/model.go b/src/payload-processor/processor/model.go deleted file mode 100644 index 4921f3d..0000000 --- a/src/payload-processor/processor/model.go +++ /dev/null @@ -1,10 +0,0 @@ -package processor - -import "time" - -type File struct { - User_id string `db:"user_id"` - Absolute_path string `db:"absolute_path"` - Contents string `db:"contents"` - Timestamp time.Time `db:"timestamp"` -} diff --git a/src/payload-processor/processor/processor.go b/src/payload-processor/processor/processor.go index 889f4c0..ab128cb 100644 --- a/src/payload-processor/processor/processor.go +++ b/src/payload-processor/processor/processor.go @@ -11,6 +11,7 @@ import ( "syscall" "time" + "github.com/Baitinq/fs-tracer-backend/lib" "github.com/google/uuid" "github.com/jmoiron/sqlx" "github.com/segmentio/kafka-go" @@ -92,7 +93,7 @@ func (p Processor) process(ctx context.Context, cancel context.CancelFunc) { func (p Processor) handleMessage(ctx context.Context, m kafka.Message) error { fmt.Printf("(%s): message at paritition %d: offset %d: %s = %s\n", time.Now().String(), m.Partition, m.Offset, string(m.Key), string(m.Value)) - var file File + var file lib.File err := json.Unmarshal(m.Value, &file) if err != nil { return err diff --git a/src/payload-processor/processor/processor_test.go b/src/payload-processor/processor/processor_test.go index d3778de..39e965e 100644 --- a/src/payload-processor/processor/processor_test.go +++ b/src/payload-processor/processor/processor_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "github.com/Baitinq/fs-tracer-backend/lib" "github.com/segmentio/kafka-go" "github.com/stretchr/testify/require" gomock "go.uber.org/mock/gomock" @@ -28,7 +29,7 @@ func TestProcessMessage(t *testing.T) { ctx := context.Background() - mockdb.EXPECT().InsertFile(ctx, File{ + mockdb.EXPECT().InsertFile(ctx, lib.File{ User_id: "1", Absolute_path: "/tmp/file.txt", Contents: "hello world", |