From cac7fb1dc14dce64dbcd42c3ea394a018dfbe1c6 Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Fri, 29 Dec 2023 19:53:56 +0100 Subject: [PATCH] Cleanup (#277) Some cleanup of imports, headers, licences, etc. --- cli/cli.go | 3 +-- cli/commands/account.go | 19 ++++++++++++++++- cli/commands/portfolio.go | 8 +++---- cli/commands/securities.go | 8 +++---- cmd/mgo/mgo.go | 6 +++--- finance/calculation.go | 2 +- finance/calculation_test.go | 5 +++-- gen/account_sql.go | 1 + gen/currency.go | 1 + gen/portfolio.go | 1 + gen/portfolio_sql.go | 2 ++ gen/portfolio_test.go | 16 ++++++++++++++ gen/securities_sql.go | 2 ++ import/csv/csv_importer.go | 4 ++-- import/csv/csv_importer_test.go | 3 ++- internal/persistence.go | 19 +++++++++++++++-- money-gopher.code-workspace | 2 +- service/internal/crud/crud_requests.go | 4 ++-- service/internal/crud/crud_requests_test.go | 21 +++++++++++++++++-- service/portfolio/account.go | 6 +++--- service/portfolio/account_test.go | 5 +++-- service/portfolio/portfolio.go | 2 +- service/portfolio/portfolio_test.go | 5 +++-- service/portfolio/service_test.go | 3 ++- service/portfolio/snapshot_test.go | 8 +++---- service/portfolio/transactions_test.go | 5 +++-- service/securities/quote.go | 4 ++-- service/securities/quote_provider_ing_test.go | 3 ++- service/securities/quote_provider_yf_test.go | 3 ++- service/securities/quote_test.go | 8 +++---- service/securities/securities_test.go | 5 +++-- 31 files changed, 132 insertions(+), 52 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index e0f5f381..10028fbe 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -14,8 +14,7 @@ // // This file is part of The Money Gopher. -// repl provides a simple Read-Eval-Print-Loop (REPL) to issue commands to an -// integrated client. +// cli provides the commands for a simple CLI. package cli import ( diff --git a/cli/commands/account.go b/cli/commands/account.go index 3ab123b9..5123b83f 100644 --- a/cli/commands/account.go +++ b/cli/commands/account.go @@ -1,12 +1,29 @@ +// Copyright 2023 Christian Banse +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// This file is part of The Money Gopher. + package commands import ( "context" "fmt" - "connectrpc.com/connect" "github.com/oxisto/money-gopher/cli" portfoliov1 "github.com/oxisto/money-gopher/gen" + + "connectrpc.com/connect" ) type BankAccountCmd struct { diff --git a/cli/commands/portfolio.go b/cli/commands/portfolio.go index 97076378..0231f3c1 100644 --- a/cli/commands/portfolio.go +++ b/cli/commands/portfolio.go @@ -25,15 +25,15 @@ import ( "strings" "time" - "github.com/fatih/color" - kongcompletion "github.com/jotaen/kong-completion" "github.com/oxisto/money-gopher/cli" portfoliov1 "github.com/oxisto/money-gopher/gen" "github.com/oxisto/money-gopher/gen/portfoliov1connect" - "github.com/posener/complete" - "google.golang.org/protobuf/types/known/timestamppb" "connectrpc.com/connect" + "github.com/fatih/color" + kongcompletion "github.com/jotaen/kong-completion" + "github.com/posener/complete" + "google.golang.org/protobuf/types/known/timestamppb" ) type PortfolioCmd struct { diff --git a/cli/commands/securities.go b/cli/commands/securities.go index f779cc41..7ea1033e 100644 --- a/cli/commands/securities.go +++ b/cli/commands/securities.go @@ -22,13 +22,13 @@ import ( "fmt" "net/http" - "connectrpc.com/connect" - kongcompletion "github.com/jotaen/kong-completion" - "github.com/posener/complete" - "github.com/oxisto/money-gopher/cli" portfoliov1 "github.com/oxisto/money-gopher/gen" "github.com/oxisto/money-gopher/gen/portfoliov1connect" + + "connectrpc.com/connect" + kongcompletion "github.com/jotaen/kong-completion" + "github.com/posener/complete" ) type SecurityCmd struct { diff --git a/cmd/mgo/mgo.go b/cmd/mgo/mgo.go index 0a570e40..c8df6a5b 100644 --- a/cmd/mgo/mgo.go +++ b/cmd/mgo/mgo.go @@ -19,11 +19,11 @@ package main import ( "os" - "github.com/alecthomas/kong" - kongcompletion "github.com/jotaen/kong-completion" - "github.com/oxisto/money-gopher/cli" "github.com/oxisto/money-gopher/cli/commands" + + "github.com/alecthomas/kong" + kongcompletion "github.com/jotaen/kong-completion" ) func main() { diff --git a/finance/calculation.go b/finance/calculation.go index 4f342c7f..a7699c10 100644 --- a/finance/calculation.go +++ b/finance/calculation.go @@ -14,7 +14,7 @@ // // This file is part of The Money Gopher. -// package portfolio contains all kinds of different finance calculations. +// package finance contains all kinds of different finance calculations. package finance import ( diff --git a/finance/calculation_test.go b/finance/calculation_test.go index d64e8455..811d8eea 100644 --- a/finance/calculation_test.go +++ b/finance/calculation_test.go @@ -14,14 +14,15 @@ // // This file is part of The Money Gopher. -// package portfolio contains all kinds of different finance calculations. +// package finance contains all kinds of different finance calculations. package finance import ( "testing" - "github.com/oxisto/assert" portfoliov1 "github.com/oxisto/money-gopher/gen" + + "github.com/oxisto/assert" ) func TestNewCalculation(t *testing.T) { diff --git a/gen/account_sql.go b/gen/account_sql.go index ced6c85e..5cc34c64 100644 --- a/gen/account_sql.go +++ b/gen/account_sql.go @@ -13,6 +13,7 @@ // limitations under the License. // // This file is part of The Money Gopher. + package portfoliov1 import ( diff --git a/gen/currency.go b/gen/currency.go index 3772e74f..62e2230a 100644 --- a/gen/currency.go +++ b/gen/currency.go @@ -13,6 +13,7 @@ // limitations under the License. // // This file is part of The Money Gopher. + package portfoliov1 import ( diff --git a/gen/portfolio.go b/gen/portfolio.go index 51da4595..c709cf48 100644 --- a/gen/portfolio.go +++ b/gen/portfolio.go @@ -13,6 +13,7 @@ // limitations under the License. // // This file is part of The Money Gopher. + package portfoliov1 import ( diff --git a/gen/portfolio_sql.go b/gen/portfolio_sql.go index 24eb23a4..943eebc4 100644 --- a/gen/portfolio_sql.go +++ b/gen/portfolio_sql.go @@ -13,6 +13,7 @@ // limitations under the License. // // This file is part of The Money Gopher. + package portfoliov1 import ( @@ -22,6 +23,7 @@ import ( "time" "github.com/oxisto/money-gopher/persistence" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) diff --git a/gen/portfolio_test.go b/gen/portfolio_test.go index a6bb1506..c18f059e 100644 --- a/gen/portfolio_test.go +++ b/gen/portfolio_test.go @@ -1,3 +1,19 @@ +// Copyright 2023 Christian Banse +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// This file is part of The Money Gopher. + package portfoliov1 import ( diff --git a/gen/securities_sql.go b/gen/securities_sql.go index 6a762c88..1bb2192c 100644 --- a/gen/securities_sql.go +++ b/gen/securities_sql.go @@ -13,6 +13,7 @@ // limitations under the License. // // This file is part of The Money Gopher. + package portfoliov1 import ( @@ -21,6 +22,7 @@ import ( "time" "github.com/oxisto/money-gopher/persistence" + "google.golang.org/protobuf/types/known/timestamppb" ) diff --git a/import/csv/csv_importer.go b/import/csv/csv_importer.go index e6d38374..0a443a0b 100644 --- a/import/csv/csv_importer.go +++ b/import/csv/csv_importer.go @@ -39,11 +39,11 @@ import ( "strings" "time" - "github.com/lmittmann/tint" moneygopher "github.com/oxisto/money-gopher" portfoliov1 "github.com/oxisto/money-gopher/gen" - "github.com/oxisto/money-gopher/service/securities" + "github.com/lmittmann/tint" + "github.com/oxisto/money-gopher/service/securities" "google.golang.org/protobuf/types/known/timestamppb" ) diff --git a/import/csv/csv_importer_test.go b/import/csv/csv_importer_test.go index 6dc984a0..19dccea0 100644 --- a/import/csv/csv_importer_test.go +++ b/import/csv/csv_importer_test.go @@ -23,9 +23,10 @@ import ( "testing" "time" - "github.com/oxisto/assert" moneygopher "github.com/oxisto/money-gopher" portfoliov1 "github.com/oxisto/money-gopher/gen" + + "github.com/oxisto/assert" "github.com/oxisto/money-gopher/service/securities" "google.golang.org/protobuf/types/known/timestamppb" ) diff --git a/internal/persistence.go b/internal/persistence.go index d28dd5de..02507667 100644 --- a/internal/persistence.go +++ b/internal/persistence.go @@ -1,3 +1,19 @@ +// Copyright 2023 Christian Banse +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// This file is part of The Money Gopher. + package internal import ( @@ -25,10 +41,9 @@ func NewTestDB(t *testing.T, inits ...func(db *persistence.DB)) (db *persistence func NewTestDBOps[T persistence.StorageObject](t *testing.T, inits ...func(ops persistence.StorageOperations[T])) (ops persistence.StorageOperations[T]) { var ( - db *persistence.DB + db = NewTestDB(t) ) - db = NewTestDB(t) ops = persistence.Ops[T](db) for _, init := range inits { diff --git a/money-gopher.code-workspace b/money-gopher.code-workspace index 04b51a42..f27af36e 100644 --- a/money-gopher.code-workspace +++ b/money-gopher.code-workspace @@ -41,6 +41,6 @@ "tailwindcss", "timestamppb" ], - "editor.tabSize": 2 + "editor.tabSize": 4 } } \ No newline at end of file diff --git a/service/internal/crud/crud_requests.go b/service/internal/crud/crud_requests.go index 8aa8357a..f506e83e 100644 --- a/service/internal/crud/crud_requests.go +++ b/service/internal/crud/crud_requests.go @@ -24,10 +24,10 @@ import ( "log/slog" "strings" + "github.com/oxisto/money-gopher/persistence" + "connectrpc.com/connect" "google.golang.org/protobuf/types/known/emptypb" - - "github.com/oxisto/money-gopher/persistence" ) func Create[T any, S persistence.StorageObject](obj S, op persistence.StorageOperations[S], convert func(obj S) *T) (res *connect.Response[T], err error) { diff --git a/service/internal/crud/crud_requests_test.go b/service/internal/crud/crud_requests_test.go index 710665e7..5d7c827e 100644 --- a/service/internal/crud/crud_requests_test.go +++ b/service/internal/crud/crud_requests_test.go @@ -1,3 +1,19 @@ +// Copyright 2023 Christian Banse +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// This file is part of The Money Gopher. + package crud import ( @@ -5,11 +21,12 @@ import ( "reflect" "testing" - "connectrpc.com/connect" - "github.com/oxisto/assert" portfoliov1 "github.com/oxisto/money-gopher/gen" "github.com/oxisto/money-gopher/internal" "github.com/oxisto/money-gopher/persistence" + + "connectrpc.com/connect" + "github.com/oxisto/assert" "google.golang.org/protobuf/types/known/emptypb" ) diff --git a/service/portfolio/account.go b/service/portfolio/account.go index 88060208..49292c67 100644 --- a/service/portfolio/account.go +++ b/service/portfolio/account.go @@ -19,11 +19,11 @@ package portfolio import ( "context" - "connectrpc.com/connect" - "google.golang.org/protobuf/types/known/emptypb" - portfoliov1 "github.com/oxisto/money-gopher/gen" + + "connectrpc.com/connect" "github.com/oxisto/money-gopher/service/internal/crud" + "google.golang.org/protobuf/types/known/emptypb" ) var bankAccountSetter = func(obj *portfoliov1.BankAccount) *portfoliov1.BankAccount { diff --git a/service/portfolio/account_test.go b/service/portfolio/account_test.go index 436b9c28..d7f29038 100644 --- a/service/portfolio/account_test.go +++ b/service/portfolio/account_test.go @@ -20,12 +20,13 @@ import ( "context" "testing" - "connectrpc.com/connect" - "github.com/oxisto/assert" portfoliov1 "github.com/oxisto/money-gopher/gen" "github.com/oxisto/money-gopher/gen/portfoliov1connect" "github.com/oxisto/money-gopher/internal" "github.com/oxisto/money-gopher/persistence" + + "connectrpc.com/connect" + "github.com/oxisto/assert" "google.golang.org/protobuf/types/known/fieldmaskpb" ) diff --git a/service/portfolio/portfolio.go b/service/portfolio/portfolio.go index 61096092..a0a77f0d 100644 --- a/service/portfolio/portfolio.go +++ b/service/portfolio/portfolio.go @@ -21,9 +21,9 @@ import ( portfoliov1 "github.com/oxisto/money-gopher/gen" "github.com/oxisto/money-gopher/service/internal/crud" - "google.golang.org/protobuf/types/known/emptypb" "connectrpc.com/connect" + "google.golang.org/protobuf/types/known/emptypb" ) var portfolioSetter = func(obj *portfoliov1.Portfolio) *portfoliov1.Portfolio { diff --git a/service/portfolio/portfolio_test.go b/service/portfolio/portfolio_test.go index cf5d7d30..dba0a652 100644 --- a/service/portfolio/portfolio_test.go +++ b/service/portfolio/portfolio_test.go @@ -21,12 +21,13 @@ import ( "testing" "time" - "connectrpc.com/connect" - "github.com/oxisto/assert" portfoliov1 "github.com/oxisto/money-gopher/gen" "github.com/oxisto/money-gopher/gen/portfoliov1connect" "github.com/oxisto/money-gopher/internal" "github.com/oxisto/money-gopher/persistence" + + "connectrpc.com/connect" + "github.com/oxisto/assert" "google.golang.org/protobuf/types/known/fieldmaskpb" "google.golang.org/protobuf/types/known/timestamppb" ) diff --git a/service/portfolio/service_test.go b/service/portfolio/service_test.go index d9284762..b372883d 100644 --- a/service/portfolio/service_test.go +++ b/service/portfolio/service_test.go @@ -19,9 +19,10 @@ package portfolio import ( "testing" - "github.com/oxisto/assert" "github.com/oxisto/money-gopher/gen/portfoliov1connect" "github.com/oxisto/money-gopher/internal" + + "github.com/oxisto/assert" ) func TestNewService(t *testing.T) { diff --git a/service/portfolio/snapshot_test.go b/service/portfolio/snapshot_test.go index c72d2f98..17101430 100644 --- a/service/portfolio/snapshot_test.go +++ b/service/portfolio/snapshot_test.go @@ -22,16 +22,16 @@ import ( "testing" "time" - "github.com/oxisto/assert" - portfoliov1 "github.com/oxisto/money-gopher/gen" "github.com/oxisto/money-gopher/gen/portfoliov1connect" "github.com/oxisto/money-gopher/internal" "github.com/oxisto/money-gopher/persistence" + + "connectrpc.com/connect" + "github.com/oxisto/assert" + portfoliov1 "github.com/oxisto/money-gopher/gen" "golang.org/x/text/currency" "google.golang.org/protobuf/types/known/emptypb" "google.golang.org/protobuf/types/known/timestamppb" - - "connectrpc.com/connect" ) var mockSecuritiesClientWithData = &mockSecuritiesClient{ diff --git a/service/portfolio/transactions_test.go b/service/portfolio/transactions_test.go index d17b440c..e7b408a8 100644 --- a/service/portfolio/transactions_test.go +++ b/service/portfolio/transactions_test.go @@ -20,11 +20,12 @@ import ( "context" "testing" - "connectrpc.com/connect" - "github.com/oxisto/assert" portfoliov1 "github.com/oxisto/money-gopher/gen" "github.com/oxisto/money-gopher/gen/portfoliov1connect" "github.com/oxisto/money-gopher/persistence" + + "connectrpc.com/connect" + "github.com/oxisto/assert" "google.golang.org/protobuf/types/known/fieldmaskpb" ) diff --git a/service/securities/quote.go b/service/securities/quote.go index 7e1ddc39..62872b2f 100644 --- a/service/securities/quote.go +++ b/service/securities/quote.go @@ -21,11 +21,11 @@ import ( "log/slog" "time" + portfoliov1 "github.com/oxisto/money-gopher/gen" + "connectrpc.com/connect" "github.com/lmittmann/tint" "google.golang.org/protobuf/types/known/timestamppb" - - portfoliov1 "github.com/oxisto/money-gopher/gen" ) func (svc *service) TriggerSecurityQuoteUpdate(ctx context.Context, req *connect.Request[portfoliov1.TriggerQuoteUpdateRequest]) (res *connect.Response[portfoliov1.TriggerQuoteUpdateResponse], err error) { diff --git a/service/securities/quote_provider_ing_test.go b/service/securities/quote_provider_ing_test.go index 041feb89..ff3e92ee 100644 --- a/service/securities/quote_provider_ing_test.go +++ b/service/securities/quote_provider_ing_test.go @@ -25,8 +25,9 @@ import ( "testing" "time" - "github.com/oxisto/assert" portfoliov1 "github.com/oxisto/money-gopher/gen" + + "github.com/oxisto/assert" ) func Test_ing_LatestQuote(t *testing.T) { diff --git a/service/securities/quote_provider_yf_test.go b/service/securities/quote_provider_yf_test.go index b9b8e5a4..79716465 100644 --- a/service/securities/quote_provider_yf_test.go +++ b/service/securities/quote_provider_yf_test.go @@ -25,8 +25,9 @@ import ( "testing" "time" - "github.com/oxisto/assert" portfoliov1 "github.com/oxisto/money-gopher/gen" + + "github.com/oxisto/assert" ) type mockRoundTripper struct { diff --git a/service/securities/quote_test.go b/service/securities/quote_test.go index 415e5472..b6b69f46 100644 --- a/service/securities/quote_test.go +++ b/service/securities/quote_test.go @@ -21,14 +21,14 @@ import ( "testing" "time" - "connectrpc.com/connect" - "github.com/oxisto/assert" - "golang.org/x/text/currency" - moneygopher "github.com/oxisto/money-gopher" portfoliov1 "github.com/oxisto/money-gopher/gen" "github.com/oxisto/money-gopher/internal" "github.com/oxisto/money-gopher/persistence" + + "connectrpc.com/connect" + "github.com/oxisto/assert" + "golang.org/x/text/currency" ) const QuoteProviderMock = "mock" diff --git a/service/securities/securities_test.go b/service/securities/securities_test.go index b9f3452f..daa91413 100644 --- a/service/securities/securities_test.go +++ b/service/securities/securities_test.go @@ -20,12 +20,13 @@ import ( "context" "testing" - "connectrpc.com/connect" - "github.com/oxisto/assert" portfoliov1 "github.com/oxisto/money-gopher/gen" "github.com/oxisto/money-gopher/gen/portfoliov1connect" "github.com/oxisto/money-gopher/internal" "github.com/oxisto/money-gopher/persistence" + + "connectrpc.com/connect" + "github.com/oxisto/assert" "golang.org/x/text/currency" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/emptypb"