Skip to content

goLang-Uzbekistan/goLang-project-layout-v2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goLang Proyekt yaratish strukturasi:

Hammaga Assalomu Alaykum) Sabr qilib ko'ring videoni va bu video faqat proyektga emas, shaxsiy hayotingizdaham foyda bo'ladi degan umidaman)

Maslahat beraman ko'ring shu videoni:


Golang standard project layout

  • /cmd yoki /app: bu folder da main.go file li turadi.
/cmd
├── GIN
│   ├── main.go
│   └── go.mod
└── Gorilla
    ├── main.go
    └── go.mod
  • man tahminan misol keltirayapman 😁
  • /internal: bu folder'da /handlers, /routes, /models, /middleware, /database xullas asosiy proyetga oid kodlar buladi.
/internal
├── auth
│   ├── auth.go
│   └── auth_test.go
└── storage
    ├── storage.go
    └── storage_test.go
  • /vendor: go mod vendor - bu go.mod barcha packages offline yuklab oladi)
/vendor
├── github.com
│   └── someuser
│       └── somepackage
│           ├── somefile.go
│           └── ...
└── golang.org
    └── x
        └── net
            ├── somefile.go
            └── ...
  • /api: OpenAPI/Swagger spetsifikatsiyalari, JSON sxema fayllari yoki protokolni saqlash fayllari turadi.
/api
├── openapi.yaml
├── swagger.json
├── other.json
└── protobuf
    ├── messages.proto
    └── services.proto
  • /web: Veb statik fayllar: /img, /css, /js, /.html
/web
├── static
│   ├── css
│   │   ├── style.css
│   ├── js
│   │   ├── script.js
│   └── images
│       ├── logo.png
└── templates
    ├── layout.html
    ├── index.html
    └── about.html
  • /configs: Konfiguratsiya fayli shablonlari yoki standart konfiguratsiyalar.
/configs
├── config.yaml
├── config.toml
└── example.env

  • /scripts: voqti kelsa tushunib olasiz 😁
/scripts
├── build.sh
├── deploy.sh
└── test.sh

misol: build.sh

echo "Building the application..."
go build -o myapp ./cmd/myapp
echo "Build completed!"

misol: deploy.sh

echo "Deploying the application..."
git pull origin main
./build.sh
echo "Deployment completed!"

  • /build: agar Proyektiz finalga kelsa, ushanda foydasi tegadi go build
/build
├── docker
│   ├── Dockerfile
│   └── entrypoint.sh
├── scripts
│   ├── build.sh
│   └── deploy.sh
└── artifacts
    └── README.md
  • /deployments: IaaS, PaaS, tizim va docker-konteyner va boshqa hosting deploy konfiguratsiyalari saqlanadi, yoki boshqa fayllar.
/deployments
├── docker
│   ├── Dockerfile
│   └── docker-compose.yml
├── k8s
│   ├── deployment.yaml
│   ├── service.yaml
│   └── ingress.yaml
├── scripts
│   ├── deploy.sh
│   └── rollback.sh
└── README.md
  • /test: Proyektiz sinovdan o'tkazish/testing kodlari.
/test
├── integration_test.go
└── test_data
    ├── sample_input.json
    └── sample_output.json

  • /tools: Ushbu Proyektiz uchun yordamchi instrumentlar. Eslatma: Ushbu instrumentlar Proyektizni o'ziga tegishli emas.
/tools
├── build
│   └── build.go
├── lint
│   └── lint.go
└── format
    └── format.go

// tools/build/build.go

package main

import (
    "fmt"
    "os"
    "os/exec"
)

func main() {
    fmt.Println("Building the project...")
    cmd := exec.Command("go", "build", "./cmd/myapp")
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr
    if err := cmd.Run(); err != nil {
        fmt.Printf("Error building application: %v\n", err)
        os.Exit(1)
    }
    fmt.Println("Build completed successfully!")
}
  • /docs: Proyektizga oid docslar saqlab quyishingiz mumkin,
/docs
├── architecture.md
├── API.md
├── getting_started.md
└── examples
    ├── basic_usage.md
    └── advanced_features.md
  • /examples: Proyektizga oid examplelarni saqlab quyishingiz mumkin, xullas voqti kelsa tushunib olasiz 😁yoki esdan chiqaring xD
/examples
├── basic_usage.go
├── advanced_usage.go
└── cli_example.go

va

  • README.md: Proyektiz tushuntiruvchi fayl, Proyektiz maqsadi yoki kelajakdagi rejalariz/function yozib quyishingiz mumkin.
  • Makefile: Proyektiz build qilish va sinovdan o'tkazish bo'yicha ko'rsatmalar. makefile

autoUpdate: air

  1. Plus tarafi: agar Windows/Mac/Linux Terminal autoUpdate air buladi va juda qulay.
  2. Minus tarafi: agar siz goLand ishlatsangiz xar safar (CTRL + S) bosib zzz bulib ketasizlar xD
go install github.com/air-verse/air@latest

Starting air

air

Testing the API for terminal

docs: https://www.codepedia.org/ama/how-to-test-a-rest-api-from-command-line-with-curl/

curl -I http://localhost:8000/api/healthChecker ## GET request
curl -i -X HEAD http://localhost:8000/api/healthChecker ## HEAD request
curl -X GET "http://localhost:8000/api/healthChecker" -H "accept: application/json" ## GET request

Agar siz uni yanada chiroyli ko'rsatishni istasangiz, jq tavsiya qilaman:

curl http://localhost:8000/api/healthChecker | jq . ## GET request

Curl options

-I or --head - fetch the headers only
-i, --include - include the HTTP response headers in the output
-X, --request - specify a custom request method to use when communicating with the HTTP server (GET, PUT, DELETE&)