Skip to content

Commit

Permalink
Rehouse actor vars and make config more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed Nov 26, 2023
1 parent f83822f commit 404eff2
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 48 deletions.
52 changes: 52 additions & 0 deletions config/defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package config

import (
"time"

"github.com/bahner/go-ma"
"github.com/bahner/go-ma/key/set"
"go.deanishe.net/env"
)

const (
name = "go-ma-actor"

// The default entity to connect to.
GO_MA_ACTOR_KEYSET_VAR = "GO_MA_ACTOR_KEYSET"
GO_MA_ACTOR_ENTITY_VAR = "GO_MA_ACTOR_ENTITY"
GO_MA_ACTOR_DISCOVERY_TIMEOUT_VAR = "GO_MA_ACTOR_DISCOVERY_TIMEOUT"
GO_MA_ACTOR_LOW_WATERMARK_VAR = "GO_MA_ACTOR_LOW_WATERMARK"
GO_MA_ACTOR_HIGH_WATERMARK_VAR = "GO_MA_ACTOR_HIGH_WATERMARK"
GO_MA_ACTOR_CONNMGR_GRACE_VAR = "GO_MA_ACTOR_CONNMGR_GRACE"

defaultDiscoveryTimeout int = 300
defaultLowWaterMark int = 2
defaultHighWaterMark int = 10
defaultConnMgrGrace time.Duration = time.Minute * 1
)

var (
generate *bool
genenv *bool
publish *bool
forcePublish *bool

keyset *set.Keyset

discoveryTimeout int = env.GetInt(GO_MA_ACTOR_DISCOVERY_TIMEOUT_VAR, defaultDiscoveryTimeout)
lowWaterMark int = env.GetInt(GO_MA_ACTOR_LOW_WATERMARK_VAR, defaultLowWaterMark)
highWaterMark int = env.GetInt(GO_MA_ACTOR_HIGH_WATERMARK_VAR, defaultHighWaterMark)
connmgrGracePeriod time.Duration = env.GetDuration(GO_MA_ACTOR_CONNMGR_GRACE_VAR, defaultConnMgrGrace)

logLevel string = env.Get(ma.LOGLEVEL_VAR, "info")
logfile string = env.Get(ma.LOGFILE_VAR, name+".log")

// What we want to communicate with initially
entity string = env.Get(GO_MA_ACTOR_ENTITY_VAR, "")

// Actor
keyset_string string = env.Get(GO_MA_ACTOR_KEYSET_VAR, "")

// Nick is only used for keyset generation. Must be a valid NanoID.
nick string = env.Get("USER")
)
45 changes: 0 additions & 45 deletions config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,7 @@ import (
"os"
"time"

"github.com/bahner/go-ma"
"github.com/bahner/go-ma/key/set"
log "github.com/sirupsen/logrus"
"go.deanishe.net/env"
)

const (
name = "go-ma-actor"

// The default entity to connect to.
GO_MA_ACTOR_ENTITY_VAR = "GO_MA_ACTOR_ENTITY"

defaultDiscoveryTimeout int = 300
defaultLowWaterMark int = 2
defaultHighWaterMark int = 10
defaultConnMgrGrace time.Duration = time.Minute * 1
)

var (
err error

generate *bool
genenv *bool
publish *bool
forcePublish *bool

keyset *set.Keyset
)

var (
discoveryTimeout int = env.GetInt(ma.DISCOVERY_TIMEOUT_VAR, defaultDiscoveryTimeout)
lowWaterMark int = env.GetInt(ma.LOW_WATERMARK_VAR, defaultLowWaterMark)
highWaterMark int = env.GetInt(ma.HIGH_WATERMARK_VAR, defaultHighWaterMark)
connmgrGracePeriod time.Duration = env.GetDuration(ma.CONNMGR_GRACE_VAR, defaultConnMgrGrace)

logLevel string = env.Get(ma.LOGLEVEL_VAR, "info")
logfile string = env.Get(ma.LOGFILE_VAR, name+".log")

// What we want to communicate with initially
entity string = env.Get(GO_MA_ACTOR_ENTITY_VAR, "")

// Actor
keyset_string string = env.Get(ma.KEYSET_VAR, "")

// Nick is only used for keyset generation. Must be a valid NanoID.
nick string = env.Get("USER")
)

func init() {
Expand Down
5 changes: 3 additions & 2 deletions config/keyset.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"

"github.com/bahner/go-ma"
"github.com/bahner/go-ma/did/doc"
"github.com/bahner/go-ma/key/set"
"github.com/pkg/errors"
Expand All @@ -13,6 +12,8 @@ import (

func initKeyset(keyset_string string) {

var err error

// Generate a new keysets if requested
if *generate || *genenv {
log.Debugf("config.initKeyset: Generating new keyset for %s", nick)
Expand Down Expand Up @@ -66,7 +67,7 @@ func generateKeyset() string {
}

if *genenv {
fmt.Println("export " + ma.KEYSET_VAR + "=" + pks)
fmt.Println("export " + GO_MA_ACTOR_KEYSET_VAR + "=" + pks)
}

return pks
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/bahner/go-ma-actor
go 1.21

require (
github.com/bahner/go-ma v0.0.6-0.20231126000006-ea6d3230b7c5
github.com/bahner/go-ma v0.0.6-0.20231126211854-c1323073bd64
github.com/c-bata/go-prompt v0.2.6
github.com/gdamore/tcell/v2 v2.6.0
github.com/libp2p/go-libp2p v0.32.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/bahner/go-ma v0.0.6-0.20231126000006-ea6d3230b7c5 h1:Olf3MlIvYYfgdDQnofqcKSQOdO7hcGleD68ofrptxsA=
github.com/bahner/go-ma v0.0.6-0.20231126000006-ea6d3230b7c5/go.mod h1:l9ty9QbOZfRUtovECXES7a01Su7xBYIBphFak1TOjVs=
github.com/bahner/go-ma v0.0.6-0.20231126211854-c1323073bd64 h1:dBGw1zZm46xJWUnVDT9BAbL8GUu8AwjWbP5Ddc7yRS4=
github.com/bahner/go-ma v0.0.6-0.20231126211854-c1323073bd64/go.mod h1:l9ty9QbOZfRUtovECXES7a01Su7xBYIBphFak1TOjVs=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
Expand Down

0 comments on commit 404eff2

Please sign in to comment.