Skip to content

Commit

Permalink
Implemented Clean Architecture principles
Browse files Browse the repository at this point in the history
  • Loading branch information
VikashChauhan51 committed Jul 21, 2024
1 parent 8694edc commit ea0ba88
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 8 deletions.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# go-sample-api
Web api in golang with Gin farmwork
Web api in golang with Gin farmwork:

GO-SAMPLE-API
├───.github # GitHub-specific files
│ └───workflows # CI/CD workflows
├───.vscode # VSCode-specific files and configurations
├───cmd # Application entry points
│ └───api # Main API entry point
│ └───routes # Route configurations for the HTTP server
├───configs # Configuration files
├───docs # Documentation files
├───internal # Private application and library code
│ ├───controllers # HTTP handlers
│ ├───core # Core business logic
│ │ ├───entities # Core business entities
│ │ ├───interfaces # Interfaces for dependencies
│ │ │ ├───repositories # Repository interfaces
│ │ │ └───services # Service interfaces
│ │ └───usecases # Business logic use cases
│ ├───dto # Data transfer objects (request/response models)
│ └───infra # Infrastructure implementations
│ ├───databases # Database access implementations
│ ├───repositories # Implementations of repository interfaces
│ └───services # Implementations of service interfaces
├───pkg # Public library code
│ └───middlewares # Custom middleware implementations
├───test # Test-related files
└───vendor # Third-party dependencies (managed by `go mod`)



## Update swagger document
Expand Down
2 changes: 1 addition & 1 deletion cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"net/http"
"time"

"github.com/VikashChauhan51/go-sample-api/cmd/api/routes"
docs "github.com/VikashChauhan51/go-sample-api/docs"
"github.com/VikashChauhan51/go-sample-api/internal/routes"
"github.com/gin-gonic/gin"
swaggerfiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added internal/core/usecases/.keep
Empty file.
4 changes: 2 additions & 2 deletions internal/models/book.go → internal/dto/book.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package models
package dto

type Book struct {
ID uint `json:"id" xml:"id" gorm:"primary_key"`
ID uint `json:"id" xml:"id"`
Title string `json:"title" xml:"title"`
Author string `json:"author" xml:"author"`
}
8 changes: 4 additions & 4 deletions internal/infra/services/book_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package services
import (
"time"

"github.com/VikashChauhan51/go-sample-api/internal/models"
"github.com/VikashChauhan51/go-sample-api/internal/dto"
)

// Simulate fetching books from an external API
func FetchBooksAsync() ([]models.Book, error) {
func FetchBooksAsync() ([]dto.Book, error) {

r := make(chan []models.Book)
r := make(chan []dto.Book)
go func() {
time.Sleep(2 * time.Second) // Simulate external API call
books := []models.Book{
books := []dto.Book{
{ID: 1, Title: "The Lord of the Rings", Author: "J. R. R. Tolkien"},
{ID: 2, Title: "Pride and Prejudice", Author: "Jane Austen"},
{ID: 3, Title: "To Kill a Mockingbird", Author: "Harper Lee"},
Expand Down

0 comments on commit ea0ba88

Please sign in to comment.