move H to pkg
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"io"
|
||||
"servicea/internal/app"
|
||||
"pkg"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -74,7 +74,7 @@ func (c *CSV) Parse(r io.Reader) ([]MeteoData, []RejectedMeteoData, error) {
|
||||
|
||||
rowValue := strings.Join(row, ";")
|
||||
|
||||
record := make(app.H)
|
||||
record := make(pkg.H)
|
||||
for i, value := range row {
|
||||
if i < len(header) {
|
||||
record[header[i]] = value
|
||||
@@ -104,7 +104,7 @@ func (c *CSV) Parse(r io.Reader) ([]MeteoData, []RejectedMeteoData, error) {
|
||||
return meteoDataList, rejectedDataList, nil
|
||||
}
|
||||
|
||||
func normalize(record app.H) (*MeteoData, error) {
|
||||
func normalize(record pkg.H) (*MeteoData, error) {
|
||||
meteoData := &MeteoData{}
|
||||
|
||||
var err error
|
||||
@@ -142,7 +142,7 @@ func normalize(record app.H) (*MeteoData, error) {
|
||||
return meteoData, nil
|
||||
}
|
||||
|
||||
func parseDate(record app.H, key string, errMissing error) (time.Time, error) {
|
||||
func parseDate(record pkg.H, key string, errMissing error) (time.Time, error) {
|
||||
if str, ok := record[key].(string); ok && str != "" {
|
||||
t, err := time.Parse("2006/01/02", str)
|
||||
if err != nil {
|
||||
@@ -153,14 +153,14 @@ func parseDate(record app.H, key string, errMissing error) (time.Time, error) {
|
||||
return time.Time{}, errMissing
|
||||
}
|
||||
|
||||
func parseString(record app.H, key string, errMissing error) (string, error) {
|
||||
func parseString(record pkg.H, key string, errMissing error) (string, error) {
|
||||
if str, ok := record[key].(string); ok && str != "" {
|
||||
return str, nil
|
||||
}
|
||||
return "", errMissing
|
||||
}
|
||||
|
||||
func parseFloatField(record app.H, key string, errMissing error) (float32, error) {
|
||||
func parseFloatField(record pkg.H, key string, errMissing error) (float32, error) {
|
||||
if str, ok := record[key].(string); ok && str != "" {
|
||||
str = strings.Replace(str, ",", ".", 1)
|
||||
f, err := strconv.ParseFloat(str, 32)
|
||||
@@ -172,7 +172,7 @@ func parseFloatField(record app.H, key string, errMissing error) (float32, error
|
||||
return 0, errMissing
|
||||
}
|
||||
|
||||
func parseIntField(record app.H, key string, errMissing error) (int, error) {
|
||||
func parseIntField(record pkg.H, key string, errMissing error) (int, error) {
|
||||
if str, ok := record[key].(string); ok && str != "" {
|
||||
str = strings.TrimSpace(str)
|
||||
i, err := strconv.Atoi(str)
|
||||
|
||||
Reference in New Issue
Block a user