Skip to content

Commit

Permalink
Merge pull request #33 from strideynet/Store-credentials-and-config-i…
Browse files Browse the repository at this point in the history
…n-dotenv

Store credentials and config in .env
  • Loading branch information
KevSlashNull authored Jul 18, 2023
2 parents 5fc62d4 + c8b0bf6 commit 3b7acbb
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ENV=dev

# Your handle on bsky.app and an app password generated
# at: https://bsky.app/settings/app-passwords
BLUESKY_USERNAME=
BLUESKY_PASSWORD=
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ go.work

.idea/
infra/secrets/
.DS_Store
.DS_Store
.env
9 changes: 8 additions & 1 deletion cmd/bffctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package main

import (
"context"
"errors"
"fmt"
"os"

"github.com/joho/godotenv"
"github.com/strideynet/bsky-furry-feed/bluesky"
"github.com/urfave/cli/v2"
"go.uber.org/zap"
"os"
)

type environment struct {
Expand Down Expand Up @@ -37,6 +40,10 @@ func getBlueskyClient(ctx context.Context) (*bluesky.Client, error) {
func main() {
log, _ := zap.NewDevelopment()

if err := godotenv.Load(); err != nil && !errors.Is(err, os.ErrNotExist) {
log.Info("could not load .env file", zap.Error(err))
}

var env = &environment{}
app := &cli.App{
Name: "bffctl",
Expand Down
17 changes: 12 additions & 5 deletions cmd/bffsrv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ package main

import (
"context"
"errors"
"fmt"
"os"
"os/signal"
"time"

"github.com/joho/godotenv"
"github.com/strideynet/bsky-furry-feed/api"
"github.com/strideynet/bsky-furry-feed/bluesky"
"github.com/strideynet/bsky-furry-feed/feed"
Expand All @@ -18,9 +24,6 @@ import (
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
"golang.org/x/sys/unix"
"os"
"os/signal"
"time"
)

// TODO: Better, more granular, env configuration.
Expand Down Expand Up @@ -48,8 +51,12 @@ func getMode() (mode, error) {

func main() {
log, _ := zap.NewProduction()
err := runE(log)
if err != nil {

if err := godotenv.Load(); err != nil && !errors.Is(err, os.ErrNotExist) {
log.Fatal("could not load existing .env file", zap.Error(err))
}

if err := runE(log); err != nil {
log.Fatal("exited with error", zap.Error(err))
}
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ require (
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/joho/godotenv v1.5.1
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
Expand Down

1 comment on commit 3b7acbb

@vercel
Copy link

@vercel vercel bot commented on 3b7acbb Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.