Documentation ¶
Overview ¶
Package utils contains utils.
Package utils .
Index ¶
- Constants
- Variables
- func CalculateEventCost(rpcstats rpcinfo.RPCStats, start, end stats.Event) time.Duration
- func GetConfDir() string
- func GetConfFile() string
- func GetFuncName(i interface{}) string
- func GetLogDir() string
- func GetUIntLen(n uint64) int
- func JSONStr2Map(jsonStr string) (mapInfo map[string]string, err error)
- func Map2JSONStr(mapInfo map[string]string) (str string, err error)
- func MarshalError(method string, err error) []byte
- func NewNetAddr(network, address string) net.Addr
- func SliceByteToString(b []byte) string
- func StringToSliceByte(s string) []byte
- func UnmarshalError(b []byte) error
- func WriteInt64ToStringBuilder(sb *strings.Builder, value int64)
- type AtomicInt
- type ErrChain
- type MaxCounter
- type NetAddr
- type Ring
- type Slice
- type ThriftMessageCodec
- func (t *ThriftMessageCodec) Decode(b []byte, msg thrift.TStruct) (method string, seqID int32, err error)
- func (t *ThriftMessageCodec) Deserialize(msg thrift.TStruct, b []byte) (err error)
- func (t *ThriftMessageCodec) Encode(method string, msgType thrift.TMessageType, seqID int32, msg thrift.TStruct) (b []byte, err error)
- func (t *ThriftMessageCodec) Serialize(msg thrift.TStruct) (b []byte, err error)
- type YamlConfig
Constants ¶
const ( EnvConfDir = "KITEX_CONF_DIR" EnvConfFile = "KITEX_CONF_FILE" EnvLogDir = "KITEX_LOG_DIR" DefaultConfDir = "conf" DefaultConfFile = "kitex.yml" DefaultLogDir = "log" )
Predefined env variables and default configurations.
const ( EmptyJSON = "{}" Comma = ',' Colon = ':' DQuotation = '"' LeftBrace = '{' RightBrace = '}' )
const of json keyword char
const DefaultErrorSeparator = " | "
DefaultErrorSeparator is the separator for string representations of errors hold by ErrChain.
Variables ¶
var ErrRingFull = errors.New("ring is full")
ErrRingFull means the ring is full.
Functions ¶
func CalculateEventCost ¶
CalculateEventCost get events from rpcstats, and calculates the time duration of (end - start). It returns 0 when get nil rpcinfo event of either stats event.
func GetFuncName ¶
func GetFuncName(i interface{}) string
GetFuncName returns the function name of i.
func GetUIntLen ¶
GetUIntLen returns the length of the string representation of the given value n.
func JSONStr2Map ¶
JSONStr2Map transform json str to map[string]string, perf is better than use json lib directly
func Map2JSONStr ¶
Map2JSONStr transform map[string]string to json str, perf is better than use json lib directly
func MarshalError ¶
MarshalError convert go error to thrift exception, and encode exception over buffered binary transport.
func NewNetAddr ¶
NewNetAddr creates a new NetAddr object with the network and address provided.
func SliceByteToString ¶
SliceByteToString converts []byte to string without copy. DO NOT USE unless you know what you're doing.
func StringToSliceByte ¶
StringToSliceByte converts string to []byte without copy. DO NOT USE unless you know what you're doing.
func UnmarshalError ¶
UnmarshalError decode binary and return error message
func WriteInt64ToStringBuilder ¶
WriteInt64ToStringBuilder writes a int64 to a strings.Builder.
Types ¶
type ErrChain ¶
type ErrChain struct {
// contains filtered or unexported fields
}
ErrChain is used to pack multiple errors. The zero value of ErrChain is ready to use.
func (*ErrChain) UseSeparator ¶
UseSeparator sets the separator of the current ErrChain instance.
type MaxCounter ¶
type MaxCounter struct {
// contains filtered or unexported fields
}
MaxCounter is a integer counter with upper limit.
func NewMaxCounter ¶
func NewMaxCounter(max int) *MaxCounter
NewMaxCounter returns a new MaxCounter.
func (*MaxCounter) Inc ¶
func (cl *MaxCounter) Inc() bool
Inc increases the counter by one and returns if the operation succeeds.
type NetAddr ¶
type NetAddr struct {
// contains filtered or unexported fields
}
NetAddr implements the net.Addr interface.
type Ring ¶
type Ring struct {
// contains filtered or unexported fields
}
Ring implements a fixed size hash list to manage data
type Slice ¶
type Slice []interface{}
Slice is an abstraction of []interface{}.
type ThriftMessageCodec ¶
type ThriftMessageCodec struct {
// contains filtered or unexported fields
}
ThriftMessageCodec is used to codec thrift messages.
func NewThriftMessageCodec ¶
func NewThriftMessageCodec() *ThriftMessageCodec
NewThriftMessageCodec creates a new ThriftMessageCodec.
func (*ThriftMessageCodec) Decode ¶
func (t *ThriftMessageCodec) Decode(b []byte, msg thrift.TStruct) (method string, seqID int32, err error)
Decode do thrift message decode, notice: msg must be XXXArgs/XXXResult that the wrap struct for args and result, not the actual args or result
func (*ThriftMessageCodec) Deserialize ¶
func (t *ThriftMessageCodec) Deserialize(msg thrift.TStruct, b []byte) (err error)
Deserialize deserialize bytes into message. This is normal thrift deserialize func. Notice: Binary generic use Decode instead of Deserialize.
func (*ThriftMessageCodec) Encode ¶
func (t *ThriftMessageCodec) Encode(method string, msgType thrift.TMessageType, seqID int32, msg thrift.TStruct) (b []byte, err error)
Encode do thrift message encode. Notice! msg must be XXXArgs/XXXResult that the wrap struct for args and result, not the actual args or result Notice! seqID will be reset in kitex if the buffer is used for generic call in client side, set seqID=0 is suggested when you call this method as client.
type YamlConfig ¶
type YamlConfig struct { configutil.RichTypeConfig // contains filtered or unexported fields }
YamlConfig contains configurations from yaml file.
func ReadYamlConfigFile ¶
func ReadYamlConfigFile(yamlFile string) (*YamlConfig, error)
ReadYamlConfigFile creates a YamlConfig from the file.
func (*YamlConfig) Get ¶
func (yc *YamlConfig) Get(key string) (interface{}, bool)
Get implements the configutil.Config interface.
func (*YamlConfig) GetDuration ¶
func (yc *YamlConfig) GetDuration(key string) (time.Duration, bool)
GetDuration implements the configutil.RichTypeConfig interface. It converts string item to time.Duration.