Documentation ¶
Index ¶
Constants ¶
const DEFAULT_SOCKET_FILE = "gno"
const DEFAULT_SOCKET_SUBDIR = "s"
const DEFAULT_TCP_ADDR = ":26658"
Variables ¶
var WithChainID = func(chainID string) GnoNativeOption { return func(cfg *Config) error { cfg.ChainID = chainID return nil } }
WithChainID sets the given chain ID.
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.
var WithLogger = func(l *zap.Logger) GnoNativeOption { return func(cfg *Config) error { cfg.Logger = l return nil } }
WithLogger set the given logger.
var WithRemote = func(remote string) GnoNativeOption { return func(cfg *Config) error { cfg.Remote = remote return nil } }
WithRemote sets the given remote node address.
var WithRootDir = func(rootDir string) GnoNativeOption { return func(cfg *Config) error { cfg.RootDir = rootDir return nil } }
WithRootDir sets the given root directory path.
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.
var WithTmpDir = func(path string) GnoNativeOption { return func(cfg *Config) error { cfg.TmpDir = path return nil } }
WithTmpDir sets the given temporary path.
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.
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 ¶
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.