Skip to content

Commit

Permalink
ft(db): auth svc db conn and svc discovery added
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhantprateek committed Aug 20, 2023
1 parent 17e85ad commit e428855
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions authentication/db/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func GetDBInstance() *gorm.DB {
return DB
}

func PGConnect() {
func PGConnect() error {
postgresURI := config.GetEnvConfig("POSTGRES_URI")
db, err := gorm.Open(postgres.Open(postgresURI), &gorm.Config{
Logger: logger.Default.LogMode(logger.Info),
Expand All @@ -29,8 +29,8 @@ func PGConnect() {

// Migrate the schema to Database
log.Println("Running migrations...")
db.AutoMigrate(&models.User{})
err = db.AutoMigrate(&models.User{})

DB = db

return err
}
23 changes: 23 additions & 0 deletions authentication/main.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
package main

import (
db "landate/authentication/db"
auth_api "landate/authentication/routes"

config "landate/config"
consul "landate/consul"
"log"
"strconv"
)

var (
svcId = "auth_id"
svcName = "auth_svc"
envPORT = "AUTH_SERVICE_PORT"
svcTag = "auth"
)

// This Service contain User Authentication information
// and Its Profile Information
func main() {

if err := db.PGConnect(); err != nil {
log.Fatal("Unable to connect auth-svc to database.")
}

svc_port, err := strconv.Atoi(config.GetEnvConfig(envPORT))
if err != nil {
log.Fatal(err)
}
auth_svc := consul.NewService(svcId, svcName, svcTag, svc_port)

if err := auth_api.Init(); err != nil {
log.Fatalln("Unable to start auth service.")
}
auth_svc.DeregisterService()

}

0 comments on commit e428855

Please sign in to comment.