Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"config.go",
"stdout.go",
],
importpath = "go-common/app/service/ops/log-agent/output/stdout",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/ops/log-agent/event:go_default_library",
"//app/service/ops/log-agent/output:go_default_library",
"//vendor/github.com/BurntSushi/toml:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,27 @@
package stdout
import (
"errors"
"github.com/BurntSushi/toml"
)
type Config struct {
Name string `tome:"name"`
}
func (c *Config) ConfigValidate() (error) {
if c == nil {
return errors.New("config of Stdout Output is nil")
}
return nil
}
func DecodeConfig(md toml.MetaData, primValue toml.Primitive) (c interface{}, err error) {
c = new(Config)
if err = md.PrimitiveDecode(primValue, c); err != nil {
return nil, err
}
return c, nil
}

View File

@@ -0,0 +1,66 @@
package stdout
import (
"context"
"fmt"
"go-common/app/service/ops/log-agent/output"
"go-common/app/service/ops/log-agent/event"
)
type Stdout struct {
c *Config
ctx context.Context
cancel context.CancelFunc
i chan *event.ProcessorEvent
}
func init() {
err := output.Register("stdout", NewStdout)
if err != nil {
panic(err)
}
}
func NewStdout(ctx context.Context, config interface{}) (output.Output, error) {
var err error
stdout := new(Stdout)
if c, ok := config.(*Config); !ok {
return nil, fmt.Errorf("Error config for Lancer output")
} else {
if err = c.ConfigValidate(); err != nil {
return nil, err
}
stdout.c = c
}
stdout.i = make(chan *event.ProcessorEvent)
stdout.ctx, stdout.cancel = context.WithCancel(ctx)
return stdout, nil
}
func (s *Stdout) Run() (err error) {
go func() {
for {
select {
case e := <-s.i:
fmt.Println(string(e.Body))
case <-s.ctx.Done():
return
}
}
}()
if s.c.Name != "" {
output.RegisterOutput(s.c.Name, s)
}
return nil
}
func (s *Stdout) Stop() {
s.cancel()
}
func (s *Stdout) InputChan() (chan *event.ProcessorEvent) {
return s.i
}