Internal state persistence #27

Merged
natercio merged 15 commits from internal-state-persistence into main 2026-08-03 00:33:07 +01:00
3 changed files with 11 additions and 9 deletions
Showing only changes of commit 43e086f752 - Show all commits
+1 -1
View File
@@ -98,7 +98,7 @@ func run(ctx context.Context) error {
func getReader(platform string, ofAPIKey string) (internal.RecordReader, error) { func getReader(platform string, ofAPIKey string) (internal.RecordReader, error) {
switch platform { switch platform {
case "trading212": case "trading212":
return trading212.NewRecordReader(os.Stdin, ofigi.NewClient(&http.Client{Timeout: 5 * time.Second}, ofAPIKey)), nil return trading212.NewRecordReader(os.Stdin, ofigi.NewOpenFIGI(&http.Client{Timeout: 5 * time.Second}, ofAPIKey)), nil
default: default:
return nil, fmt.Errorf("unsupported platform: %s", platform) return nil, fmt.Errorf("unsupported platform: %s", platform)
} }
+4 -3
View File
@@ -12,6 +12,7 @@ import (
"github.com/biter777/countries" "github.com/biter777/countries"
"github.com/nmoniz/any2anexoj/internal" "github.com/nmoniz/any2anexoj/internal"
"github.com/nmoniz/any2anexoj/internal/ofigi"
"github.com/shopspring/decimal" "github.com/shopspring/decimal"
) )
@@ -70,10 +71,10 @@ func (r Record) Nature() internal.Nature {
type RecordReader struct { type RecordReader struct {
reader *csv.Reader reader *csv.Reader
figi *internal.OpenFIGI figi *ofigi.Client
} }
func NewRecordReader(r io.Reader, f *internal.OpenFIGI) *RecordReader { func NewRecordReader(r io.Reader, f *ofigi.Client) *RecordReader {
return &RecordReader{ return &RecordReader{
reader: csv.NewReader(r), reader: csv.NewReader(r),
figi: f, figi: f,
@@ -187,7 +188,7 @@ func (rr RecordReader) ReadRecord(ctx context.Context) (internal.Record, error)
} }
} }
func figiNatureGetter(ctx context.Context, of *internal.OpenFIGI, isin string) func() internal.Nature { func figiNatureGetter(ctx context.Context, of *ofigi.Client, isin string) func() internal.Nature {
return sync.OnceValue(func() internal.Nature { return sync.OnceValue(func() internal.Nature {
secType, err := of.SecurityTypeByISIN(ctx, isin) secType, err := of.SecurityTypeByISIN(ctx, isin)
if err != nil { if err != nil {
+6 -5
View File
@@ -9,6 +9,7 @@ import (
"time" "time"
"github.com/nmoniz/any2anexoj/internal" "github.com/nmoniz/any2anexoj/internal"
"github.com/nmoniz/any2anexoj/internal/ofigi"
"github.com/shopspring/decimal" "github.com/shopspring/decimal"
) )
@@ -221,7 +222,7 @@ func TestRecordReader_ReadRecord_Split(t *testing.T) {
func Test_figiNatureGetter(t *testing.T) { func Test_figiNatureGetter(t *testing.T) {
tests := []struct { tests := []struct {
name string // description of this test case name string // description of this test case
of *internal.OpenFIGI of *ofigi.Client
want internal.Nature want internal.Nature
}{ }{
{ {
@@ -272,7 +273,7 @@ func (f RoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
return f(req) return f(req)
} }
func NewFigiClientSecurityTypeStub(t testing.TB, securityType string) *internal.OpenFIGI { func NewFigiClientSecurityTypeStub(t testing.TB, securityType string) *ofigi.Client {
t.Helper() t.Helper()
c := &http.Client{ c := &http.Client{
@@ -287,10 +288,10 @@ func NewFigiClientSecurityTypeStub(t testing.TB, securityType string) *internal.
}), }),
} }
return internal.NewOpenFIGI(c, "") return ofigi.NewOpenFIGI(c, "")
} }
func NewFigiClientErrorStub(t testing.TB, err error) *internal.OpenFIGI { func NewFigiClientErrorStub(t testing.TB, err error) *ofigi.Client {
t.Helper() t.Helper()
c := &http.Client{ c := &http.Client{
@@ -300,5 +301,5 @@ func NewFigiClientErrorStub(t testing.TB, err error) *internal.OpenFIGI {
}), }),
} }
return internal.NewOpenFIGI(c, "") return ofigi.NewOpenFIGI(c, "")
} }