goLang-project-layout-v2

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

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,
```text
/docs
├── architecture.md
├── API.md
├── getting_started.md
└── examples
    ├── basic_usage.md
    └── advanced_features.md

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&)