rookie-ninja / rk-db Goto Github PK
View Code? Open in Web Editor NEWEnterprise level database bootstrapper with YAML based on rk-entry in Golang
License: Apache License 2.0
Enterprise level database bootstrapper with YAML based on rk-entry in Golang
License: Apache License 2.0
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.
https://github.com/rookie-ninja/rk-db/blob/master/mongodb/README.md
import mongo package is : github.com/rookie-ninja/rk-db/mongodb
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.