gaudit

package module
v0.1.0-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2024 License: MIT Imports: 7 Imported by: 0

README ΒΆ

logo

πŸ† Gaudit

Welcome to Gaudit, an elegant and powerful auditing package for Go applications! With Gaudit, you can effortlessly track changes, log activities, and maintain a detailed audit trail of your data.

go versionΒ 

πŸ“¦ Features

  • Comprehensive Auditing: Automatically log changes for insert and update operations.
  • Flexible Hooks: Use pre-defined hooks or create your own to customize auditing behavior.
  • Rich Metadata: Capture essential details such as user actions, timestamps, and IP addresses.
  • Easy Integration: Seamlessly integrate with your existing Go applications.
  • Extensible: Extend the package with your own custom functionalities.

πŸš€ Installation

To get started with Gaudit, install it using Go modules:

go get github.com/its-own/gaudit

πŸ“– Usage

Here's a quick example of how to use Gaudit in your application:

//main.go

package main

import (
    "context"
    "fmt"
    "github.com/its-own/gaudit"
    "go.mongodb.org/mongo-driver/bson/primitive"
    "go.mongodb.org/mongo-driver/mongo"
    "go.mongodb.org/mongo-driver/mongo/options"
    "log/slog"
)

func main() {
    // connect to mongo db
    ctx := context.Background()
    client := connectMongo(ctx, "mongodb://localhost:27017")
    // initialize go audit
    aMgo := gaudit.Init(&gaudit.Config{
        Client:   client,
        Database: client.Database("test_database"),
        Logger:   slog.Default(),
    })
    // create user and pass gaudit mongo instance
    _, err := NewUserRepo("user", aMgo).Create(ctx, &User{
        ID:   primitive.NewObjectID(),
        Name: "Razibul Hasan Mithu",
    })
    if err != nil {
        return
    }
}

//repo.go

package main

import (
    "context"
    "github.com/its-own/gaudit/db"
    "github.com/its-own/gaudit/in"
    "go.mongodb.org/mongo-driver/bson/primitive"
)

type User struct {
    in.Inject
    ID   primitive.ObjectID `bson:"_id" json:"id"`
    Name string             `bson:"name" json:"name"`
}

// IUserRepo is a User repository
type IUserRepo interface {
    Create(ctx context.Context, param *User) (*User, error)
}

// UserRepo implementation of IUserRepo, also holds collection name and mongo db rapper repository
type UserRepo struct {
    collection string
    connection db.NoSql
}

func NewUserRepo(collection string, connection db.NoSql) IUserRepo {
    return &UserRepo{connection: connection, collection: collection}
}

// Create is a simple implementation of user repository
func (u UserRepo) Create(ctx context.Context, param *User) (*User, error) {
    err := u.connection.Insert(ctx, u.collection, param)
    if err != nil {
        return nil, err
    }
    return param, nil
}

πŸ”§ Configuration

Customize Gaudit to fit your needs. You can configure logging settings, output formats, and more in the config.go file.

coming soon

// Example of setting configuration
gaudit.SetConfig(gaudit.Config{
    LogLevel: "debug",
    // other configurations...
})

πŸ“š Documentation

coming soon

πŸ§ͺ Testing

Gaudit comes with a robust set of tests to ensure stability. Run the tests with:

go test ./...

πŸŽ‰ Contributing

We welcome contributions! If you'd like to contribute to Gaudit, please fork the repo and create a pull request. For larger changes, please open an issue first to discuss.

  1. Fork the repository
  2. Create a new branch (git checkout -b feature/my-feature)
  3. Make your changes
  4. Commit your changes (git commit -m 'Add some feature')
  5. Push to the branch (git push origin feature/my-feature)
  6. Open a Pull Request

πŸ“§ Contact

For any questions, suggestions, or feedback, feel free to reach out via Issues or contact us directly at razibulhasan.mithu@gmail.com.

🀝 License

This project is licensed under the MIT License - see the LICENSE file for details.


Thank you for considering Gaudit for your auditing needs! We hope it enhances your application's capabilities. Happy coding! πŸš€

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

func Init ΒΆ

func Init(c *Config) db.NoSql

Types ΒΆ

type Config ΒΆ

type Config struct {
	*mongo.Client
	Database *mongo.Database

	Logger *slog.Logger
	// contains filtered or unexported fields
}

Directories ΒΆ

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL