0

我正在按照这个pgxSO 问题在我的连接中实现一个记录器,因为我closed poolScan.

我在 vscode 中遇到了这个错误。

不能将 logrusadapter.NewLogger(logrusLogger) (类型 *logrusadapter.Logger 的值)用作“github.com/jackc/pgx/v4”。分配中的记录器值:方法日志的类型错误(具有 func(级别 github.com/jackc /pgx.LogLevel, msg string, data map[string]interface{}), want func(ctx context.Context, level github.com/jackc/pgx/v4.LogLevel, msg string, data map[string]interface{} ))

package main

import (
    "context"
    "log"
    "net/http"
    "os"

    "github.com/go-chi/chi"
    "github.com/go-chi/chi/middleware"
    "github.com/go-chi/jwtauth"
    "github.com/go-chi/render"
    "github.com/jackc/pgx/log/logrusadapter"
    "github.com/jackc/pgx/v4/pgxpool"
    "github.com/minio/minio-go/v7"
    "github.com/minio/minio-go/v7/pkg/credentials"
    "github.com/sirupsen/logrus"
)

func router() http.Handler {

    var err error

    // urlExample := "postgres://username:password@localhost:5432/database_name"

    config, err := pgxpool.ParseConfig(os.Getenv("DATABASE_URL"))

    if err != nil {
        log.Fatalln(err)
    }

    logrusLogger := &logrus.Logger{
        Out:          os.Stderr,
        Formatter:    new(logrus.JSONFormatter),
        Hooks:        make(logrus.LevelHooks),
        Level:        logrus.InfoLevel,
        ExitFunc:     os.Exit,
        ReportCaller: false,
    }
    config.ConnConfig.Logger = logrusadapter.NewLogger(logrusLogger)

    db, err := pgxpool.ConnectConfig(context.Background(), config)

    if err != nil {
        log.Fatalln(err)
    }

    defer db.Close()
4

0 回答 0