本文整理匯總了Golang中github.com/hevnly/eevy/event.Event類的典型用法代碼示例。如果您正苦於以下問題:Golang Event類的具體用法?Golang Event怎麽用?Golang Event使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Event類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Exec
// Satisfies the Listener interface and calls the relevant binary file
func (this *Cli) Exec(evt event.Event) {
this.Log.Handler(this, &evt)
bin := magicString(this.Config.GetBin(), evt)
stdin := magicString(this.Config.GetStdin(), evt)
args := append([]string(nil), this.Config.GetArgs()...)
for i, arg := range this.Config.GetArgs() {
args[i] = magicString(arg, evt)
}
cmd := exec.Command(bin, args...)
cmd.Stdin = strings.NewReader(stdin)
var out bytes.Buffer
var sErr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &sErr
this.Log.Info("CLI CMD %s %s \"%s %s\"", evt.GetId(), this.GetName(), bin, strings.Join(args, " "))
err := cmd.Run()
if err != nil {
this.Log.HandlerError(this, err.Error(), &evt)
return
}
this.Log.Debug("CLI OUT %s %s \"%s\"", evt.GetId(), this.GetName(), out.String())
}
示例2: Exec
// Satisfies the Listener interface and calls the Lambda function
func (this *Lambda) Exec(evt event.Event) {
this.Log.Handler(this, &evt)
msg := magicString(this.Config.GetMessage(), evt)
reg := magicString(this.Config.GetRegion(), evt)
fun := magicString(this.Config.GetFunction(), evt)
svc := lambda.New(&aws.Config{Region: reg})
params := &lambda.InvokeInput{
FunctionName: aws.String(fun), // Required
Payload: []byte(msg),
}
resp, err := svc.Invoke(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
msg := fmt.Sprintf("%s %s", awsErr.Code(), awsErr.Message())
this.Log.HandlerError(this, msg, &evt)
if _, ok := err.(awserr.RequestFailure); ok {
}
} else {
this.Log.HandlerError(this, err.Error(), &evt)
}
return
}
this.Log.Debug("LAMBDA OUT %s %s \"%s\"", evt.GetId(), this.GetName(), awsutil.StringValue(resp))
}
示例3: magicString
// Replaces variables ("${}") in the string to their actual value
func magicString(s string, evt event.Event) string {
rep := regexp.MustCompile("(\\${|})")
rst := findMagicStrings(s)
for _, v := range rst {
variable := rep.ReplaceAllString(v, "")
opt := strings.Split(variable, ".")
switch opt[0] {
case "event":
b, _ := json.Marshal(evt)
s = strings.Replace(s, v, string(b), -1)
case "message":
str := ""
if len(opt) <= 1 {
b, _ := json.Marshal(evt.Message)
str = string(b)
} else {
str = evt.GetString(strings.Join(opt[1:], "."))
}
s = strings.Replace(s, v, str, -1)
}
}
return s
}
示例4: processRaw
// Convert a raw json string into an Event struct
func (s *Base) processRaw(msg string) event.Event {
var evt event.Event
if err := json.Unmarshal([]byte(msg), &evt); err != nil {
s.Log.Error("Can not turn string into event: %s", msg)
return evt
}
evt.Id = generateId()
s.Log.Event(&evt)
s.processEvent(evt)
return evt
}
示例5: Exec
// Satisfies the Listener interface and calls the relevant binary file
func (this *Cli) Exec(evt event.Event) {
this.Log.Handler(this, &evt)
bin := magicString(this.Config.GetBin(), evt)
stdin := magicString(this.Config.GetStdin(), evt)
args := append([]string(nil), this.Config.GetArgs()...)
for i, arg := range this.Config.GetArgs() {
args[i] = magicString(arg, evt)
}
cmd := exec.Command(bin, args...)
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
cmd.Stdin = strings.NewReader(stdin)
var out bytes.Buffer
var sErr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &sErr
this.Log.Info("CLI CMD %s %s \"%s %s\"", evt.GetId(), this.GetName(), bin, strings.Join(args, " "))
err := cmd.Start()
if err != nil {
this.Log.Error("CLI ERR %s %s \"%s\"", evt.GetId(), this.GetName(), sErr.String())
this.Log.HandlerError(this, err.Error(), &evt)
return
}
timeOut := this.Config.GetTimeout()
if timeOut == 0 {
if err := cmd.Wait(); err != nil {
this.Log.Error("CLI ERROR %s", err.Error())
}
} else {
// this allows us to set a timeout on the cli (phantomjs def needs this)
done := make(chan error, 1)
go func() {
done <- cmd.Wait()
}()
select {
case <-time.After(time.Duration(timeOut) * time.Second):
pgid, err := syscall.Getpgid(cmd.Process.Pid)
if err == nil {
syscall.Kill(-pgid, 15) // note the minus sign
this.Log.Warning("CLITIMEOUT %s %s", evt.GetId(), this.GetName())
}
<-done // allow goroutine to exit
case err := <-done:
if err != nil {
this.Log.Error("CLI ERROR %s", err.Error())
}
}
}
this.Log.Debug("CLI OUT %s %s \"%s\"", evt.GetId(), this.GetName(), out.String())
}
示例6: processRaw
// Convert a raw json string into an Event struct
func (s *Base) processRaw(msg string) event.Event {
var evt event.Event
if umsg, err := strconv.Unquote(msg); err == nil {
msg = umsg
}
if err := json.Unmarshal([]byte(msg), &evt); err != nil {
s.Log.Error("Can not turn string into event: %s", msg)
return evt
}
evt.Id = generateId()
s.Log.Event(&evt)
s.processEvent(evt)
s.Log.Info("Process %s \"%s\"", evt.Id, msg)
return evt
}