Skip to content

Commit

Permalink
bits and bolts
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrekmonko committed Jan 14, 2024
1 parent d10359c commit eed1cea
Show file tree
Hide file tree
Showing 20 changed files with 517 additions and 181 deletions.
4 changes: 2 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ package cmd
import (
"encoding/json"
"fmt"
"github.com/piotrekmonko/portfello/pkg/config"
"github.com/piotrekmonko/portfello/pkg/conf"
"github.com/spf13/cobra"
)

Expand All @@ -34,7 +34,7 @@ var configCmd = &cobra.Command{
Aliases: []string{"conf"},
Short: "Config verifies configuration is complete",
Run: func(cmd *cobra.Command, args []string) {
conf := config.New()
conf := conf.New()
err := conf.Validate()
cobra.CheckErr(err)

Expand Down
8 changes: 4 additions & 4 deletions cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"errors"
"github.com/golang-migrate/migrate/v4"
"github.com/piotrekmonko/portfello/dbschema"
"github.com/piotrekmonko/portfello/pkg/config"
"github.com/piotrekmonko/portfello/pkg/conf"
"github.com/spf13/cobra"
"log"
)
Expand All @@ -48,7 +48,7 @@ var upCmd = &cobra.Command{
Use: "up",
Short: "Apply missing migrations",
Run: func(cmd *cobra.Command, args []string) {
conf := config.New()
conf := conf.New()
migrator, err := dbschema.NewMigrator(conf.DatabaseDSN)
if err != nil {
logFatalMigrate(err)
Expand All @@ -66,7 +66,7 @@ var downCmd = &cobra.Command{
Use: "down",
Short: "Revert one last migration",
Run: func(cmd *cobra.Command, args []string) {
conf := config.New()
conf := conf.New()
migrator, err := dbschema.NewMigrator(conf.DatabaseDSN)
if err != nil {
logFatalMigrate(err)
Expand All @@ -84,7 +84,7 @@ var dropCmd = &cobra.Command{
Use: "drop",
Short: "Drop database. WARNING: This will delete all data!",
Run: func(cmd *cobra.Command, args []string) {
conf := config.New()
conf := conf.New()
migrator, err := dbschema.NewMigrator(conf.DatabaseDSN)
if err != nil {
logFatalMigrate(err)
Expand Down
6 changes: 3 additions & 3 deletions cmd/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/brianvoe/gofakeit/v6"
"github.com/lithammer/shortuuid/v4"
"github.com/piotrekmonko/portfello/pkg/auth"
"github.com/piotrekmonko/portfello/pkg/config"
"github.com/piotrekmonko/portfello/pkg/conf"
"github.com/piotrekmonko/portfello/pkg/dao"
"github.com/piotrekmonko/portfello/pkg/logz"
"github.com/spf13/cobra"
Expand All @@ -41,7 +41,7 @@ var provisionCmd = &cobra.Command{
Short: "Add objects to systems",
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
conf := config.New()
conf := conf.New()
log := logz.NewLogger(&conf.Logging)
db, dbq, err := dao.NewDAO(ctx, log, conf.DatabaseDSN)
if err != nil {
Expand Down Expand Up @@ -119,5 +119,5 @@ func provisionTestData(ctx context.Context, dbq *dao.DAO) error {
}
}

return q.Commit()
return q.Commit(ctx)
}
29 changes: 2 additions & 27 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ package cmd

import (
"fmt"
"github.com/piotrekmonko/portfello/pkg/conf"
"github.com/piotrekmonko/portfello/pkg/logz"
"go.uber.org/zap"
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

const baseVersion = "v1.0.0"
Expand Down Expand Up @@ -82,30 +82,5 @@ func init() {

// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
if err := viper.ReadInConfig(); err != nil {
cobra.CheckErr(fmt.Errorf("fatal error config file @ %s: %w", cfgFile, err))
}
}

// Find home directory.
home, err := os.UserHomeDir()
cobra.CheckErr(err)

// Search config in home directory with name ".portfello" (without extension).
viper.AddConfigPath(home)
viper.AddConfigPath(".")
viper.SetConfigType("yaml")

viper.AutomaticEnv() // read in environment variables that match

// Loop through found config files until all are parsed
for _, configFile := range []string{".portfello", ".portfello-local"} {
viper.SetConfigName(configFile)
if err := viper.MergeInConfig(); err == nil {
_, _ = fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
}
}
cobra.CheckErr(conf.InitConfig(cfgFile))
}
12 changes: 7 additions & 5 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"context"
"errors"
"github.com/piotrekmonko/portfello/pkg/auth"
"github.com/piotrekmonko/portfello/pkg/config"
"github.com/piotrekmonko/portfello/pkg/conf"
"github.com/piotrekmonko/portfello/pkg/dao"
"github.com/piotrekmonko/portfello/pkg/logz"
"github.com/piotrekmonko/portfello/pkg/server"
Expand All @@ -41,20 +41,20 @@ import (
var serveCmd = &cobra.Command{
Use: "serve",
Short: "Start GraphQL server",
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
conf := config.New()
conf := conf.New()
log := logz.NewLogger(&conf.Logging)

db, dbQuerier, err := dao.NewDAO(ctx, log, conf.DatabaseDSN)
if err != nil {
return
return err
}
defer db.Close()

authProvider, err := auth.NewProvider(ctx, log, conf, dbQuerier)
if err != nil {
return
return err
}
authService := auth.New(authProvider)

Expand All @@ -73,6 +73,8 @@ var serveCmd = &cobra.Command{
defer closeCanc()
cobra.CheckErr(httpSrv.Shutdown(closeCtx))
log.Infow(ctx, "Server stopped")

return nil
},
}

Expand Down
50 changes: 32 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/99designs/gqlgen v0.17.42
github.com/auth0/go-auth0 v1.4.0
github.com/auth0/go-jwt-middleware/v2 v2.2.0
github.com/brianvoe/gofakeit/v6 v6.26.3
github.com/brianvoe/gofakeit/v6 v6.26.4
github.com/eko/gocache/lib/v4 v4.1.5
github.com/eko/gocache/store/go_cache/v4 v4.2.1
github.com/go-acme/lego/v4 v4.14.2
Expand All @@ -17,7 +17,7 @@ require (
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
github.com/sqlc-dev/sqlc v1.24.0
github.com/sqlc-dev/sqlc v1.25.0
github.com/stretchr/testify v1.8.4
github.com/vektah/gqlparser/v2 v2.5.10
go.uber.org/zap v1.26.0
Expand All @@ -26,16 +26,15 @@ require (
require (
github.com/PuerkitoBio/rehttp v1.3.0 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230321174746-8dcc6526cfb1 // indirect
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytecodealliance/wasmtime-go/v14 v14.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/cubicdaiya/gonp v1.0.4 // indirect
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.1 // indirect
Expand All @@ -51,23 +50,25 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
github.com/jackc/pgx/v5 v5.5.1 // indirect
github.com/jackc/pgx/v5 v5.5.2 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.19 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pganalyze/pg_query_go/v4 v4.2.3 // indirect
github.com/pganalyze/pg_query_go/v4 v4.2.4-0.20231205012101-7463430c7b73 // indirect
github.com/pganalyze/pg_query_go/v5 v5.1.0 // indirect
github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63 // indirect
github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c // indirect
github.com/pingcap/log v1.1.0 // indirect
github.com/pingcap/tidb/pkg/parser v0.0.0-20240102121832-237b2c7d5078 // indirect
github.com/pingcap/tidb/pkg/parser v0.0.0-20240113042725-d0c81e1f2aff // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/common v0.46.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/riza-io/grpc-go v0.2.0 // indirect
Expand All @@ -81,26 +82,39 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tetratelabs/wazero v1.6.0 // indirect
github.com/urfave/cli/v2 v2.27.1 // indirect
github.com/wasilibs/go-pgquery v0.0.0-20240111082134-4f3a12da8e62 // indirect
github.com/wasilibs/wazerox v0.0.0-20240105014115-75455786b41e // indirect
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.16.1 // indirect
golang.org/x/tools v0.17.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240108191215-35c7eff3a6b1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240108191215-35c7eff3a6b1 // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/go-jose/go-jose.v2 v2.6.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/uint128 v1.3.0 // indirect
modernc.org/cc/v3 v3.41.0 // indirect
modernc.org/ccgo/v3 v3.16.15 // indirect
modernc.org/libc v1.40.2 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/sqlite v1.28.0 // indirect
modernc.org/strutil v1.2.0 // indirect
modernc.org/token v1.1.0 // indirect
)

0 comments on commit eed1cea

Please sign in to comment.