Skip to content

goLang-Uzbekistan/goLang-project-layout-v2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 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:

Testing example getAlbums project:

https://go.dev/doc/tutorial/web-service-gin/


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 (/api, /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: deploy.sh

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

go build

Linux (amd64)

GOOS=linux GOARCH=amd64 go build -o app-linux-amd64

macOS (amd64)

GOOS=darwin GOARCH=amd64 go build -o app-darwin-amd64

macOS (arm64 - M1/M2)

GOOS=darwin GOARCH=arm64 go build -o app-darwin-arm64

Windows (amd64)

GOOS=windows GOARCH=amd64 go build -o app-windows-amd64.exe
  • /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, /testing: Proyektiz 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, CTRL + S dan keyin autoUpdate buladi...
go install github.com/air-verse/air@latest

Starting air

air

Contributors 2

  •  
  •