Skip to content

Commit

Permalink
Use internal package to prevent cross service imports
Browse files Browse the repository at this point in the history
  • Loading branch information
billykore committed Jun 14, 2024
1 parent c0d82cc commit d6d390b
Show file tree
Hide file tree
Showing 137 changed files with 235 additions and 219 deletions.
4 changes: 2 additions & 2 deletions backend/pkg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ go_library(
importpath = "github.com/billykore/kore/backend/pkg",
visibility = ["//visibility:public"],
deps = [
"//pkg/broker/rabbit",
"//pkg/db",
"//pkg/log",
"//pkg/websocket",
"//pkg/net/rabbit",
"//pkg/net/websocket",
"@com_github_google_wire//:wire",
],
)
11 changes: 10 additions & 1 deletion backend/pkg/codes/codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ package codes
type Code int

const (
_ Code = iota // OK
// OK is success code.
_ Code = iota

// BadRequest is code to represents bad request error.
BadRequest

// Unauthenticated is code to represents unauthenticated error.
Unauthenticated

// NotFound is code to represents not found error.
NotFound

// Internal is code to represents internal server error.
Internal
)
1 change: 1 addition & 0 deletions backend/pkg/entity/cart.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type CartResponse struct {
} `json:"product"`
}

// MakeCartResponse makes CartResponse from model.Cart model.
func MakeCartResponse(m *model.Cart) *CartResponse {
return &CartResponse{
Id: m.ID,
Expand Down
1 change: 1 addition & 0 deletions backend/pkg/entity/discount.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type DiscountResponse struct {
DiscountPercentage float64 `json:"discountPercentage"`
}

// MakeDiscountResponse makes DiscountResponse from model.Discount model.
func MakeDiscountResponse(m *model.Discount) *DiscountResponse {
return &DiscountResponse{
Id: m.ID,
Expand Down
1 change: 1 addition & 0 deletions backend/pkg/entity/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type OrderResponse struct {
ShippingId int `json:"shippingId"`
}

// MakeOrderResponse makes OrderResponse from model.Order model.
func MakeOrderResponse(m *model.Order) *OrderResponse {
return &OrderResponse{
Id: m.ID,
Expand Down
1 change: 1 addition & 0 deletions backend/pkg/entity/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type ProductResponse struct {
Discount *DiscountResponse `json:"discount"`
}

// MakeProductResponse makes ProductResponse from model.Order model.
func MakeProductResponse(m *model.Product) *ProductResponse {
return &ProductResponse{
Id: m.ID,
Expand Down
1 change: 1 addition & 0 deletions backend/pkg/entity/product_category.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type ProductCategoryResponse struct {
Description string `json:"description"`
}

// MakeProductCategoryResponse makes ProductCategoryResponse from model.ProductCategory model.
func MakeProductCategoryResponse(m *model.ProductCategory) *ProductCategoryResponse {
return &ProductCategoryResponse{
Id: m.ID,
Expand Down
1 change: 1 addition & 0 deletions backend/pkg/entity/product_inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type ProductInventoryResponse struct {
Description string `json:"description"`
}

// MakeProductInventoryResponse makes ProductInventoryResponse from model.ProductInventory model.
func MakeProductInventoryResponse(m *model.ProductInventory) *ProductInventoryResponse {
return &ProductInventoryResponse{
Quantity: m.Quantity,
Expand Down
12 changes: 7 additions & 5 deletions backend/pkg/entity/shipping.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"github.com/billykore/kore/backend/pkg/types"
)

var shippingFee = map[string]types.Money{
"regular": 20_000,
"express": 30_000,
"sameDay": 50_000,
}

// GetShippingFee return fee base on the shipping type
func GetShippingFee(shippingType string) types.Money {
var shippingFee = map[string]types.Money{
"regular": 20_000,
"express": 30_000,
"sameDay": 50_000,
}
if v, ok := shippingFee[shippingType]; ok {
return v
}
Expand Down
10 changes: 2 additions & 8 deletions backend/pkg/log/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "log",
srcs = [
"log.go",
"provider.go",
],
srcs = ["log.go"],
importpath = "github.com/billykore/kore/backend/pkg/log",
visibility = ["//visibility:public"],
deps = [
"@com_github_google_wire//:wire",
"@org_uber_go_zap//:zap",
],
deps = ["@org_uber_go_zap//:zap"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ go_library(
"payload.go",
"rabbit.go",
],
importpath = "github.com/billykore/kore/backend/pkg/broker/rabbit",
importpath = "github.com/billykore/kore/backend/pkg/net/rabbit",
visibility = ["//visibility:public"],
deps = [
"//pkg/config",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ go_library(
srcs = [
"client.go",
"pool.go",
"provider.go",
"websocket.go",
],
importpath = "github.com/billykore/kore/backend/pkg/websocket",
importpath = "github.com/billykore/kore/backend/pkg/net/websocket",
visibility = ["//visibility:public"],
deps = [
"//pkg/log",
"@com_github_google_uuid//:uuid",
"@com_github_google_wire//:wire",
"@com_github_gorilla_websocket//:websocket",
],
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions backend/pkg/provider.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package pkg

import (
"github.com/billykore/kore/backend/pkg/broker/rabbit"
"github.com/billykore/kore/backend/pkg/db"
"github.com/billykore/kore/backend/pkg/log"
"github.com/billykore/kore/backend/pkg/websocket"
"github.com/billykore/kore/backend/pkg/net/rabbit"
"github.com/billykore/kore/backend/pkg/net/websocket"
"github.com/google/wire"
)

Expand Down
2 changes: 2 additions & 0 deletions backend/pkg/transaction/payment_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import "github.com/billykore/kore/backend/pkg/types"

// PaymentMethod is interface to represents payment service.
type PaymentMethod interface {
// Pay some amount of types.Money.
Pay(amount types.Money) (*PaymentResponse, error)
}

// Payment methods.
const (
gopay = "GoPay"
creditCard = "Credit Card"
Expand Down
2 changes: 1 addition & 1 deletion backend/services/auth/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM golang:1.22-alpine AS build
WORKDIR /app
COPY . .
COPY .. .
RUN go install github.com/google/wire/cmd/wire@latest && \
go mod download && \
wire ./services/todo/... && \
Expand Down
8 changes: 4 additions & 4 deletions backend/services/auth/cmd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ go_library(
"//pkg/config",
"//pkg/db",
"//pkg/log",
"//services/auth/handler",
"//services/auth/repo",
"//services/auth/server",
"//services/auth/usecase",
"//services/auth/internal/handler",
"//services/auth/internal/repo",
"//services/auth/internal/server",
"//services/auth/internal/usecase",
"@com_github_joho_godotenv//autoload",
"@com_github_labstack_echo_v4//:echo",
],
Expand Down
2 changes: 1 addition & 1 deletion backend/services/auth/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"github.com/billykore/kore/backend/pkg/config"
"github.com/billykore/kore/backend/services/auth/server"
"github.com/billykore/kore/backend/services/auth/internal/server"
_ "github.com/joho/godotenv/autoload"
)

Expand Down
8 changes: 4 additions & 4 deletions backend/services/auth/cmd/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ package main
import (
"github.com/billykore/kore/backend/pkg"
"github.com/billykore/kore/backend/pkg/config"
"github.com/billykore/kore/backend/services/auth/handler"
"github.com/billykore/kore/backend/services/auth/repo"
"github.com/billykore/kore/backend/services/auth/server"
"github.com/billykore/kore/backend/services/auth/usecase"
"github.com/billykore/kore/backend/services/auth/internal/handler"
"github.com/billykore/kore/backend/services/auth/internal/repo"
"github.com/billykore/kore/backend/services/auth/internal/server"
"github.com/billykore/kore/backend/services/auth/internal/usecase"
"github.com/google/wire"
"github.com/labstack/echo/v4"
)
Expand Down
8 changes: 4 additions & 4 deletions backend/services/auth/cmd/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ go_library(
"auth_handler.go",
"provider.go",
],
importpath = "github.com/billykore/kore/backend/services/auth/handler",
importpath = "github.com/billykore/kore/backend/services/auth/internal/handler",
visibility = ["//visibility:public"],
deps = [
"//pkg/entity",
"//services/auth/usecase",
"//services/auth/internal/usecase",
"@com_github_google_wire//:wire",
"@com_github_labstack_echo_v4//:echo",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package handler

import (
"github.com/billykore/kore/backend/pkg/entity"
"github.com/billykore/kore/backend/services/auth/usecase"
"github.com/billykore/kore/backend/services/auth/internal/usecase"
"github.com/labstack/echo/v4"
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go_library(
"provider.go",
"user_repo.go",
],
importpath = "github.com/billykore/kore/backend/services/auth/repo",
importpath = "github.com/billykore/kore/backend/services/auth/internal/repo",
visibility = ["//visibility:public"],
deps = [
"//pkg/model",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ go_library(
"provider.go",
"router.go",
],
importpath = "github.com/billykore/kore/backend/services/auth/server",
importpath = "github.com/billykore/kore/backend/services/auth/internal/server",
visibility = ["//visibility:public"],
deps = [
"//pkg/config",
"//pkg/log",
"//services/auth/handler",
"//services/auth/internal/handler",
"@com_github_google_wire//:wire",
"@com_github_labstack_echo_v4//:echo",
"@com_github_labstack_echo_v4//middleware",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package server
import (
"github.com/billykore/kore/backend/pkg/config"
"github.com/billykore/kore/backend/pkg/log"
"github.com/billykore/kore/backend/services/auth/handler"
"github.com/billykore/kore/backend/services/auth/internal/handler"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ go_library(
"auth_usecase.go",
"provider.go",
],
importpath = "github.com/billykore/kore/backend/services/auth/usecase",
importpath = "github.com/billykore/kore/backend/services/auth/internal/usecase",
visibility = ["//visibility:public"],
deps = [
"//pkg/codes",
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions backend/services/chat/cmd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ go_library(
deps = [
"//pkg/config",
"//pkg/log",
"//pkg/websocket",
"//services/chat/handler",
"//services/chat/repo",
"//services/chat/server",
"//services/chat/usecase",
"//pkg/net/websocket",
"//services/chat/internal/handler",
"//services/chat/internal/repo",
"//services/chat/internal/server",
"//services/chat/internal/usecase",
"@com_github_joho_godotenv//autoload",
"@com_github_labstack_echo_v4//:echo",
],
Expand Down
2 changes: 1 addition & 1 deletion backend/services/chat/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"github.com/billykore/kore/backend/pkg/config"
"github.com/billykore/kore/backend/services/chat/server"
"github.com/billykore/kore/backend/services/chat/internal/server"
_ "github.com/joho/godotenv/autoload"
)

Expand Down
8 changes: 4 additions & 4 deletions backend/services/chat/cmd/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ package main
import (
"github.com/billykore/kore/backend/pkg"
"github.com/billykore/kore/backend/pkg/config"
"github.com/billykore/kore/backend/services/chat/handler"
"github.com/billykore/kore/backend/services/chat/repo"
"github.com/billykore/kore/backend/services/chat/server"
"github.com/billykore/kore/backend/services/chat/usecase"
"github.com/billykore/kore/backend/services/chat/internal/handler"
"github.com/billykore/kore/backend/services/chat/internal/repo"
"github.com/billykore/kore/backend/services/chat/internal/server"
"github.com/billykore/kore/backend/services/chat/internal/usecase"
"github.com/google/wire"
"github.com/labstack/echo/v4"
)
Expand Down
12 changes: 6 additions & 6 deletions backend/services/chat/cmd/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ go_library(
"chat_handler.go",
"provider.go",
],
importpath = "github.com/billykore/kore/backend/services/chat/handler",
importpath = "github.com/billykore/kore/backend/services/chat/internal/handler",
visibility = ["//visibility:public"],
deps = [
"//pkg/websocket",
"//services/chat/usecase",
"//pkg/net/websocket",
"//services/chat/internal/usecase",
"@com_github_google_wire//:wire",
"@com_github_labstack_echo_v4//:echo",
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package handler

import (
"github.com/billykore/kore/backend/pkg/websocket"
"github.com/billykore/kore/backend/services/chat/usecase"
"github.com/billykore/kore/backend/pkg/net/websocket"
"github.com/billykore/kore/backend/services/chat/internal/usecase"
"github.com/labstack/echo/v4"
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ go_library(
"chat_repo.go",
"provider.go",
],
importpath = "github.com/billykore/kore/backend/services/chat/repo",
importpath = "github.com/billykore/kore/backend/services/chat/internal/repo",
visibility = ["//visibility:public"],
deps = [
"//pkg/model",
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit d6d390b

Please sign in to comment.