mongorus

package module
v0.0.0-...-7aa51a7 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2021 License: MIT Imports: 6 Imported by: 0

README

Use mongorus

Direct connection

package main

import (
	"fmt"
	"github.com/sirupsen/logrus"
	"github.com/wo4zhuzi/mongorus"
)

var Logger *logrus.Logger

func main() {
	Logger = logrus.New()

	hooker, err := mongorus.NewMongoHook("127.0.0.1", "test_db", "test_collection")

	if err == nil {
		Logger.Hooks.Add(hooker)
	} else {
		fmt.Print(err)
	}

	Logger.WithFields(logrus.Fields{
		"blockHeight": 1000,
		"txid":        "0x......",
	}).Warn("warn message : .........")
}

Authority connection

package main

import (
	"fmt"
	"github.com/sirupsen/logrus"
	"github.com/wo4zhuzi/mongorus"
	"go.mongodb.org/mongo-driver/mongo/options"
)

var Logger *logrus.Logger

func main() {
	Logger = logrus.New()
	hooker, err := mongorus.NewAuthMongoHook("127.0.0.1:12017", "test_db", "test_collection", options.Credential{
		Username: "test_username",
		Password: "test_password",
	})

	if err == nil {
		Logger.Hooks.Add(hooker)
	} else {
		fmt.Print(err)
	}

	Logger.WithFields(logrus.Fields{
		"blockHeight": 1000,
		"txid":        "0x......",
	}).Warn("warn message : .........")
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MongoClient *mongo.Client

Functions

This section is empty.

Types

type M

type M bson.M

type MongoHook

type MongoHook struct {
	MongoCollection *mongo.Collection
}

func NewAuthMongoHook

func NewAuthMongoHook(mongoUrl, db, collection string, auth options.Credential) (*MongoHook, error)

func NewMongoHook

func NewMongoHook(mongoUrl, db, collection string) (*MongoHook, error)

func (*MongoHook) Fire

func (h *MongoHook) Fire(entry *logrus.Entry) error

func (*MongoHook) Levels

func (h *MongoHook) Levels() []logrus.Level

Jump to

Keyboard shortcuts

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