Skip to content

Commit

Permalink
Refactored repo layout to Go standard and added basics of a Dockerise…
Browse files Browse the repository at this point in the history
…d environment
  • Loading branch information
KrylixZA committed Aug 10, 2024
1 parent eb7c7b7 commit 4f5586e
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 19 deletions.
11 changes: 0 additions & 11 deletions .editorconfig

This file was deleted.

12 changes: 10 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# JetBrains directories
.idea
# IDE directories and files
.idea
.vscode
.vs

# OS directories and files
**/.DS_Store

# Build artifacts
**/dist
24 changes: 24 additions & 0 deletions cmd/accounts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM golang:1.22.5

# Set destination for COPY
WORKDIR /app

# Download Go modules
COPY go.mod go.sum ./
RUN go mod download

# Copy the entire project or the necessary directories, preserving the structure
COPY . .

# Build the Go application
RUN go build -o /dist cmd/accounts/main.go

# Expose the application port
EXPOSE 8080

# Options to run in debug or release mode
ARG CONFIG=debug
ENV GIN_MODE=${CONFIG}

# Run the compiled application
CMD ["/dist"]
2 changes: 1 addition & 1 deletion src/accounts/account.go → cmd/accounts/app/account.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package accounts
package app

type account struct {
AccountID string `json:"accountId"`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package accounts
package app

type AccountType int

Expand Down
4 changes: 2 additions & 2 deletions src/accounts/accounts.go → cmd/accounts/app/accounts.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package accounts
package app

import (
"encoding/json"
Expand All @@ -10,7 +10,7 @@ import (

const state = "accounts-state"
const validationFailureErrorMessage = "model validation failure while attempting to map request to type"
const notFoundErrorMessage = "reesource not found"
const notFoundErrorMessage = "resource not found"
const internalServerErrorMessage = "an environmental, non-specific error has occurred"

func GetAccountsForUser(c *gin.Context) {
Expand Down
7 changes: 5 additions & 2 deletions src/main.go → cmd/accounts/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/KrylixZA/bank-with-dapr/accounts"
accounts "github.com/KrylixZA/bank-with-dapr/cmd/accounts/app"
"github.com/gin-gonic/gin"
)

Expand All @@ -10,5 +10,8 @@ func main() {
router.GET("/accounts/:userId", accounts.GetAccountsForUser)
router.POST("/accounts/:userId", accounts.CreateAccountForUser)

router.Run("localhost:8080")
err := router.Run("localhost:8080")
if err != nil {
panic(err)
}
}
File renamed without changes.
67 changes: 67 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
services:
###################################
# dapr placement service #
###################################
placement:
image: daprio/placement:latest
container_name: placement
command: [ "./placement", "--port", "50006" ]
ports:
- 50006:50006
networks:
- bank-network

###################################
# redis #
###################################
redis:
image: redis:6
container_name: redis
ports:
- 6379:6379
networks:
- bank-network

###################################
# rabbitmq #
###################################
rabbitmq:
image: rabbitmq:3-management
container_name: rabbitmq
ports:
- 5672:5672
- 15672:15672
networks:
- bank-network

###################################
# accounts service + dapr sidecar #
###################################
accounts-service:
image: bank-with-dapr/accounts:dev
container_name: accounts-service
build:
context: .
dockerfile: cmd/accounts/Dockerfile
tags:
- bank-with-dapr/accounts:dev
ports:
- 8080:8080
networks:
- bank-network

accounts-service-dapr:
image: daprio/daprd:latest
command: [ "./daprd",
"--app-id", "accounts-service",
"--app-port", "8080",
"--placement-host-address", "placement:50006",
"--components-path", "/components" ]
volumes:
- ./dapr/:/components
depends_on:
- placement
network_mode: "service:accounts-service"

networks:
bank-network: null
File renamed without changes.
File renamed without changes.
Empty file removed test/.gitkeep
Empty file.

0 comments on commit 4f5586e

Please sign in to comment.