config

package
v0.3.19 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: Apache-2.0 Imports: 9 Imported by: 24

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToString

func ConvertToString(in interface{}, tagType ...string) (s string, err error)

ConvertToString convert struct to string

func ConvertToStringWithTitle

func ConvertToStringWithTitle(in interface{}, title string, tagType ...string) (s string, err error)

ConvertToStringWithTitle convert struct to string with given title

func WriteToBuffer

func WriteToBuffer(in interface{}, buffer *bytes.Buffer, tagType ...string) (err error)

WriteToBuffer loops each member of given input struct recursively, converts member variable names and concerning values to "key = value" string, and then write the string into buffer, it follows some rules:

  1. if tag type is specified, which is optional, "key" will be replaced by the tag name
  2. toml and ini type config files requires each key should has a value(but could be empty), but some toml/ini like config files(for example: my.cnf) allows variables are only keys instead of key value pairs, (for example: skip-name-resolve), in this case, you can specify constant.DefaultRandomString or constant.DefaultRandomInt to those keys not having values, therefore when this function find out those constant values, it will convert to key string ignore the value and also the equal mark

Types

type ErrMessage added in v0.2.2

type ErrMessage struct {
	Header  string
	ErrCode int
	Raw     string
	Err     error
	Stack   errors.StackTrace
}

func NewErrMessage added in v0.2.2

func NewErrMessage(header string, errCode int, raw string, errs ...error) *ErrMessage

NewErrMessage returns a *ErrMessage without stack trace, note that if errs contains more than one error, only the first one will be used, if you want to use more than one error, please use github.com/romberli/go-multierror to wrap those errors to one

func (*ErrMessage) Clone added in v0.2.2

func (e *ErrMessage) Clone() *ErrMessage

Clone returns a new *ErrMessage with same member variables

func (*ErrMessage) Code added in v0.2.2

func (e *ErrMessage) Code() string

Code returns combined Header and ErrCode string

func (*ErrMessage) Error added in v0.2.2

func (e *ErrMessage) Error() string

Error is an implementation fo Error interface

func (*ErrMessage) ErrorOrNil added in v0.2.2

func (e *ErrMessage) ErrorOrNil() error

ErrorOrNil returns an error interface if both Header and ErrCode are not zero value, otherwise, returns nil. This function is useful at the end of accumulation to make sure that the value returned represents the existence of errors

func (*ErrMessage) Format added in v0.3.16

func (e *ErrMessage) Format(s fmt.State, verb rune)

Format implements fmt.Formatter interface

func (*ErrMessage) Renew added in v0.2.2

func (e *ErrMessage) Renew(ins ...interface{}) *ErrMessage

Renew returns a new *ErrMessage and specify with given input

func (*ErrMessage) SetError added in v0.3.16

func (e *ErrMessage) SetError(err error) *ErrMessage

SetError sets Err with the given error

func (*ErrMessage) Specify added in v0.2.2

func (e *ErrMessage) Specify(ins ...interface{})

Specify specifies placeholders with given data

func (*ErrMessage) StackTrace added in v0.3.16

func (e *ErrMessage) StackTrace() errors.StackTrace

func (*ErrMessage) String added in v0.2.20

func (e *ErrMessage) String() string

String is an alias of Error()

Jump to

Keyboard shortcuts

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