كيفية تهيئة البنية المتداخلة (nested struct) بشكل صحيح في Go؟
مرحباً بالجميع! أنا مبتدئ في Go، وقد واجهت مشكلة في تهيئة البنى المتداخلة. أكتب مشروعاً صغيراً للعمل مع API الطقس.
لدي هذه البنى:
```go
type WeatherResponse struct {
Location Location
Current CurrentWeather
}
type Location struct {
Name string
Country string
Lat float64
Lon float64
}
type CurrentWeather struct {
Temperature float64
Humidity int
Condition string
Wind WindInfo
}
type WindInfo struct {
Speed float64
Deg int
}
```
أحاول إنشاء مثيل من `WeatherResponse` وملء جميع الحقول فوراً، لكني أحصل على أخطاء في الترجمة. جربت خيارات مختلفة:
```go
// الخيار 1 - لا يعمل
data := WeatherResponse{
Location.Name: "Moscow",
Location.Country: "Russia",
CurrentWeather.Temperature: 22.5,
}
// الخيار 2 - لا يعمل أيضاً
data := WeatherResponse{
Location{"Moscow", "Russia", 55.75, 37.62},
Current