Skip to content

Infranite/go-dblog

Repository files navigation

go-dblog

CI Go Version Go Reference Go Report Card License

go-dblog is a multi-module Go toolkit for parsing database change logs. The root module defines shared event, registry, checkpoint, filtering, and safe flashback/recovery contracts; each backend keeps product-specific parsing, live reading, typed events, and extension hooks in its own module.

中文

Product Index

Install only the backend you use.

Product Module README Features Examples
Common API github.com/Infranite/go-dblog This README Roadmap scope Minimal example below
MySQL family github.com/Infranite/go-dblog/mysql English / 中文 English / 中文 English / 中文
PostgreSQL family github.com/Infranite/go-dblog/postgres English / 中文 English / 中文 English / 中文
MongoDB family github.com/Infranite/go-dblog/mongo English / 中文 English / 中文 English / 中文
Redis family github.com/Infranite/go-dblog/redis English / 中文 English / 中文 English / 中文

Core Features

  • Backend-neutral dblog.Event shape for mixed database log streams.
  • Explicit backend registration through dblog.Registry.
  • Streaming decoders built on Go iterator APIs.
  • Shared source metadata, position, checkpoint resume, filtering, and safe flashback/recovery helpers.
  • Backend-native typed events for database-specific fields.
  • Plugin hooks inside backend decoder packages for compatible dialects and product-specific records.
  • Package-level loggers with standard-library defaults and per-package levels.
  • Separate Go modules so callers do not install unused database dependencies.

Install

The current public tag set is v1.0.0.

go get github.com/Infranite/[email protected]
go get github.com/Infranite/go-dblog/[email protected]
go get github.com/Infranite/go-dblog/[email protected]
go get github.com/Infranite/go-dblog/[email protected]
go get github.com/Infranite/go-dblog/[email protected]

Minimal Example

package main

import (
	"fmt"
	"strings"

	"github.com/Infranite/go-dblog"
	"github.com/Infranite/go-dblog/redis"
)

func main() {
	var registry dblog.Registry
	if err := redis.Register(&registry); err != nil {
		panic(err)
	}

	decoder, err := registry.Open(redis.Driver,
		dblog.WithReader(strings.NewReader("*2\r\n$4\r\nINCR\r\n$7\r\ncounter\r\n")),
	)
	if err != nil {
		panic(err)
	}
	defer decoder.Close()

	for event, err := range decoder.Events() {
		if err != nil {
			panic(err)
		}
		fmt.Println(event.Kind(), dblog.PositionOf(event).Value)
	}
}

Use the common API for multi-source routing, shared filtering, CDC pipelines, backend registration, and recovery tasks. Use backend-native APIs when you need database-specific event fields.

Logging

Every package exposes an independent Log slot. The default implementation is backed by the standard-library log package and writes INFO and above. Applications can tune a single package without changing the others. Use Log.Enabled before building expensive debug messages.

package main

import (
	"log"
	"os"

	"github.com/Infranite/go-dblog"
	"github.com/Infranite/go-dblog/mysql"
	"github.com/Infranite/go-dblog/redis"
)

func main() {
	mysql.Log.SetLevel(dblog.LevelDebug)
	if mysql.Log.Enabled(dblog.LevelDebug) {
		mysql.Log.Logf(dblog.LevelDebug, "mysql decoder debug logging is enabled")
	}

	redisLogger := dblog.NewStdLogger("redis-aof", dblog.LevelWarn)
	redisLogger.StandardLogger().SetOutput(os.Stdout)
	redisLogger.StandardLogger().SetFlags(log.LstdFlags | log.Lmicroseconds)
	redis.Log.SetLogger(redisLogger)
}

Project Docs

Topic English 中文
Project overview This README doc/README.zh-CN.md
Recovery cookbook doc/RECOVERY.md doc/RECOVERY.zh-CN.md
CI evidence doc/CI.md doc/CI.zh-CN.md
Roadmap and product scope doc/ROADMAP.md doc/ROADMAP.zh-CN.md
Development and contribution flow doc/DEVELOPMENT.md doc/DEVELOPMENT.zh-CN.md
Security policy doc/SECURITY.md doc/SECURITY.zh-CN.md

GitHub Releases and git tags are the public release record. Git history is the detailed change log; this repository does not maintain separate release notes or changelog files.

License

Apache License 2.0. See LICENSE.

About

High-performance database change log parsing toolkit for Go

Topics

Resources

License

Security policy

Stars

22 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors