service

package
v0.0.0-...-c80efd4 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const DEFAULT_SOCKET_FILE = "gno"
View Source
const DEFAULT_SOCKET_SUBDIR = "s"
View Source
const DEFAULT_TCP_ADDR = ":26658"

Variables

View Source
var WithChainID = func(chainID string) GnoNativeOption {
	return func(cfg *Config) error {
		cfg.ChainID = chainID
		return nil
	}
}

WithChainID sets the given chain ID.

View Source
var WithDisableUdsListener = func() GnoNativeOption {
	return func(cfg *Config) error {
		cfg.DisableUdsListener = true
		return nil
	}
}

WithDisableUdsListener sets the gRPC server to serve on a TCP listener.

View Source
var WithLogger = func(l *zap.Logger) GnoNativeOption {
	return func(cfg *Config) error {
		cfg.Logger = l
		return nil
	}
}

WithLogger set the given logger.

View Source
var WithRemote = func(remote string) GnoNativeOption {
	return func(cfg *Config) error {
		cfg.Remote = remote
		return nil
	}
}

WithRemote sets the given remote node address.

View Source
var WithRootDir = func(rootDir string) GnoNativeOption {
	return func(cfg *Config) error {
		cfg.RootDir = rootDir
		return nil
	}
}

WithRootDir sets the given root directory path.

View Source
var WithTcpAddr = func(addr string) GnoNativeOption {
	return func(cfg *Config) error {
		cfg.TcpAddr = addr
		return nil
	}
}

WithTcpAddr sets the given TCP address to serve the gRPC server. If no TCP address is defined, a default will be used. If the TCP port is set to 0, a random port number will be chosen.

View Source
var WithTmpDir = func(path string) GnoNativeOption {
	return func(cfg *Config) error {
		cfg.TmpDir = path
		return nil
	}
}

WithTmpDir sets the given temporary path.

View Source
var WithUdsPath = func(path string) GnoNativeOption {
	return func(cfg *Config) error {
		absPath, err := filepath.Abs(path)
		if err != nil {
			return err
		}

		cfg.UdsPath = absPath
		return nil
	}
}

WithUdsPath sets the given Unix Domain Socket path to serve the gRPC server. If no UDS socket is defined, a default will be used.

View Source
var WithUseTcpListener = func() GnoNativeOption {
	return func(cfg *Config) error {
		cfg.UseTcpListener = true
		return nil
	}
}

WithUseTcpListener sets the gRPC server to serve on a TCP listener.

Functions

This section is empty.

Types

type Config

type Config struct {
	Logger             *zap.Logger
	Remote             string
	ChainID            string
	RootDir            string
	TmpDir             string
	TcpAddr            string
	UdsPath            string
	UseTcpListener     bool
	DisableUdsListener bool
}

Config describes a set of settings for a GnoNativeService

type FallBackOption

type FallBackOption struct {
	// contains filtered or unexported fields
}

FallBackOption is a structure that permits to fallback to a default option if the option is not set.

type GnoNativeOption

type GnoNativeOption func(cfg *Config) error
var WithDefaultChainID GnoNativeOption = func(cfg *Config) error {
	cfg.ChainID = "dev"

	return nil
}

WithDefaultChainID sets a default chain ID.

var WithDefaultLogger GnoNativeOption = func(cfg *Config) error {
	logger, err := zap.NewDevelopment()
	if err != nil {
		return err
	}

	cfg.Logger = logger

	return nil
}

WithDefaultLogger init a noop logger.

var WithDefaultRemote GnoNativeOption = func(cfg *Config) error {
	cfg.Remote = "127.0.0.1:26657"
	return nil
}

WithDefaultRemote inits a default remote node address.

var WithDefaultRootDir GnoNativeOption = func(cfg *Config) error {
	rootDir, err := os.MkdirTemp("", "gnonative")
	if err != nil {
		return err
	}

	cfg.RootDir = rootDir

	return nil
}

WithDefaultRootDir sets a default root directory in a temporary folder.

var WithDefaultTcpAddr GnoNativeOption = func(cfg *Config) error {
	cfg.TcpAddr = DEFAULT_TCP_ADDR

	return nil
}

WithDefaultTcpAddr sets a default TCP addr to listen to.

var WithDefaultTmpDir GnoNativeOption = func(cfg *Config) error {

	if err := WithFallbackRootDir(cfg); err != nil {
		return err
	}

	cfg.TmpDir = cfg.RootDir

	return nil
}

WithDefaultTmpDir sets a default temporary path.

var WithDefaultUdsPath GnoNativeOption = func(cfg *Config) error {

	if err := WithFallbackTmpDir(cfg); err != nil {
		return err
	}

	sockDir := filepath.Join(cfg.TmpDir, DEFAULT_SOCKET_SUBDIR)
	if err := os.MkdirAll(sockDir, 0700); err != nil {
		return api_gen.ErrCode_ErrInitService.Wrap(err)
	}

	cfg.UdsPath = filepath.Join(sockDir, DEFAULT_SOCKET_FILE)

	return nil
}

WithDefaultUdsPath sets a default UDS path to listen to.

var WithFallbacChainID GnoNativeOption = func(cfg *Config) error {
	if fallbackChainID.fallback(cfg) {
		return fallbackChainID.opt(cfg)
	}
	return nil
}

WithFallbackChainID sets the chain ID if no chain ID is set.

var WithFallbacRemote GnoNativeOption = func(cfg *Config) error {
	if fallbackRemote.fallback(cfg) {
		return fallbackRemote.opt(cfg)
	}
	return nil
}

WithFallbackRemote sets the remote node address if no address is set.

var WithFallbackDefaults GnoNativeOption = func(cfg *Config) error {
	for _, def := range defaults {
		if !def.fallback(cfg) {
			continue
		}
		if err := def.opt(cfg); err != nil {
			return err
		}
	}
	return nil
}

WithFallbackDefaults sets the default options if no option is set.

var WithFallbackLogger GnoNativeOption = func(cfg *Config) error {
	if fallbackLogger.fallback(cfg) {
		return fallbackLogger.opt(cfg)
	}
	return nil
}

WithFallbackLogger sets the logger if no logger is set.

var WithFallbackRootDir GnoNativeOption = func(cfg *Config) error {
	if fallbackRootDir.fallback(cfg) {
		return fallbackRootDir.opt(cfg)
	}
	return nil
}

WithFallbackRootDir sets the default root directory if no directory is set.

var WithFallbackTcpAddr GnoNativeOption = func(cfg *Config) error {
	if fallbackTcpAddr.fallback(cfg) {
		return fallbackTcpAddr.opt(cfg)
	}
	return nil
}

WithDefaultTcpAddr sets a default TCP addr to listen to if no address is set.

var WithFallbackTmpDir GnoNativeOption = func(cfg *Config) error {
	if fallbackTmpDir.fallback(cfg) {
		return fallbackTmpDir.opt(cfg)
	}
	return nil
}

WithFallbackTmpDir sets the default temporary path if no path is set.

var WithFallbackUdsPath GnoNativeOption = func(cfg *Config) error {
	if fallbackUdsPath.fallback(cfg) {
		return fallbackUdsPath.opt(cfg)
	}
	return nil
}

WithDefaultUdsPath sets a default UDS path to listen to if no path is set.

type GnoNativeService

type GnoNativeService interface {
	GetUDSPath() string
	GetTcpAddr() string
	GetTcpPort() int

	io.Closer
}

func NewGnoNativeService

func NewGnoNativeService(opts ...GnoNativeOption) (GnoNativeService, error)

NewGnoNativeService create a new GnoNative service along with a gRPC server listening on UDS by default.

Jump to

Keyboard shortcuts

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