initutil

package
v2.175.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2020 License: Apache-2.0, MIT Imports: 57 Imported by: 0

Documentation

Overview

Example (Flags)
package main

import (
	"context"
	"flag"
	"fmt"

	"moul.io/u"

	"berty.tech/berty/v2/go/internal/initutil"
)

func main() {
	// init manager
	ctx := context.Background()
	manager, err := initutil.New(ctx)
	if err != nil {
		panic(err)
	}
	defer manager.Close()

	// configure flags
	fmt.Println("before", u.JSON(manager.Node.GRPC))
	fs := flag.NewFlagSet("test", flag.ExitOnError)
	manager.SetupLocalProtocolServerFlags(fs)
	manager.SetupRemoteNodeFlags(fs)
	manager.SetupDefaultGRPCListenersFlags(fs)
	err = fs.Parse([]string{"-store.inmem", "-p2p.min-backoff=2m10s", "-node.remote-addr=1.2.3.4:5678"})
	if err != nil {
		panic(err)
	}
	fmt.Println("after ", u.JSON(manager.Node.GRPC))

}
Output:

before {"RemoteAddr":"","Listeners":""}
after  {"RemoteAddr":"1.2.3.4:5678","Listeners":"/ip4/127.0.0.1/tcp/9091/grpc"}
Example (Noflags)
package main

import (
	"context"
	"flag"
	"fmt"

	"berty.tech/berty/v2/go/internal/initutil"
	"berty.tech/berty/v2/go/pkg/bertytypes"
)

func main() {
	// init manager
	ctx := context.Background()
	manager, err := initutil.New(ctx)
	if err != nil {
		panic(err)
	}
	defer manager.Close()

	fs := flag.NewFlagSet("", flag.ExitOnError)
	manager.SetupLocalProtocolServerFlags(fs)
	manager.SetupRemoteNodeFlags(fs)
	fs.Parse([]string{})

	// configure manager without flags
	manager.Node.GRPC.Listeners = ""
	manager.Node.Protocol.DisableIPFSNetwork = true
	manager.Datastore.InMemory = true

	// start a local berty protocol server
	_, err = manager.GetLocalProtocolServer()
	if err != nil {
		panic(err)
	}

	// build a client for the previously created protocol server
	client, err := manager.GetProtocolClient()
	if err != nil {
		panic(err)
	}

	// retrieve config
	ret, err := client.InstanceGetConfiguration(ctx, &bertytypes.InstanceGetConfiguration_Request{})
	if err != nil {
		panic(err)
	}

	// check that the reply is valid (cannot check hardcoded value, since it's random)
	fmt.Println(ret.AccountPK != nil)

}
Output:

true

Index

Examples

Constants

View Source
const InMemoryDir = ":memory:"

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	Logging struct {
		Format  string
		Logfile string
		Filters string
		Tracer  string
		// contains filtered or unexported fields
	}
	Datastore struct {
		Dir      string
		InMemory bool
		// contains filtered or unexported fields
	}
	Node struct {
		Protocol struct {
			// IPFS
			IPFSListeners      string
			IPFSAPIListeners   string
			IPFSWebUIListener  string
			Announce           string
			NoAnnounce         string
			LocalDiscovery     bool
			MinBackoff         time.Duration
			MaxBackoff         time.Duration
			DisableIPFSNetwork bool
			// RdvpMaddrs store a list of rdvp server maddr.
			// The entry : `:dev:` will add the devs servers to the list (default).
			// The netry : `:none:` will disable all rdvp servers.
			RdvpMaddrs flagStringSlice

			// Auth
			AuthSecret    string
			AuthPublicKey string
			// contains filtered or unexported fields
		}
		Messenger struct {
			DisplayName          string
			DisableNotifications bool
			RebuildSqlite        bool
			MessengerSqliteOpts  string
			// contains filtered or unexported fields
		}
		GRPC struct {
			RemoteAddr string
			Listeners  string
			// contains filtered or unexported fields
		}
		// contains filtered or unexported fields
	}
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context) (*Manager, error)

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) DisableIPFSNetwork

func (m *Manager) DisableIPFSNetwork()

func (*Manager) GetContext

func (m *Manager) GetContext() context.Context

func (*Manager) GetDatastoreDir

func (m *Manager) GetDatastoreDir() (string, error)

func (*Manager) GetGRPCClientConn

func (m *Manager) GetGRPCClientConn() (*grpc.ClientConn, error)

func (*Manager) GetGRPCServer

func (m *Manager) GetGRPCServer() (*grpc.Server, *grpcgw.ServeMux, error)

func (*Manager) GetLifecycleManager added in v2.145.0

func (m *Manager) GetLifecycleManager() *lifecycle.Manager

func (*Manager) GetLocalIPFS added in v2.141.0

func (m *Manager) GetLocalIPFS() (ipfsutil.ExtendedCoreAPI, *ipfs_core.IpfsNode, error)

func (*Manager) GetLocalMessengerServer

func (m *Manager) GetLocalMessengerServer() (bertymessenger.MessengerServiceServer, error)

func (*Manager) GetLocalProtocolServer

func (m *Manager) GetLocalProtocolServer() (bertyprotocol.Service, error)

func (*Manager) GetLogger

func (m *Manager) GetLogger() (*zap.Logger, error)

func (*Manager) GetMessengerClient

func (m *Manager) GetMessengerClient() (bertymessenger.MessengerServiceClient, error)

func (*Manager) GetMessengerDB

func (m *Manager) GetMessengerDB() (*gorm.DB, error)

func (*Manager) GetOrbitDB added in v2.141.0

func (m *Manager) GetOrbitDB() (*bertyprotocol.BertyOrbitDB, error)

func (*Manager) GetProtocolClient

func (m *Manager) GetProtocolClient() (bertyprotocol.ProtocolServiceClient, error)

func (*Manager) GetRootDatastore

func (m *Manager) GetRootDatastore() (datastore.Batching, error)

func (*Manager) RunWorkers

func (m *Manager) RunWorkers() error

func (*Manager) SetupDatastoreFlags

func (m *Manager) SetupDatastoreFlags(fs *flag.FlagSet)

func (*Manager) SetupDefaultGRPCListenersFlags added in v2.141.1

func (m *Manager) SetupDefaultGRPCListenersFlags(fs *flag.FlagSet)

func (*Manager) SetupEmptyGRPCListenersFlags added in v2.141.1

func (m *Manager) SetupEmptyGRPCListenersFlags(fs *flag.FlagSet)

func (*Manager) SetupLocalIPFSFlags added in v2.141.0

func (m *Manager) SetupLocalIPFSFlags(fs *flag.FlagSet)

func (*Manager) SetupLocalMessengerServerFlags

func (m *Manager) SetupLocalMessengerServerFlags(fs *flag.FlagSet)

func (*Manager) SetupLocalProtocolServerFlags

func (m *Manager) SetupLocalProtocolServerFlags(fs *flag.FlagSet)

func (*Manager) SetupLoggingFlags

func (m *Manager) SetupLoggingFlags(fs *flag.FlagSet)

func (*Manager) SetupProtocolAuth added in v2.154.0

func (m *Manager) SetupProtocolAuth(fs *flag.FlagSet)

func (*Manager) SetupRemoteNodeFlags

func (m *Manager) SetupRemoteNodeFlags(fs *flag.FlagSet)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL