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 GetEnvLogDir() 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 StringDeepCopy(s string) string
- func StringToSliceByte(s string) []byte
- func UnmarshalError(b []byte) error
- func WriteInt64ToStringBuilder(sb *strings.Builder, value int64)
- type AtomicInt
- type ErrChain
- type KitexArgs
- type KitexResult
- type MaxCounter
- type NetAddr
- type Ringdeprecated
- func NewRing(size int) *Ringdeprecated
- type SharedTicker
- type Slice
- type StringBuilder
- func (b *StringBuilder) Cap() int
- func (b *StringBuilder) Grow(n int)
- func (b *StringBuilder) Len() int
- func (b *StringBuilder) RawStringBuilder() *strings.Builder
- func (b *StringBuilder) Reset()
- func (b *StringBuilder) String() string
- func (b *StringBuilder) WithLocked(f func(sb *strings.Builder) error) error
- func (b *StringBuilder) Write(p []byte) (int, error)
- func (b *StringBuilder) WriteByte(c byte) error
- func (b *StringBuilder) WriteRune(r rune) (int, error)
- func (b *StringBuilder) WriteString(s string) (int, error)
- type ThriftMessageCodec
- func (t *ThriftMessageCodec) Decode(b []byte, msg athrift.TStruct) (method string, seqID int32, err error)
- func (t *ThriftMessageCodec) Deserialize(msg athrift.TStruct, b []byte) (err error)
- func (t *ThriftMessageCodec) Encode(method string, msgType athrift.TMessageType, seqID int32, msg athrift.TStruct) ([]byte, error)
- func (t *ThriftMessageCodec) Serialize(msg athrift.TStruct) (b []byte, err error)
- type TickerTask
- 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 GetEnvLogDir ¶ added in v0.5.0
func GetEnvLogDir() string
GetEnvLogDir is to get log dir from env.
func GetFuncName ¶
func GetFuncName(i interface{}) string
GetFuncName returns the function name of i.
func GetLogDir ¶
func GetLogDir() string
GetLogDir gets dir of log file. Deprecated: it is suggested to use GetEnvLogDir instead of GetLogDir, and GetEnvLogDir won't return default log dir.
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 StringDeepCopy ¶ added in v0.6.0
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 KitexArgs ¶ added in v0.4.0
type KitexArgs interface {
GetFirstArgument() interface{}
}
KitexArgs is used for assert when get real request from XXXArgs. Thrift and KitexProtobuf will generate GetFirstArgument() interface{} for XXXArgs
type KitexResult ¶ added in v0.4.0
type KitexResult interface { GetResult() interface{} SetSuccess(interface{}) }
KitexResult is used for assert when get real response from XXXResult. Thrift and KitexProtobuf will generate the two functions for XXXResult.
type MaxCounter ¶
type MaxCounter struct {
// contains filtered or unexported fields
}
MaxCounter is an integer counter with upper limit.
func NewMaxCounter ¶
func NewMaxCounter(max int) *MaxCounter
NewMaxCounter returns a new MaxCounter.
func (*MaxCounter) DecN ¶ added in v0.4.3
func (cl *MaxCounter) DecN(n int64)
DecN decreases the counter by n.
func (*MaxCounter) Inc ¶
func (cl *MaxCounter) Inc() bool
Inc increases the counter by one and returns if the operation succeeds.
func (*MaxCounter) Now ¶ added in v0.4.3
func (cl *MaxCounter) Now() int64
type NetAddr ¶
type NetAddr struct {
// contains filtered or unexported fields
}
NetAddr implements the net.Addr interface.
type SharedTicker ¶ added in v0.5.0
type SharedTicker struct { // contains filtered or unexported fields }
func NewSharedTicker ¶ added in v0.5.0
func NewSharedTicker(interval time.Duration) *SharedTicker
NewSharedTicker constructs a SharedTicker with specified interval.
func (*SharedTicker) Add ¶ added in v0.5.0
func (t *SharedTicker) Add(b TickerTask)
func (*SharedTicker) Closed ¶ added in v0.5.0
func (t *SharedTicker) Closed() bool
func (*SharedTicker) Delete ¶ added in v0.5.0
func (t *SharedTicker) Delete(b TickerTask)
func (*SharedTicker) Tick ¶ added in v0.5.0
func (t *SharedTicker) Tick(interval time.Duration)
type Slice ¶
type Slice []interface{}
Slice is an abstraction of []interface{}.
type StringBuilder ¶ added in v0.7.2
StringBuilder is a concurrently safe wrapper for strings.Builder.
func (*StringBuilder) Cap ¶ added in v0.7.2
func (b *StringBuilder) Cap() int
func (*StringBuilder) Grow ¶ added in v0.7.2
func (b *StringBuilder) Grow(n int)
func (*StringBuilder) Len ¶ added in v0.7.2
func (b *StringBuilder) Len() int
func (*StringBuilder) RawStringBuilder ¶ added in v0.7.2
func (b *StringBuilder) RawStringBuilder() *strings.Builder
RawStringBuilder returns the inner strings.Builder of StringBuilder. It allows users to perform lock-free operations in scenarios without concurrency issues, thereby improving performance.
func (*StringBuilder) Reset ¶ added in v0.7.2
func (b *StringBuilder) Reset()
func (*StringBuilder) String ¶ added in v0.7.2
func (b *StringBuilder) String() string
func (*StringBuilder) WithLocked ¶ added in v0.7.2
func (b *StringBuilder) WithLocked(f func(sb *strings.Builder) error) error
WithLocked encapsulates a concurrent-safe interface for batch operations on strings.Builder. Please note that you should avoid calling member functions of StringBuilder within the input function, as it may lead to program deadlock.
func (*StringBuilder) WriteByte ¶ added in v0.7.2
func (b *StringBuilder) WriteByte(c byte) error
func (*StringBuilder) WriteRune ¶ added in v0.7.2
func (b *StringBuilder) WriteRune(r rune) (int, error)
func (*StringBuilder) WriteString ¶ added in v0.7.2
func (b *StringBuilder) WriteString(s string) (int, error)
type ThriftMessageCodec ¶
type ThriftMessageCodec struct{}
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 athrift.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 Deprecated: use github.com/cloudwego/gopkg/protocol/thrift.UnmarshalFastMsg
func (*ThriftMessageCodec) Deserialize ¶
func (t *ThriftMessageCodec) Deserialize(msg athrift.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 athrift.TMessageType, seqID int32, msg athrift.TStruct) ([]byte, 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. Deprecated: use github.com/cloudwego/gopkg/protocol/thrift.MarshalFastMsg
type TickerTask ¶ added in v0.5.0
type TickerTask interface {
Tick()
}
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.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package kitexutil provides some util methods to get RPC information
|
Package kitexutil provides some util methods to get RPC information |