Skip to content

Commit

Permalink
ft(actions)
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhantprateek committed Aug 20, 2023
1 parent 0ea201b commit 1a172a1
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 48 deletions.
13 changes: 13 additions & 0 deletions authentication/Dockerfile
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"]
36 changes: 36 additions & 0 deletions authentication/db/connect.go
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

}
33 changes: 33 additions & 0 deletions authentication/handlers/handlers.go
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
}
2 changes: 2 additions & 0 deletions authentication/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package models

type User struct {
Id int `json:"id"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Name string `json:"name"`
WalletAddress string `json:"walletAddress"`
Email string `json:"email"`
Expand Down
1 change: 1 addition & 0 deletions authentication/routes/routes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package routes
5 changes: 5 additions & 0 deletions broker/consumer/consumer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package consumer

func MessageConsumer() {

}
48 changes: 0 additions & 48 deletions broker/msg_broker.go

This file was deleted.

47 changes: 47 additions & 0 deletions broker/producer/producer.go
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)
}
}
33 changes: 33 additions & 0 deletions broker/rabbitmq.go
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)
}
}

0 comments on commit 1a172a1

Please sign in to comment.