-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from underbek/feature/parse_broken_sources
Fixed parsing broken sources
- Loading branch information
Showing
14 changed files
with
233 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package transport | ||
|
||
import "github.com/google/uuid" | ||
|
||
type User struct { | ||
UUID uuid.UUID `json:"uuid" map:"id"` | ||
Name string `json:"name" map:"name"` | ||
Age string `map:"age"` | ||
ChildCount *string `map:"children"` | ||
} | ||
|
||
type BrokenUser [T]struct { | ||
UUID uuid.UUID `json:"uuid" map:"id"` | ||
Name string `json:"name" map:"name"` | ||
Age string `map:"age"` | ||
ChildCount *string `map:"children"` | ||
} | ||
|
||
type BrokenUser2 struct { | ||
UUID `json:"uuid"` | ||
} |
19 changes: 19 additions & 0 deletions
19
_test_data/mapper/convertors_with_broken/user_conversion_functions.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package convertors | ||
|
||
import ( | ||
"github.com/google/uuid" | ||
"github.com/shopspring/decimal" | ||
"golang.org/x/exp/constraints" | ||
) | ||
|
||
func CustomUUIDToInteger[T constraints.Integer](from uuid.UUID) T { | ||
return T(from.ID()) | ||
} | ||
|
||
func CustomIntegerToUUID[T constraints.Integer](from T) uuid.UUID { | ||
return uuid.New() | ||
} | ||
|
||
func BrokenConvertor(from decimal.Decimal) int { | ||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package logger | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
) | ||
|
||
const depth = 2 | ||
|
||
type Logger interface { | ||
Info(v ...any) | ||
Warn(v ...any) | ||
Error(v ...any) | ||
Fatal(v ...any) | ||
} | ||
|
||
type logger struct { | ||
info *log.Logger | ||
warn *log.Logger | ||
error *log.Logger | ||
} | ||
|
||
func New() Logger { | ||
return &logger{ | ||
info: log.New(os.Stderr, "INFO: ", log.Ldate|log.Ltime), | ||
warn: log.New(os.Stderr, "WARNING: ", log.Ldate|log.Ltime), | ||
error: log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime), | ||
} | ||
} | ||
|
||
func (l *logger) Info(v ...any) { | ||
_ = l.info.Output(depth, fmt.Sprint(v...)) | ||
} | ||
|
||
func (l *logger) Warn(v ...any) { | ||
_ = l.warn.Output(depth, fmt.Sprint(v...)) | ||
} | ||
|
||
func (l *logger) Error(v ...any) { | ||
_ = l.error.Output(depth, fmt.Sprint(v...)) | ||
} | ||
|
||
func (l *logger) Fatal(v ...any) { | ||
_ = l.error.Output(depth, fmt.Sprint(v...)) | ||
os.Exit(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
"github.com/underbek/datamapper/logger" | ||
"github.com/underbek/datamapper/mapper" | ||
"github.com/underbek/datamapper/options" | ||
) | ||
|
||
func main() { | ||
lg := logger.New() | ||
opts, err := options.ParseOptions() | ||
if err != nil { | ||
os.Exit(1) | ||
lg.Fatal(err) | ||
} | ||
|
||
err = mapper.MapModels(opts) | ||
err = mapper.MapModels(lg, opts) | ||
if err != nil { | ||
log.Fatal(err) | ||
lg.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.