-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ea201b
commit 1a172a1
Showing
9 changed files
with
170 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM golang:1.20-alpine AS build | ||
WORKDIR /app | ||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
COPY . . | ||
RUN CGO_ENABLED=0 GOOS=linux go build -o main | ||
|
||
FROM alpine:latest | ||
WORKDIR /app | ||
COPY --from=build /app/main . | ||
ENV AUTH_SERVICE_PORT=${AUTH_SERVICE_PORT} | ||
ENV POSTGRES_URI=${POSTGRES_URI} | ||
CMD [ "./main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package db | ||
|
||
import ( | ||
"landate/authentication/models" | ||
"landate/config" | ||
"log" | ||
|
||
"gorm.io/driver/postgres" | ||
"gorm.io/gorm" | ||
"gorm.io/gorm/logger" | ||
) | ||
|
||
var DB *gorm.DB | ||
|
||
func GetDBInstance() *gorm.DB { | ||
return DB | ||
} | ||
|
||
func PGConnect() { | ||
postgresURI := config.GetEnvConfig("POSTGRES_URI") | ||
db, err := gorm.Open(postgres.Open(postgresURI), &gorm.Config{ | ||
Logger: logger.Default.LogMode(logger.Info), | ||
}) | ||
if err != nil { | ||
log.Fatal("Failed to connect to Database.", err) | ||
} | ||
log.Println("Connected ✅") | ||
db.Logger = logger.Default.LogMode(logger.Info) | ||
|
||
// Migrate the schema to Database | ||
log.Println("Running migrations...") | ||
db.AutoMigrate(&models.User{}) | ||
|
||
DB = db | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package handlers | ||
|
||
import "github.com/gofiber/fiber/v2" | ||
|
||
// @Desp: Create User | ||
func CreateUser(c *fiber.Ctx) error { | ||
return nil | ||
} | ||
|
||
// @Desp: Get User | ||
func RetrieveUser(c *fiber.Ctx) error { | ||
return nil | ||
} | ||
|
||
func GetAllUsers(c *fiber.Ctx) error { | ||
return nil | ||
} | ||
|
||
func RemoveUser(c *fiber.Ctx) error { | ||
return nil | ||
} | ||
|
||
func UpdateUser(c *fiber.Ctx) error { | ||
return nil | ||
} | ||
|
||
func GetUserByWalledId(c *fiber.Ctx) error { | ||
return nil | ||
} | ||
|
||
func GetUserById(c *fiber.Ctx) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package routes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package consumer | ||
|
||
func MessageConsumer() { | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package producer | ||
|
||
import ( | ||
"context" | ||
broker "landate/broker" | ||
"log" | ||
"time" | ||
|
||
amqp "github.com/rabbitmq/amqp091-go" | ||
) | ||
|
||
func MessageProducer() { | ||
|
||
ch, bctx := broker.RabbitMQClient() | ||
|
||
err := ch.ExchangeDeclare( | ||
"payload", // name | ||
"fanout", // type | ||
true, // durable | ||
false, // auto-deleted | ||
false, // internal | ||
false, // no-wait | ||
nil, // arguments | ||
) | ||
failOnError(err, "Failed to declare an exchange") | ||
|
||
ctx, cancel := context.WithTimeout(bctx, 5*time.Second) | ||
defer cancel() | ||
|
||
err = ch.PublishWithContext(ctx, | ||
"logs", // exchange | ||
"", // routing key | ||
false, // mandatory | ||
false, // immediate | ||
amqp.Publishing{ | ||
ContentType: "text/plain", | ||
Body: []byte(""), | ||
}) | ||
|
||
failOnError(err, "Failed to publish a message") | ||
} | ||
|
||
func failOnError(err error, msg string) { | ||
if err != nil { | ||
log.Panicf("%s: %s", msg, err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package broker | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/rabbitmq/amqp091-go" | ||
) | ||
|
||
type MsgBroker struct { | ||
mbChannel *amqp091.Channel | ||
ctx context.Context | ||
} | ||
|
||
func RabbitMQClient() (*amqp091.Channel, context.Context) { | ||
|
||
conn, err := amqp091.Dial("amqp://guest:guest@localhost:5672/") | ||
failOnError(err, "Failed to connect to RabbitMQ") | ||
defer conn.Close() | ||
|
||
channel, err := conn.Channel() | ||
failOnError(err, "Failed to open a channel") | ||
defer channel.Close() | ||
|
||
ctx := context.Background() | ||
return channel, ctx | ||
} | ||
|
||
func failOnError(err error, msg string) { | ||
if err != nil { | ||
log.Panicf("%s: %s", msg, err) | ||
} | ||
} |