Skip to content

Commit

Permalink
WIP: structuralise config
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed Mar 24, 2024
1 parent caf13f4 commit 67a2f83
Show file tree
Hide file tree
Showing 30 changed files with 691 additions and 659 deletions.
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@
"GOLOG_OUTPUT": "file"
}
},
{
"name": "Launch relay",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/relay/",
"console": "integratedTerminal",
"env": {
"GOLOG_FILE": "/tmp/debug.log",
"GOLOG_LOG_LEVEL": "debug",
"GOLOG_STDOUT": "false",
"GOLOG_OUTPUT": "file"
}
},
{
"name": "go-ma-actor generate",
"type": "go",
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ It provides The ability to browse IPFS properly, and to pin files and directorie

### Cros-compiling

Cross-cmpiling for Windows requires gcc-mingw-w64 and gcc-multilib tools to be installed.

CGO is required for sqlite to work on Windows™.
Cross-compiling for Windows requires gcc-mingw-w64 and gcc-multilib tools to be installed.

## TL;DR

Expand Down
11 changes: 6 additions & 5 deletions cmd/actor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"

"github.com/bahner/go-ma-actor/config"
"github.com/bahner/go-ma-actor/entity/actor"
"github.com/bahner/go-ma-actor/p2p"
"github.com/bahner/go-ma-actor/ui"
Expand All @@ -12,14 +11,16 @@ import (
log "github.com/sirupsen/logrus"
)

const name = "actor"

func main() {

var (
err error
)
var err error

actor.Config(name)

Check failure on line 20 in cmd/actor/main.go

View workflow job for this annotation

GitHub Actions / build

undefined: actor.Config

fmt.Println("Initialising actor configuation...")
actor.InitConfig(config.Profile())
// actor.InitConfig(config.Profile())

// P2P
fmt.Println("Setting default p2p options...")
Expand Down
83 changes: 83 additions & 0 deletions cmd/node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ package main
import (
"time"

"github.com/bahner/go-ma-actor/config"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"gopkg.in/yaml.v2"
)

const (
defautSpaceNodeName = "space@localhost"
defaultNodeCookie = "spacecookie"
defaultNodeName = "pubsub@localhost"
defaultNodeDebugInterval = time.Second * 60
name = "node"
)

func init() {
Expand All @@ -34,3 +37,83 @@ func init() {
viper.SetDefault("node.debug_interval", defaultNodeDebugInterval)

}

type NodeStruct struct {
Cookie string `yaml:"cookie"`
Name string `yaml:"name"`
Space string `yaml:"space"`
DebugInterval time.Duration `yaml:"debug-interval"`
}

type NodeConfigStruct struct {
Node NodeStruct `yaml:"node"`
}

type NodeConfig struct {
Actor config.ActorConfigStruct `yaml:"actor"`
API config.APIConfigStruct `yaml:"api"`
DB config.DBConfigStruct `yaml:"db"`
HTTP config.HTTPConfigStruct `yaml:"http"`
Node NodeConfigStruct `yaml:"node"`
Log config.LogConfigStruct `yaml:"log"`
P2P config.P2PConfigStruct `yaml:"p2p"`
}

func Config(name string) NodeConfig {

config.ActorFlags()
pflag.Parse()

config.SetProfile(name)

c := NodeConfig{
Actor: config.ActorConfig(),
API: config.APIConfig(),
DB: config.DBConfig(),
HTTP: config.HTTPConfig(),
Node: NodeConfigStruct{
Node: NodeStruct{
Cookie: NodeCookie(),
Name: NodeName(),
Space: NodeSpace(),
DebugInterval: NodeDebugInterval(),
},
},
Log: config.LogConfig(),
P2P: config.P2PConfig(),
}

if config.GenerateFlag() {
config.Save(&c)
}

return c
}

func (c *NodeConfig) MarshalToYAML() ([]byte, error) {
return yaml.Marshal(c)
}

func (c *NodeConfig) Print() {
config.Print(c)
}

func (c *NodeConfig) Save() error {
return config.Save(c)
}

func NodeSpace() string {
return viper.GetString("node.space")
}

func NodeCookie() string {
return viper.GetString("node.cookie")
}

func NodeName() string {
return viper.GetString("node.name")
}

func NodeDebugInterval() time.Duration {
return viper.GetDuration("node.debug_interval")
}
8 changes: 3 additions & 5 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ package main
import (
"context"

"github.com/bahner/go-ma-actor/config"
"github.com/bahner/go-ma-actor/entity/actor"
"github.com/bahner/go-ma-actor/p2p"
"github.com/bahner/go-ma-actor/ui/web"
log "github.com/sirupsen/logrus"
)

const name = "node"

func main() {

ctx := context.Background()

Config(name)

// Init config and logger
config.SetProfile(name)
actor.InitConfig(config.Profile())
// actor.InitConfig(config.Profile())

p, err := p2p.Init(p2p.DefaultOptions())
if err != nil {
Expand Down
58 changes: 0 additions & 58 deletions cmd/node/template.go

This file was deleted.

Loading

0 comments on commit 67a2f83

Please sign in to comment.