Coder Social home page Coder Social logo

rk-db's People

Contributors

dongxuny avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rk-db's Issues

Failed to get Postgres entry using rk-boot in Golang

I'm developing a gRPC server in Go using rookie-ninja/rk-boot, rookie-ninja/rk-db/postgres, and rookie-ninja/rk-grpc/boot. I'm trying to connect to a Postgres database, but I'm encountering the error: "failed to get Postgres entry".

Configuration

Below is my configuration for the Postgres database:

postgres:
  - name: user
    enabled: true
    domain: "*"
    addr: "192.168.8.104:5432"
    user: postgres
    pass: 12345678
    database:
      - name: webchat
        autoCreate: true

Code

Here is the relevant part of my code:

package main

import (
    "context"
    "fmt"
    "log"
    "os"
    "time"

    greeter "github.com/chater-co/web-chat/api/gen/v1"
    rkboot "github.com/rookie-ninja/rk-boot"
    rkpostgres "github.com/rookie-ninja/rk-db/postgres"
    rkgrpc "github.com/rookie-ninja/rk-grpc/boot"
    "google.golang.org/grpc"
    "google.golang.org/grpc/grpclog"
    "gorm.io/gorm"
)

var userDb *gorm.DB

func init() {
    grpclog.SetLoggerV2(grpclog.NewLoggerV2(os.Stdout, os.Stdout, os.Stdout))
}

func main() {
    boot := rkboot.NewBoot()
    boot.Bootstrap(context.TODO())

    pgEntry := rkpostgres.GetPostgresEntry("user")
    if pgEntry == nil {
        log.Fatalf("failed to get Postgres entry")
    }
    userDb = pgEntry.GetDB("webchat")
    if !userDb.DryRun {
        userDb.AutoMigrate(&User{})
    }

    grpcEntry := rkgrpc.GetGrpcEntry("chat-app")
    grpcEntry.AddRegFuncGrpc(registerGreeter)
    grpcEntry.AddRegFuncGw(greeter.RegisterGreeterHandlerFromEndpoint)
    boot.Bootstrap(context.Background())
    boot.WaitForShutdownSig(context.TODO())
}

func registerGreeter(server *grpc.Server) {
    greeter.RegisterGreeterServer(server, &GreeterServer{})
}

type GreeterServer struct{}

type Base struct {
    CreatedAt time.Time      `yaml:"-" json:"-"`
    UpdatedAt time.Time      `yaml:"-" json:"-"`
    DeletedAt gorm.DeletedAt `yaml:"-" json:"-" gorm:"index"`
}

type User struct {
    Base
    Id   int    `yaml:"id" json:"id" gorm:"primaryKey"`
    Name string `yaml:"name" json:"name"`
}

func (server *GreeterServer) Greeter(ctx context.Context, request *greeter.GreeterRequest) (*greeter.GreeterResponse, error) {
    return &greeter.GreeterResponse{
        Message: fmt.Sprintf("Hello %s!", request.Name),
    }, nil
}

What I've Tried

Double-checked the YAML configuration for errors.

Verified that the database server is running and accessible at 192.168.8.104:5432.

Checked for any network issues between my application and the database server.

Expected Behavior

The application should successfully connect to the Postgres database and perform auto-migration for the User table.

Actual Behavior

The application logs the error: "failed to get Postgres entry" and exits.

Additional Information

Any help or guidance on what might be causing this issue would be greatly appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.