s/import/include/

Signed-off-by: RouxAntoine <antoinroux@hotmail.fr>
This commit is contained in:
RouxAntoine 2022-12-23 19:05:34 +01:00
parent 56c81bce58
commit eb4226c003
Signed by: antoine
GPG Key ID: 098FB66FC0475E70
3 changed files with 95 additions and 2 deletions

83
internal/storage/model.go Normal file
View File

@ -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
}

View File

@ -2,6 +2,7 @@ package storage
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"go/weather/pkg/logger" "go/weather/pkg/logger"
"io" "io"
@ -75,14 +76,21 @@ func (ss *S3Storage) Store(ctx context.Context, content io.Reader) {
} }
//GetAtDate retrieve one data from bucket //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)) filename := fmt.Sprintf("%s.json", atDate.Format(time.RFC3339))
reader, err := ss.Session.GetObject(ctx, ss.S3Config.BucketName, filename, minio.GetObjectOptions{}) reader, err := ss.Session.GetObject(ctx, ss.S3Config.BucketName, filename, minio.GetObjectOptions{})
if err != nil { if err != nil {
ss.logger.Error("Storage get s3Object failed", zap.Error(err)) ss.logger.Error("Storage get s3Object failed", zap.Error(err))
return nil return nil
} }
return reader
dec := json.NewDecoder(reader)
var raw interface{}
dec.Decode(raw)
return &CurrentWeather{
latitude: raw.lat,
}
} }
type Streamable interface{} type Streamable interface{}

View File

@ -125,6 +125,8 @@ func (wl *WeatherLogger) LogHTTPRequest(r *http.Request) {
// zap.Int64("http.request.bytes", r.Header ContentLength), // total body+header len // 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("http.request.mime_type", r.Header.Get(headers.ContentType)),
zap.String("url.path", r.RequestURI), zap.String("url.path", r.RequestURI),
zap.String("url.port", r.URL.Port()),
zap.String("url.query", r.URL.RawQuery),
// zap.String(""), // zap.String(""),
}...) }...)