common

package
v0.0.0-...-7b16d43 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FORMAT_BINARY = "binary"
	FORMAT_JSON   = "json"

	DEFAULT_FIELD = "self"
)
View Source
const (
	StreamConf      = "kuiper.yaml"
	KuiperBaseKey   = "KuiperBaseKey"
	KuiperSyslogKey = "KuiperSyslogKey"
	MetaKey         = "__meta"
)
View Source
const EtcOsRelease string = "/etc/os-release"
View Source
const ISO8601 = "2006-01-02T15:04:05"
View Source
const JSISO = "2006-01-02T15:04:05.000Z07:00"
View Source
const UsrLibOsRelease string = "/usr/lib/os-release"

Variables

View Source
var (
	Log       *logrus.Logger
	Config    *KuiperConf
	IsTesting bool
	Clock     clock.Clock

	LoadFileType = "relative"
)
View Source
var BodyTypeMap = map[string]string{"none": "", "text": "text/plain", "json": "application/json", "html": "text/html", "xml": "application/xml", "javascript": "application/javascript", "form": ""}

Functions

func CloseLogger

func CloseLogger()

func ConvertArray

func ConvertArray(s []interface{}) []interface{}

func ConvertMap

func ConvertMap(s map[interface{}]interface{}) map[string]interface{}

func FormatTime

func FormatTime(time time.Time, f string) (string, error)

func GetConfLoc

func GetConfLoc() (string, error)

func GetDataLoc

func GetDataLoc() (string, error)

func GetLoc

func GetLoc(subdir string) (string, error)

func GetNowInMilli

func GetNowInMilli() int64

func GetTicker

func GetTicker(duration int) *clock.Ticker

Time related. For Mock

func GetTimer

func GetTimer(duration int) *clock.Timer

func InitConf

func InitConf()

func InterfaceToTime

func InterfaceToTime(i interface{}, format string) (time.Time, error)

func InterfaceToUnixMilli

func InterfaceToUnixMilli(i interface{}, format string) (int64, error)

func LoadConf

func LoadConf(confName string) ([]byte, error)

func MapToStruct

func MapToStruct(input, output interface{}) error

* Convert a map into a struct. The output parameter must be a pointer to a struct * The struct can have the json meta data

func MapToSyncMap

func MapToSyncMap(m map[string]interface{}) *sync.Map

func MessageDecode

func MessageDecode(payload []byte, format string) (map[string]interface{}, error)

func ParseTime

func ParseTime(t string, f string) (time.Time, error)

func PrintMap

func PrintMap(m map[string]string, buff *bytes.Buffer)

func ProcessPath

func ProcessPath(p string) (string, error)

func Read

func Read() (osrelease map[string]string, err error)

Read and return os-release, trying EtcOsRelease, followed by UsrLibOsRelease. err will contain an error message if neither file exists or failed to parse

func ReadFile

func ReadFile(filename string) (osrelease map[string]string, err error)

Similar to Read(), but takes the name of a file to load instead

func ReadJsonUnmarshal

func ReadJsonUnmarshal(path string, ret interface{}) error

func ReadString

func ReadString(content string) (osrelease map[string]string, err error)

ReadString is similar to Read(), but takes a string to load instead

func ReadYamlUnmarshal

func ReadYamlUnmarshal(path string, ret interface{}) error

func Send

func Send(logger api.Logger, client *http.Client, bodyType string, method string, u string, headers map[string]string, sendSingle bool, v interface{}) (*http.Response, error)

func SyncMapToMap

func SyncMapToMap(sm *sync.Map) map[string]interface{}

func TimeFromUnixMilli

func TimeFromUnixMilli(t int64) time.Time

func TimeToUnixMilli

func TimeToUnixMilli(time time.Time) int64

func ToInt

func ToInt(input interface{}) (int, error)

func ToString

func ToString(input interface{}) string

********** Type Cast Utilities **** TODO datetime type

func WriteYamlMarshal

func WriteYamlMarshal(path string, data interface{}) error

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

func NewError

func NewError(message string) *Error

func NewErrorWithCode

func NewErrorWithCode(code ErrorCode, message string) *Error

func (*Error) Code

func (e *Error) Code() ErrorCode

func (*Error) Error

func (e *Error) Error() string

type ErrorCode

type ErrorCode int
const (
	GENERAL_ERR ErrorCode = iota
	NOT_FOUND
)

type KeyValue

type KeyValue interface {
	Open() error
	Close() error
	// Set key to hold string value if key does not exist otherwise return an error
	Setnx(key string, value interface{}) error
	// Set key to hold the string value. If key already holds a value, it is overwritten
	Set(key string, value interface{}) error
	Get(key string, val interface{}) (bool, error)
	//Must return *common.Error with NOT_FOUND error
	Delete(key string) error
	Keys() (keys []string, err error)
	Clean() error
}

type KuiperConf

type KuiperConf struct {
	Basic struct {
		Debug          bool     `yaml:"debug"`
		ConsoleLog     bool     `yaml:"consoleLog"`
		FileLog        bool     `yaml:"fileLog"`
		RotateTime     int      `yaml:"rotateTime"`
		MaxAge         int      `yaml:"maxAge"`
		Ip             string   `yaml:"ip"`
		Port           int      `yaml:"port"`
		RestIp         string   `yaml:"restIp"`
		RestPort       int      `yaml:"restPort"`
		RestTls        *tlsConf `yaml:"restTls"`
		Prometheus     bool     `yaml:"prometheus"`
		PrometheusPort int      `yaml:"prometheusPort"`
		PluginHosts    string   `yaml:"pluginHosts"`
	}
	Rule api.RuleOption
	Sink struct {
		CacheThreshold    int  `yaml:"cacheThreshold"`
		CacheTriggerCount int  `yaml:"cacheTriggerCount"`
		DisableCache      bool `yaml:"disableCache""`
	}
}

type PluginDesc

type PluginDesc struct {
	RuleDesc
	Type int
	Stop bool
}

type RuleDesc

type RuleDesc struct {
	Name, Json string
}

type SqliteKVStore

type SqliteKVStore struct {
	// contains filtered or unexported fields
}

func GetSqliteKVStore

func GetSqliteKVStore(fpath string) (ret *SqliteKVStore)

func (*SqliteKVStore) Clean

func (m *SqliteKVStore) Clean() error

func (*SqliteKVStore) Close

func (m *SqliteKVStore) Close() error

func (*SqliteKVStore) Delete

func (m *SqliteKVStore) Delete(key string) error

func (*SqliteKVStore) Get

func (m *SqliteKVStore) Get(key string, value interface{}) (bool, error)

func (*SqliteKVStore) Keys

func (m *SqliteKVStore) Keys() ([]string, error)

func (*SqliteKVStore) Open

func (m *SqliteKVStore) Open() error

func (*SqliteKVStore) Set

func (m *SqliteKVStore) Set(key string, value interface{}) error

func (*SqliteKVStore) Setnx

func (m *SqliteKVStore) Setnx(key string, value interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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