diff --git a/internal/storage/model.go b/internal/storage/model.go new file mode 100644 index 0000000..1db1b71 --- /dev/null +++ b/internal/storage/model.go @@ -0,0 +1,83 @@ +package storage + +import "time" + +//CurrentWeatherDetail +type CurrentWeatherDetail struct { + // https://openweathermap.org/weather-conditions#Weather-Condition-Codes-2 + id int + // Group of weather parameters (Rain, Snow, Extreme etc.) + main string + // Weather condition within the group (full list of weather conditions). Get the output in your language + description string + // Weather icon id. How to get icons + icon string +} + +//CurrentWeather +type CurrentWeather struct { + // Geographical coordinates of the location (latitude) + latitude float32 + + // Geographical coordinates of the location (longitude) + longitude float32 + + // Timezone name for the requested location + timezone string + + // Shift in seconds from UTC + timezone_offset int + + // Current time, Unix, UTC + timestamp time.Time + + // Sunrise time, Unix, UTC + sunrise time.Time + + // Sunset time, Unix, UTC + sunset time.Time + + // Temperature. Units - default: kelvin, metric: Celsius, imperial: Fahrenheit. How to change units used + temperature int + + // Temperature. This temperature parameter accounts for the human perception of weather. + // Units – default: kelvin, metric: Celsius, imperial: Fahrenheit. + feels_like float32 + + // Atmospheric pressure on the sea level, hPa + pressure int + + // Humidity, % + humidity int + + // Atmospheric temperature (varying according to pressure and humidity) below which water droplets begin to condense and dew can form. + // Units – default: kelvin, metric: Celsius, imperial: Fahrenheit. + dew_point float32 + + // Cloudiness, % + clouds int + + // Current UV index + uvi int + + // Average visibility, metres + visibility int + + // Wind speed. Wind speed. Units – default: metre/sec, metric: metre/sec, imperial: miles/hour. How to change units used + wind_speed float32 + + // Wind gust. Units – default: metre/sec, metric: metre/sec, imperial: miles/hour. How to change units used (rafale) + wind_gust int + + // Wind direction, degrees (meteorological) + wind_deg int + + // Rain volume for last hour, mm + rainLastHour int + + // Snow volume for last hour, mm + snowLastHour int + + // detail about weather condition + detaiil CurrentWeatherDetail +} diff --git a/internal/storage/s3.go b/internal/storage/s3.go index d0c3044..3252a15 100644 --- a/internal/storage/s3.go +++ b/internal/storage/s3.go @@ -2,6 +2,7 @@ package storage import ( "context" + "encoding/json" "fmt" "go/weather/pkg/logger" "io" @@ -75,14 +76,21 @@ func (ss *S3Storage) Store(ctx context.Context, content io.Reader) { } //GetAtDate retrieve one data from bucket -func (ss *S3Storage) GetAtDate(ctx context.Context, atDate time.Time) *minio.Object { +func (ss *S3Storage) GetAtDate(ctx context.Context, atDate time.Time) *CurrentWeather { filename := fmt.Sprintf("%s.json", atDate.Format(time.RFC3339)) reader, err := ss.Session.GetObject(ctx, ss.S3Config.BucketName, filename, minio.GetObjectOptions{}) if err != nil { ss.logger.Error("Storage get s3Object failed", zap.Error(err)) return nil } - return reader + + dec := json.NewDecoder(reader) + var raw interface{} + dec.Decode(raw) + + return &CurrentWeather{ + latitude: raw.lat, + } } type Streamable interface{} diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index 92f0e9c..cec0ce2 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -125,6 +125,8 @@ func (wl *WeatherLogger) LogHTTPRequest(r *http.Request) { // zap.Int64("http.request.bytes", r.Header ContentLength), // total body+header len zap.String("http.request.mime_type", r.Header.Get(headers.ContentType)), zap.String("url.path", r.RequestURI), + zap.String("url.port", r.URL.Port()), + zap.String("url.query", r.URL.RawQuery), // zap.String(""), }...)