utils

package
v0.0.0-...-b1bb88e Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2021 License: LGPL-2.1 Imports: 23 Imported by: 0

Documentation

Overview

Config

PidPortFile

Index

Constants

This section is empty.

Variables

View Source
var Application = OCPErrorClass("application") //Problems that occure based on current application state
View Source
var CidUndef = Cid{cid.Undef}
View Source
var Connection = OCPErrorClass("connection") //Problems with any connection to the outside world
View Source
var Decoder = newDecoder()
View Source
var Internal = OCPErrorClass("internal") //Fatal internal errors
View Source
var Type = OCPErrorClass("type") //Type errors
View Source
var User = OCPErrorClass("user") //Problems that occure based on user input

Functions

func AddConfigFlag

func AddConfigFlag(cmd *cobra.Command, accessor string)

Adds a flag to a command based on a config entry. This uses the long and short names as defined in the config, as well as the default vaule. The accessor string is the standart viper access string.

func ClearPidPort

func ClearPidPort() error

func CreateConfigFile

func CreateConfigFile(name string) (string, error)

func ErrorToWampResult

func ErrorToWampResult(err error) nxclient.InvokeResult

func GetDefaultNodeFolder

func GetDefaultNodeFolder() string

func InitConfig

func InitConfig(path string)

Default init of config stuff: - There is always a config file, even if node is not initialized - If not existing it must be created - Default values are setup - Setup the subcommands for the main config command

func PrintWithStacktrace

func PrintWithStacktrace(err error)

func ReadPidPort

func ReadPidPort() (int, int, error)

Read the pid from the configured file. It is an error if the pidfile hasn't been configured.

func RemoveConfigFile

func RemoveConfigFile(name string) error

func StackError

func StackError(err error, args ...interface{}) error

func WritePidPort

func WritePidPort() error

Write the pidfile based on the flag. It is an error if the pidfile hasn't been configured.

Types

type Cid

type Cid struct {
	cid.Cid
}

func CidDecode

func CidDecode(code string) (Cid, error)

func FromP2PCid

func FromP2PCid(p2p cid.Cid) Cid

func (Cid) Encode

func (self Cid) Encode() string

func (Cid) MarshalBinary

func (self Cid) MarshalBinary() ([]byte, error)

func (Cid) P2P

func (self Cid) P2P() cid.Cid

func (*Cid) UnmarshalBinary

func (self *Cid) UnmarshalBinary(data []byte) error

It implements the encoding.BinaryUnmarshaler interface. Needed as we want to be able to use CidUndef in gob

type ConfigEntry

type ConfigEntry struct {
	Short   string
	Text    string
	Default interface{}
}

func GetConfigEntry

func GetConfigEntry(keys ...string) (ConfigEntry, error)

func (ConfigEntry) IsIntSlice

func (self ConfigEntry) IsIntSlice() bool

func (ConfigEntry) IsSlice

func (self ConfigEntry) IsSlice() bool

func (ConfigEntry) IsStringSlice

func (self ConfigEntry) IsStringSlice() bool

func (ConfigEntry) ValueFromString

func (self ConfigEntry) ValueFromString(value string) (interface{}, error)

type ConfigHandler

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

WAMP API for conf read/write

func NewConfigAPI

func NewConfigAPI(client *nxclient.Client) *ConfigHandler

func (*ConfigHandler) Close

func (self *ConfigHandler) Close()

type DecotableFunc

type DecotableFunc = func(string) (interface{}, error)

type Encotable

type Encotable interface {
	Encode() string
}

A interface for types that could be decoded into string, and hence be used for marshalling The output of the Encode function has to has a defined prefix: ocp_**_ where ** is a arbitrary type specific string. This type identifier is used by the Decoder to recognize the type. "_" is not allowed in the data string

type Error

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

func NewError

func NewError(class OCPErrorClass, source, reason, message string, args ...interface{}) *Error

Creates a new Error from the following informations: * - class: one of the predefined OCPErrorClass types * - source: custom identifier specifying the source of the error (e.g. datastore, host etc.) * - reason: custom identifier specifying the general reason. This is not intended as description, but a kind of grouping for reasons, e.g. "key_not_existant" * - message: detailed information of what has gone wrong * - args: Arguments further detail the error with runtime information provided in log style doubles, e.g. "MyNAme", name, "MyId", id

func (*Error) AddToStack

func (self *Error) AddToStack(val string)

func (*Error) Arguments

func (self *Error) Arguments() []interface{}

func (*Error) Class

func (self *Error) Class() OCPErrorClass

func (*Error) Error

func (self *Error) Error() string

Prints the error in the for of ErrorType: message (arguments)

func (*Error) ErrorType

func (self *Error) ErrorType() string

Print the error type only in the form of ocp.error.class.source.reason

func (*Error) ErrorWithStacktrace

func (self *Error) ErrorWithStacktrace() string

Prints the error in the form of: ErrorType origin: message (Arguments) Stacktraces...

func (*Error) Message

func (self *Error) Message() string

func (*Error) Origin

func (self *Error) Origin() string

func (*Error) Reason

func (self *Error) Reason() string

func (*Error) Source

func (self *Error) Source() string

func (*Error) Stack

func (self *Error) Stack() []string

type OCPError

type OCPError interface {
	error

	Class() OCPErrorClass
	Source() string
	Reason() string
	Message() string
	Origin() string
	Arguments() []interface{}
	Stack() []string
	ErrorType() string
	ErrorWithStacktrace() string

	AddToStack(string)
}

the default error used for all OCP related errors

func WampRPCErrorToError

func WampRPCErrorToError(err nxclient.RPCError) OCPError

type OCPErrorClass

type OCPErrorClass string

Jump to

Keyboard shortcuts

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