mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
refactor configs
This commit is contained in:
parent
523aedaf3e
commit
17e37fb8fb
69 changed files with 1013 additions and 605 deletions
|
@ -6,7 +6,7 @@ proto:
|
|||
|
||||
build:
|
||||
@$(eval FLAGS := $$(shell govvv -flags -pkg github.com/anytypeio/go-anytype-infrastructure-experiments/consensus))
|
||||
go build -v -o ../bin/consensus-node -ldflags "$(FLAGS)" github.com/anytypeio/go-anytype-infrastructure-experiments/consensus/cmd
|
||||
go build -v -o ../bin/anytype-consensus -ldflags "$(FLAGS)" github.com/anytypeio/go-anytype-infrastructure-experiments/consensus/cmd
|
||||
|
||||
test:
|
||||
go test ./... --cover
|
||||
go test ./... --cover
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
commonaccount "github.com/anytypeio/go-anytype-infrastructure-experiments/common/accountservice"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/object/accountdata"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/encryptionkey"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/signingkey"
|
||||
|
@ -24,7 +23,7 @@ func New() app.Component {
|
|||
}
|
||||
|
||||
func (s *service) Init(a *app.App) (err error) {
|
||||
acc := a.MustComponent(config.CName).(commonaccount.ConfigGetter).GetAccount()
|
||||
acc := a.MustComponent("config").(commonaccount.ConfigGetter).GetAccount()
|
||||
|
||||
decodedEncryptionKey, err := keys.DecodeKeyFromString(
|
||||
acc.EncryptionKey,
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
commonaccount "github.com/anytypeio/go-anytype-infrastructure-experiments/common/accountservice"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
|
||||
config2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/metric"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net"
|
||||
"gopkg.in/yaml.v3"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
const CName = "config"
|
||||
|
||||
func NewFromFile(path string) (c *Config, err error) {
|
||||
c = &Config{}
|
||||
data, err := ioutil.ReadFile(path)
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -22,12 +25,11 @@ func NewFromFile(path string) (c *Config, err error) {
|
|||
}
|
||||
|
||||
type Config struct {
|
||||
GrpcServer config2.GrpcServer `yaml:"grpcServer"`
|
||||
Account config2.Account `yaml:"account"`
|
||||
Mongo Mongo `yaml:"mongo"`
|
||||
Metric config2.Metric `yaml:"metric"`
|
||||
Log config2.Log `yaml:"log"`
|
||||
Stream config2.Stream `yaml:"stream"`
|
||||
GrpcServer net.Config `yaml:"grpcServer"`
|
||||
Account commonaccount.Config `yaml:"account"`
|
||||
Mongo Mongo `yaml:"mongo"`
|
||||
Metric metric.Config `yaml:"metric"`
|
||||
Log logger.Config `yaml:"log"`
|
||||
}
|
||||
|
||||
func (c *Config) Init(a *app.App) (err error) {
|
||||
|
@ -42,18 +44,14 @@ func (c Config) GetMongo() Mongo {
|
|||
return c.Mongo
|
||||
}
|
||||
|
||||
func (c Config) GetGRPCServer() config2.GrpcServer {
|
||||
func (c Config) GetNet() net.Config {
|
||||
return c.GrpcServer
|
||||
}
|
||||
|
||||
func (c Config) GetStream() config2.Stream {
|
||||
return c.Stream
|
||||
}
|
||||
|
||||
func (c Config) GetAccount() config2.Account {
|
||||
func (c Config) GetAccount() commonaccount.Config {
|
||||
return c.Account
|
||||
}
|
||||
|
||||
func (c Config) GetMetric() config2.Metric {
|
||||
func (c Config) GetMetric() metric.Config {
|
||||
return c.Metric
|
||||
}
|
||||
|
|
|
@ -3,8 +3,9 @@ package consensusclient
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/accountservice/mock_accountservice"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/object/accountdata"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/pool"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/rpc/rpctest"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/nodeconf"
|
||||
|
@ -137,20 +138,21 @@ func newFixture(t *testing.T) *fixture {
|
|||
fx.drpcTS = rpctest.NewTestServer()
|
||||
require.NoError(t, consensusproto.DRPCRegisterConsensus(fx.drpcTS.Mux, fx.testServer))
|
||||
fx.a.Register(fx.Service).
|
||||
Register(mock_accountservice.NewAccountServiceWithAccount(fx.ctrl, &accountdata.AccountData{})).
|
||||
Register(fx.nodeconf).
|
||||
Register(rpctest.NewTestPool().WithServer(fx.drpcTS)).
|
||||
Register(&config.Config{Nodes: []config.Node{
|
||||
Register(&testConfig{Nodes: []nodeconf.NodeConfig{
|
||||
{
|
||||
PeerId: "c1",
|
||||
Types: []config.NodeType{config.NodeTypeConsensus},
|
||||
Types: []nodeconf.NodeType{nodeconf.NodeTypeConsensus},
|
||||
},
|
||||
{
|
||||
PeerId: "c2",
|
||||
Types: []config.NodeType{config.NodeTypeConsensus},
|
||||
Types: []nodeconf.NodeType{nodeconf.NodeTypeConsensus},
|
||||
},
|
||||
{
|
||||
PeerId: "c3",
|
||||
Types: []config.NodeType{config.NodeTypeConsensus},
|
||||
Types: []nodeconf.NodeType{nodeconf.NodeTypeConsensus},
|
||||
},
|
||||
}})
|
||||
return fx
|
||||
|
@ -240,3 +242,14 @@ func (t *testWatcher) AddConsensusError(err error) {
|
|||
close(t.ready)
|
||||
})
|
||||
}
|
||||
|
||||
type testConfig struct {
|
||||
Nodes []nodeconf.NodeConfig
|
||||
}
|
||||
|
||||
func (t testConfig) GetNodes() []nodeconf.NodeConfig {
|
||||
return t.Nodes
|
||||
}
|
||||
|
||||
func (t *testConfig) Init(a *app.App) error { return nil }
|
||||
func (t *testConfig) Name() string { return "config" }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue