Documentation ¶
Overview ¶
Index ¶
- Constants
- Variables
- func AddTags(ms MapStr, tags []string) error
- func AutoGetAddress(addr string) string
- func ByteSize(bytes uint64) string
- func BytesToInt64(buf []byte) int64
- func BytesToString(bs []byte) string
- func BytesToUint32(b []byte) (v uint32)
- func BytesToUint64(b []byte) (v uint64)
- func CheckInstanceLock(p string)
- func CheckProcessExists(pid int) bool
- func ClearInstanceLock()
- func ContainStr(s, substr string) bool
- func ContainsAnyInArray(s string, v []string) bool
- func Copy(sourceStruct interface{}, pointToTarget interface{}) (err error)
- func CopyFile(src, dst string) (w int64, err error)
- func CreateCert(template, parent *x509.Certificate, pub interface{}, parentPriv interface{}) (cert *x509.Certificate, certPEM []byte, err error)
- func CreateFile(dir string, name string) (string, error)
- func DeepCopy(value interface{}) interface{}
- func EncodeToBytes(key interface{}) ([]byte, error)
- func Expand(value map[string]interface{}) map[string]interface{}
- func ExpandPrefixed(value map[string]interface{}, prefix string) map[string]interface{}
- func ExpandPrefixedToResult(value map[string]interface{}, prefix string, result map[string]interface{})
- func FileAppendContentWithByte(file string, content []byte) (int, error)
- func FileAppendNewLine(file string, content string) (int, error)
- func FileAppendNewLineWithByte(file string, content []byte) (int, error)
- func FileDelete(file string) error
- func FileExists(path string) bool
- func FileExtension(file string) string
- func FileGetContent(file string) ([]byte, error)
- func FileMTime(file string) (int64, error)
- func FilePutContent(file string, content string) (int, error)
- func FilePutContentWithByte(file string, content []byte) (int, error)
- func FileSize(file string) (int64, error)
- func FilterDirName(name string) bool
- func FilterSpecialChar(keyword string) string
- func Flatten(value interface{}, ignoreNil bool) map[string]interface{}
- func FlattenJSON(value interface{}, ignoreNil bool) (m map[string]interface{})
- func FlattenJSONString(nestedstr, prefix string, ignoreNil bool) (string, error)
- func FlattenPrefixed(value interface{}, prefix string, ignoreNil bool) map[string]interface{}
- func FlattenPrefixedToResult(value interface{}, prefix string, m map[string]interface{}, ignoreNil bool)
- func FlattenPrefixedToResultWithTagAsFieldName(value interface{}, prefix string, m map[string]interface{}, tag string, ...)
- func FormatTime(date time.Time) string
- func FormatTimeForFileName(date time.Time) string
- func FormatTimeWithLocalTZ(date time.Time) string
- func FormatTimeWithTZ(date time.Time) string
- func FormatUnixTimestamp(unix int64) string
- func FromJSONBytes(b []byte, v interface{})
- func FromJson(str string, to interface{}) error
- func FromUnixTimestamp(unix int64) time.Time
- func GetAddress(adr string) *net.TCPAddr
- func GetAvailablePort(ip string, port int) int
- func GetBytes(key interface{}) []byte
- func GetCertTemplate() (*x509.Certificate, error)
- func GetClientCert(rootCert *x509.Certificate, rootKey *rsa.PrivateKey) (clientTLSCert tls.Certificate, clientCertPEM, clientKeyPEM []byte)
- func GetFieldValueByTagName(any interface{}, tagName string, tagValue string) string
- func GetHost(url string) string
- func GetIncrementID(bucket string) int64
- func GetIntValue(any interface{}) int
- func GetIntranetIP() (string, error)
- func GetLocalZone() string
- func GetRootCert() (rootCert *x509.Certificate, rootKey *rsa.PrivateKey, rootCertPEM []byte)
- func GetRootUrl(source *uri.URL) string
- func GetRuntimeErrorMessage(r runtime.Error) string
- func GetSafetyInternalAddress(addr string) string
- func GetTypeName(any interface{}, lowercase bool) string
- func GetUUID() string
- func GetValidAddress(addr string) string
- func Int64ToBytes(i int64) []byte
- func IntToString(num int) string
- func Invoke(any interface{}, name string, args ...interface{})
- func IsExist(path string) bool
- func IsFile(file string) bool
- func IsPublicIP(IP net.IP) bool
- func IsValidTLD(tld string) bool
- func JoinPath(filenames ...string) string
- func MD5digest(str string) string
- func MergeFields(ms, fields MapStr, underRoot bool) error
- func MergeSpace(in string) (out string)
- func NoWordBreak(in string) string
- func PickRandomName() string
- func Post(url string, values url.Values) []byte
- func PrefixStr(s, substr string) bool
- func RemoveSpaces(str string) string
- func Rename(file string, to string) error
- func ReplaceByte(str []byte, old, new []byte) []byte
- func RestorePersistID(path string)
- func Sha1Hash(str string) string
- func SnapshotPersistID()
- func StringToUTF16(s string) []uint16
- func SubString(str string, begin, length int) (substr string)
- func SubStringWithSuffix(str string, length int, suffix string) string
- func SuffixStr(s, substr string) bool
- func TestListenPort(ip string, port int) bool
- func TestPort(port int) bool
- func ToBytes(s string) (uint64, error)
- func ToInt(str string) (int, error)
- func ToJSONBytes(v interface{}) []byte
- func ToJson(in interface{}, indent bool) string
- func ToLowercase(str []byte) []byte
- func ToMegabytes(s string) (uint64, error)
- func ToUppercase(str []byte) []byte
- func TrimLeftStr(str string, left string) string
- func TrimSpaces(str string) string
- func TypeIsMap(any interface{}) bool
- func Uint32toBytes(b []byte, v uint32)
- func Uint64toBytes(b []byte, v uint64)
- func UnicodeIndex(str, substr string) int
- func UrlDecode(str string) string
- func UrlEncode(str string) string
- func WaitServerUp(addr string, duration time.Duration) error
- func XSSHandle(src string) string
- type Annotation
- type EventMetadata
- type MapStr
- func (m MapStr) Clone() MapStr
- func (m MapStr) CopyFieldsTo(to MapStr, key string) error
- func (m MapStr) Delete(key string) error
- func (m MapStr) GetValue(key string) (interface{}, error)
- func (m MapStr) HasKey(key string) (bool, error)
- func (m MapStr) Put(key string, value interface{}) (interface{}, error)
- func (m MapStr) String() string
- func (m MapStr) StringToPrint() string
- func (m MapStr) Update(d MapStr)
- type Request
- func (r *Request) AcceptGzip() *Request
- func (r *Request) AddHeader(key, v string) *Request
- func (r *Request) SetAgent(agent string) *Request
- func (r *Request) SetBasicAuth(username, password string) *Request
- func (r *Request) SetContentType(contentType string) *Request
- func (r *Request) SetProxy(proxy string) *Request
- type Result
- type StringSet
Constants ¶
const ( BYTE = 1.0 KILOBYTE = 1024 * BYTE MEGABYTE = 1024 * KILOBYTE GIGABYTE = 1024 * MEGABYTE TERABYTE = 1024 * GIGABYTE )
ByteSize unit definition
const ( FieldsKey = "fields" TagsKey = "tags" )
Event metadata constants. These keys are used to identify metadata stored in an event.
const ( Verb_GET string = "GET" Verb_PUT string = "PUT" Verb_POST string = "POST" Verb_DELETE string = "DELETE" Verb_HEAD string = "HEAD" )
const ContentTypeForm = "application/x-www-form-urlencoded;charset=UTF-8"
const ContentTypeJson = "application/json;charset=utf-8"
const ContentTypeXml = "application/xml;charset=utf-8"
Variables ¶
var ( // ErrKeyNotFound indicates that the specified key was not found. ErrKeyNotFound = errors.New("key not found") )
Functions ¶
func AddTags ¶
AddTags appends a tag to the tags field of ms. If the tags field does not exist then it will be created. If the tags field exists and is not a []string then an error will be returned. It does not deduplicate the list of tags.
func AutoGetAddress ¶
AutoGetAddress get valid address to listen, if the specify port is not available, auto choose the next one
func ByteSize ¶
ByteSize returns a human-readable byte string of the form 10M, 12.5K, and so forth. The following units are available:
T: Terabyte G: Gigabyte M: Megabyte K: Kilobyte B: Byte
The unit that results in the smallest number greater than or equal to 1 is always chosen.
func BytesToInt64 ¶
func BytesToString ¶
func BytesToUint64 ¶
BytesToUint64 convert bytes to type uint64
func CheckInstanceLock ¶
func CheckInstanceLock(p string)
CheckInstanceLock make sure there is not a lock placed before check, and place a lock after check
func CheckProcessExists ¶
CheckProcessExists check if the pid is running
func ContainStr ¶
func ContainsAnyInArray ¶
func Copy ¶
func Copy(sourceStruct interface{}, pointToTarget interface{}) (err error)
source should be a struct, target should be a pointer to the struct
func CreateCert ¶
func CreateCert(template, parent *x509.Certificate, pub interface{}, parentPriv interface{}) ( cert *x509.Certificate, certPEM []byte, err error)
func EncodeToBytes ¶
func ExpandPrefixed ¶
func ExpandPrefixedToResult ¶
func FileAppendContentWithByte ¶
FileAppendContentWithByte append bytes to the end of the file
func FileAppendNewLine ¶
FileAppendNewLine append new line to the end of the file
func FileAppendNewLineWithByte ¶
FileAppendNewLineWithByte append bytes and break line(\n) to the end of the file
func FileExtension ¶
FileExtension extract file extension from file name
func FileGetContent ¶
FileGetContent get string from text file
func FilePutContent ¶
FilePutContent put string to file
func FilePutContentWithByte ¶
FilePutContentWithByte put string to file
func FilterDirName ¶
FilterDirName guess the file or directory is or contains Go source files.
func FilterSpecialChar ¶
func FlattenJSON ¶
func FlattenJSONString ¶
func FlattenPrefixed ¶
func FlattenPrefixedToResult ¶
func FormatTime ¶
func FormatTimeForFileName ¶
func FormatTimeWithLocalTZ ¶
func FormatTimeWithTZ ¶
func FormatUnixTimestamp ¶
func FromJSONBytes ¶
func FromJSONBytes(b []byte, v interface{})
FromJSONBytes simply do json unmarshal
func FromUnixTimestamp ¶
func GetAddress ¶
func GetAvailablePort ¶
GetAvailablePort get valid port to listen, if the specify port is not available, auto choose the next one
func GetCertTemplate ¶
func GetCertTemplate() (*x509.Certificate, error)
helper function to create a cert template with a serial number and other required fields
func GetClientCert ¶
func GetClientCert(rootCert *x509.Certificate, rootKey *rsa.PrivateKey) (clientTLSCert tls.Certificate, clientCertPEM, clientKeyPEM []byte)
func GetFieldValueByTagName ¶
GetFieldValueByTagName return the field value which field was tagged with this tagName, only support string field
func GetIncrementID ¶
GetIncrementID return incremented id in specify bucket
func GetIntValue ¶
func GetIntValue(any interface{}) int
func GetIntranetIP ¶
func GetRootCert ¶
func GetRootCert() (rootCert *x509.Certificate, rootKey *rsa.PrivateKey, rootCertPEM []byte)
func GetRuntimeErrorMessage ¶
func GetTypeName ¶
func GetValidAddress ¶
GetValidAddress get valid address, input: :8001 -> output: 127.0.0.1:8001
func Int64ToBytes ¶
func IntToString ¶
func Invoke ¶
func Invoke(any interface{}, name string, args ...interface{})
Invoke dynamic execute function via function name and parameters
func IsPublicIP ¶
func IsValidTLD ¶
IsValidTLD returns true if tld is a valid tld, eg: com
func MergeFields ¶
MergeFields merges the top-level keys and values in each source map (it does not perform a deep merge). If the same key exists in both, the value in fields takes precedence. If underRoot is true then the contents of the fields MapStr is merged with the value of the 'fields' key in ms.
An error is returned if underRoot is true and the value of ms.fields is not a MapStr.
func NoWordBreak ¶
func RemoveSpaces ¶
func ReplaceByte ¶
TODO optimize performance ReplaceByte simply replace old bytes to new bytes, the two bytes should have same length
func RestorePersistID ¶
func RestorePersistID(path string)
RestorePersistID will take the snapshot and restore to id seeds
func SnapshotPersistID ¶
func SnapshotPersistID()
SnapshotPersistID will make a snapshot and persist id stats to disk
func StringToUTF16 ¶
func TestListenPort ¶
TestListenPort check availability of port with ip
func ToJSONBytes ¶
func ToJSONBytes(v interface{}) []byte
ToJSONBytes convert interface to json with byte array
func ToLowercase ¶
ToLowercase convert string bytes to lowercase
func ToMegabytes ¶
ToMegabytes parses a string formatted by ByteSize as megabytes.
func ToUppercase ¶
ToUppercase convert string bytes to uppercase
func TrimLeftStr ¶
func Uint32toBytes ¶
Uint32toBytes convert uint32 to bytes, max uint: 4294967295
func UnicodeIndex ¶
Types ¶
type Annotation ¶
type Annotation struct { Field string `json:"field,omitempty"` Type string `json:"type,omitempty"` Tag string `json:"tag,omitempty"` Annotation []Annotation `json:"annotation,omitempty"` }
func GetTagsByTagName ¶
func GetTagsByTagName(any interface{}, tagName string) []Annotation
type EventMetadata ¶
type EventMetadata struct { Fields MapStr FieldsUnderRoot bool `config:"fields_under_root"` Tags []string }
EventMetadata contains fields and tags that can be added to an event via configuration.
type MapStr ¶
type MapStr map[string]interface{}
MapStr is a map[string]interface{} wrapper with utility methods for common map operations like converting to JSON.
func MapStrUnion ¶
MapStrUnion creates a new MapStr containing the union of the key-value pairs of the two maps. If the same key is present in both, the key-value pairs from dict2 overwrite the ones from dict1.
func (MapStr) Clone ¶
Clone returns a copy of the MapStr. It recursively makes copies of inner maps.
func (MapStr) CopyFieldsTo ¶
CopyFieldsTo copies the field specified by key to the given map. It will overwrite the key if it exists. An error is returned if the key does not exist in the source map.
func (MapStr) GetValue ¶
GetValue gets a value from the map. If the key does not exist then an error is returned.
func (MapStr) HasKey ¶
HasKey returns true if the key exist. If an error occurs then false is returned with a non-nil error.
func (MapStr) Put ¶
Put associates the specified value with the specified key. If the map previously contained a mapping for the key, the old value is replaced and returned. The key can be expressed in dot-notation (e.g. x.y) to put a value into a nested map.
If you need insert keys containing dots then you must use bracket notation to insert values (e.g. m[key] = value).
func (MapStr) StringToPrint ¶
StringToPrint returns the MapStr as pretty JSON.
type Request ¶
type Request struct { Agent string Method string Url string Cookie string Proxy string Body []byte ContentType string // contains filtered or unexported fields }
func NewDeleteRequest ¶
NewDeleteRequest issue a simple http delete request
func NewGetRequest ¶
NewGetRequest issue a simple http get request
func NewPostRequest ¶
NewPostRequest issue a simple http post request
func NewPutRequest ¶
NewPutRequest issue a simple http put request
func NewRequest ¶
func (*Request) AcceptGzip ¶
func (*Request) SetBasicAuth ¶
SetBasicAuth set user and password for request
func (*Request) SetContentType ¶
type Result ¶
type Result struct { Host string Url string Headers map[string][]string Body []byte StatusCode int Size uint64 }
Result is the http request result
func ExecuteRequest ¶
ExecuteRequest issue a request
func HttpDelete ¶
HttpDelete issue a simple http delete request
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package file copied from github.com/elastic/beats https://github.com/elastic/beats/blob/master/LICENSE Licensed under the Apache License, Version 2.0 (the "License");
|
Package file copied from github.com/elastic/beats https://github.com/elastic/beats/blob/master/LICENSE Licensed under the Apache License, Version 2.0 (the "License"); |