output

package
v2.0.7-rc3 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Format string

Format is the target of output-format flag

Functions

func FormatString

func FormatString(t MessageType, m Message) string

FormatString returns Output as string in certain format

func FormatStringWithTrans

func FormatStringWithTrans(t MessageType, m MessageWithTranslation) string

FormatStringWithTrans returns Output as string in certain format supporting multi languages

func JSONString

func JSONString(out interface{}) string

JSONString returns json string for message

func NewError

func NewError(code ErrorCode, info string, pre error) error

NewError and returns golang error that contains Error Message ErrorCode can pass zero only when previous error is always a format error that contains non-zero error code. ErrorCode passes 0 means that I want to use previous error's code rather than override it. If there is no previous error, newInfo should not be empty.

func PrintError

func PrintError(err error) error

PrintError prints Error Message in format, only used at top layer of a command

func PrintQuery

func PrintQuery(query string)

PrintQuery prints query message in format

func PrintResult

func PrintResult(result string)

PrintResult prints result message in format

Types

type ConfirmationMessage

type ConfirmationMessage struct {
	Info    string   `json:"info"`
	Options []string `json:"options"`
}

ConfirmationMessage is the struct of an Confirmation output

func (*ConfirmationMessage) String

func (m *ConfirmationMessage) String() string

type ErrorCode

type ErrorCode int

ErrorCode is the code of error

const (
	// UndefinedError used when an error cat't be classified
	UndefinedError ErrorCode = iota
	// UpdateError used when an error occurs when running update command
	UpdateError
	// RuntimeError used when an error occurs in runtime
	RuntimeError
	// NetworkError used when an network error is happened
	NetworkError
	// APIError used when an API error is happened
	APIError
	// ValidationError used when validation is not passed
	ValidationError
	// SerializationError used when marshal or unmarshal meets error
	SerializationError
	// ReadFileError used when error occurs during reading a file
	ReadFileError
	// WriteFileError used when error occurs during writing a file
	WriteFileError
	// FlagError used when invalid flag is set
	FlagError
	// ConvertError used when fail to converting data
	ConvertError
	// CryptoError used when crypto error occurs
	CryptoError
	// AddressError used if an error is related to address
	AddressError
	// InputError used when error about input occurs
	InputError
	// KeystoreError used when an error related to keystore
	KeystoreError
	// ConfigError used when an error about config occurs
	ConfigError
	// InstantiationError used when an error during instantiation
	InstantiationError
	// CompilerError used when an error occurs when using the solidity compiler
	CompilerError
)

type ErrorMessage

type ErrorMessage struct {
	Code ErrorCode `json:"code"`
	Info string    `json:"info"`
}

ErrorMessage is the struct of an Error output

func (ErrorMessage) Error

func (m ErrorMessage) Error() string

Error implements error interface

func (*ErrorMessage) String

func (m *ErrorMessage) String() string

type Message

type Message interface {
	String() string
}

Message is the message part of output

type MessageType

type MessageType int

MessageType marks the type of output message

const (
	// Result represents the result of a command
	Result MessageType = iota
	// Confirmation represents request for confirmation
	Confirmation
	// Query represents request for answer of certain question
	Query
	// Error represents error occurred when running a command
	Error
	// Warn represents non-fatal mistake occurred when running a command
	Warn
)

type MessageWithTranslation

type MessageWithTranslation interface {
	String(args ...string) string
}

MessageWithTranslation is the message part of output supporting multi languages

type Output

type Output struct {
	MessageType            MessageType            `json:"messageType"`
	Message                Message                `json:"message"`
	MessageWithTranslation MessageWithTranslation `json:"messageWithTranslation"`
}

Output is used for format output

type StringMessage

type StringMessage string

StringMessage is the Message for string

func (StringMessage) Query

func (m StringMessage) Query() string

Query prints query message

func (StringMessage) String

func (m StringMessage) String() string

func (StringMessage) Warn

func (m StringMessage) Warn() string

Warn prints warn message

Jump to

Keyboard shortcuts

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