mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-22 23:35:26 +00:00
Chats (#96)
* stash * replace chats sql with store * strip unused method
This commit is contained in:
@@ -1,21 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/micro/services/chats/handler"
|
||||
pb "github.com/micro/services/chats/proto"
|
||||
|
||||
"github.com/micro/micro/v3/service"
|
||||
"github.com/micro/micro/v3/service/config"
|
||||
"github.com/micro/micro/v3/service/logger"
|
||||
|
||||
_ "github.com/jackc/pgx/v4/stdlib"
|
||||
)
|
||||
|
||||
var dbAddress = "postgresql://postgres:postgres@localhost:5432/chats?sslmode=disable"
|
||||
|
||||
func main() {
|
||||
// Create service
|
||||
srv := service.New(
|
||||
@@ -23,19 +17,7 @@ func main() {
|
||||
service.Version("latest"),
|
||||
)
|
||||
|
||||
// Connect to the database
|
||||
cfg, err := config.Get("chats.database")
|
||||
if err != nil {
|
||||
logger.Fatalf("Error loading config: %v", err)
|
||||
}
|
||||
addr := cfg.String(dbAddress)
|
||||
sqlDB, err := sql.Open("pgx", addr)
|
||||
if err != nil {
|
||||
logger.Fatalf("Failed to open connection to DB %s", err)
|
||||
}
|
||||
|
||||
h := &handler.Chats{Time: time.Now}
|
||||
h.DBConn(sqlDB).Migrations(&handler.Chat{}, &handler.Message{})
|
||||
// Register handler
|
||||
pb.RegisterChatsHandler(srv.Server(), h)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user