Skip to content

Commit

Permalink
add some comments in code
Browse files Browse the repository at this point in the history
Signed-off-by: tsaikd <tsaikd@gmail.com>
  • Loading branch information
tsaikd committed Jan 16, 2017
1 parent 12073ef commit 63c44c2
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 60 deletions.
9 changes: 6 additions & 3 deletions input/dockerlog/inputdockerlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"github.com/tsaikd/gogstash/config"
)

const (
ModuleName = "dockerlog"
)
// ModuleName is the name used in config file
const ModuleName = "dockerlog"

// InputConfig holds the configuration json fields and internal objects
type InputConfig struct {
config.InputConfig
DockerURL string `json:"dockerurl"`
Expand All @@ -31,6 +31,7 @@ type InputConfig struct {
client *docker.Client
}

// DefaultInputConfig returns an InputConfig struct with default values
func DefaultInputConfig() InputConfig {
return InputConfig{
InputConfig: config.InputConfig{
Expand All @@ -46,6 +47,7 @@ func DefaultInputConfig() InputConfig {
}
}

// InitHandler initialize the input plugin
func InitHandler(confraw *config.ConfigRaw) (retconf config.TypeInputConfig, err error) {
conf := DefaultInputConfig()
if err = config.ReflectConfig(confraw, &conf); err != nil {
Expand Down Expand Up @@ -74,6 +76,7 @@ func InitHandler(confraw *config.ConfigRaw) (retconf config.TypeInputConfig, err
return
}

// Start wraps the actual function starting the plugin
func (t *InputConfig) Start() {
t.Invoke(t.start)
}
Expand Down
9 changes: 6 additions & 3 deletions input/dockerstats/inputdockerstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"github.com/tsaikd/gogstash/config"
)

const (
ModuleName = "dockerstats"
)
// ModuleName is the name used in config file
const ModuleName = "dockerstats"

// InputConfig holds the configuration json fields and internal objects
type InputConfig struct {
config.InputConfig
DockerURL string `json:"dockerurl"`
Expand All @@ -32,6 +32,7 @@ type InputConfig struct {
client *docker.Client
}

// DefaultInputConfig returns an InputConfig struct with default values
func DefaultInputConfig() InputConfig {
return InputConfig{
InputConfig: config.InputConfig{
Expand All @@ -48,6 +49,7 @@ func DefaultInputConfig() InputConfig {
}
}

// InitHandler initialize the input plugin
func InitHandler(confraw *config.ConfigRaw) (retconf config.TypeInputConfig, err error) {
conf := DefaultInputConfig()
if err = config.ReflectConfig(confraw, &conf); err != nil {
Expand All @@ -73,6 +75,7 @@ func InitHandler(confraw *config.ConfigRaw) (retconf config.TypeInputConfig, err
return
}

// Start wraps the actual function starting the plugin
func (t *InputConfig) Start() {
t.Invoke(t.start)
}
Expand Down
11 changes: 7 additions & 4 deletions input/exec/inputexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
"github.com/tsaikd/gogstash/config/logevent"
)

const (
ModuleName = "exec"
)
// ModuleName is the name used in config file
const ModuleName = "exec"

// InputConfig holds the configuration json fields and internal objects
type InputConfig struct {
config.InputConfig
Command string `json:"command"` // Command to run. e.g. “uptime”
Expand All @@ -28,9 +28,10 @@ type InputConfig struct {
MsgPrefix string `json:"message_prefix,omitempty"` // only in text type, e.g. "%{@timestamp} [uptime] "
MsgType MsgType `json:"message_type,omitempty"` // default: "text"

hostname string `json:"-"`
hostname string
}

// DefaultInputConfig returns an InputConfig struct with default values
func DefaultInputConfig() InputConfig {
return InputConfig{
InputConfig: config.InputConfig{
Expand All @@ -44,6 +45,7 @@ func DefaultInputConfig() InputConfig {
}
}

// InitHandler initialize the input plugin
func InitHandler(confraw *config.ConfigRaw) (retconf config.TypeInputConfig, err error) {
conf := DefaultInputConfig()
if err = config.ReflectConfig(confraw, &conf); err != nil {
Expand All @@ -58,6 +60,7 @@ func InitHandler(confraw *config.ConfigRaw) (retconf config.TypeInputConfig, err
return
}

// Start wraps the actual function starting the plugin
func (self *InputConfig) Start() {
startChan := make(chan bool) // startup tick
ticker := time.NewTicker(time.Duration(self.Interval) * time.Second)
Expand Down
20 changes: 9 additions & 11 deletions input/file/inputfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,24 @@ import (
"github.com/tsaikd/gogstash/config/logevent"
)

const (
ModuleName = "file"
)
// ModuleName is the name used in config file
const ModuleName = "file"

// InputConfig holds the configuration json fields and internal objects
type InputConfig struct {
config.InputConfig
Path string `json:"path"`
StartPos string `json:"start_position,omitempty"` // one of ["beginning", "end"]
SinceDBPath string `json:"sincedb_path,omitempty"`
SinceDBWriteInterval int `json:"sincedb_write_interval,omitempty"`

hostname string `json:"-"`
hostname string
SinceDBInfos map[string]*SinceDBInfo `json:"-"`
sinceDBLastInfosRaw []byte `json:"-"`
SinceDBLastSaveTime time.Time `json:"-"`
sinceDBLastInfosRaw []byte
SinceDBLastSaveTime time.Time `json:"-"`
}

// DefaultInputConfig returns an InputConfig struct with default values
func DefaultInputConfig() InputConfig {
return InputConfig{
InputConfig: config.InputConfig{
Expand All @@ -49,6 +50,7 @@ func DefaultInputConfig() InputConfig {
}
}

// InitHandler initialize the input plugin
func InitHandler(confraw *config.ConfigRaw) (retconf config.TypeInputConfig, err error) {
conf := DefaultInputConfig()
if err = config.ReflectConfig(confraw, &conf); err != nil {
Expand All @@ -63,6 +65,7 @@ func InitHandler(confraw *config.ConfigRaw) (retconf config.TypeInputConfig, err
return
}

// Start wraps the actual function starting the plugin
func (t *InputConfig) Start() {
t.Invoke(t.start)
}
Expand Down Expand Up @@ -230,7 +233,6 @@ func (self *InputConfig) fileWatchLoop(readEventChan chan fsnotify.Event, fpath
}
readEventChan <- event
}
return
}

func isFileTruncated(fp *os.File, since *SinceDBInfo) (truncated bool, err error) {
Expand Down Expand Up @@ -292,8 +294,6 @@ func readline(reader *bufio.Reader, buffer *bytes.Buffer) (line string, size int
return
}
}

return
}

func isPartialLine(segment []byte) bool {
Expand Down Expand Up @@ -354,6 +354,4 @@ func waitWatchEvent(fpath string, op fsnotify.Op) (event fsnotify.Event, err err
return
}
}

return
}
1 change: 0 additions & 1 deletion input/file/sincedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,4 @@ func (self *InputConfig) CheckSaveSinceDBInfosLoop() (err error) {
return
}
}
return
}
11 changes: 7 additions & 4 deletions input/http/inputhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ import (
"github.com/tsaikd/gogstash/config/logevent"
)

const (
ModuleName = "http"
)
// ModuleName is the name used in config file
const ModuleName = "http"

// InputConfig holds the configuration json fields and internal objects
type InputConfig struct {
config.InputConfig
Method string `json:"method,omitempty"` // one of ["HEAD", "GET"]
Url string `json:"url"`
Interval int `json:"interval,omitempty"`

hostname string `json:"-"`
hostname string
}

// DefaultInputConfig returns an InputConfig struct with default values
func DefaultInputConfig() InputConfig {
return InputConfig{
InputConfig: config.InputConfig{
Expand All @@ -39,6 +40,7 @@ func DefaultInputConfig() InputConfig {
}
}

// InitHandler initialize the input plugin
func InitHandler(confraw *config.ConfigRaw) (retconf config.TypeInputConfig, err error) {
conf := DefaultInputConfig()
if err = config.ReflectConfig(confraw, &conf); err != nil {
Expand All @@ -53,6 +55,7 @@ func InitHandler(confraw *config.ConfigRaw) (retconf config.TypeInputConfig, err
return
}

// Start wraps the actual function starting the plugin
func (t *InputConfig) Start() {
t.Invoke(t.start)
}
Expand Down
2 changes: 1 addition & 1 deletion input/httplisten/httplisten.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const invalidMethodError = "Method not allowed: '%v'"
const invalidJsonError = "Invalid JSON received on HTTP listener. Decoder error: %+v"
const invalidAccessToken = "Invalid access token. Access denied."

// InputConfig holds the output configuration json fields
// InputConfig holds the configuration json fields and internal objects
type InputConfig struct {
config.InputConfig
Address string `json:"address"` // host:port to listen on
Expand Down
3 changes: 2 additions & 1 deletion input/redis/inputredis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package inputredis
import (
"bytes"
"encoding/json"

"github.com/Sirupsen/logrus"
"github.com/fzzy/radix/redis"
"github.com/tsaikd/gogstash/config"
Expand All @@ -14,7 +15,7 @@ const ModuleName = "redis"

const invalidJsonError = "Invalid JSON received from Redis input. Decoder error: %+v"

// InputConfig holds the output configuration json fields
// InputConfig holds the configuration json fields and internal objects
type InputConfig struct {
config.InputConfig
Key string `json:"key"`
Expand Down
3 changes: 1 addition & 2 deletions input/socket/inputsocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

"github.com/Sirupsen/logrus"

"github.com/tsaikd/KDGoLib/errutil"
"github.com/tsaikd/gogstash/config"
"github.com/tsaikd/gogstash/config/logevent"
Expand All @@ -18,7 +17,7 @@ import (
// ModuleName is the name used in config file
const ModuleName = "socket"

// InputConfig holds the output configuration json fields
// InputConfig holds the configuration json fields and internal objects
type InputConfig struct {
config.InputConfig
Socket string `json:"socket"` // Type of socket, must be one of ["tcp", "unix", "unixpacket"].
Expand Down
2 changes: 1 addition & 1 deletion output/amqp/outputamqp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (
ErrorNoValidConn = errutil.NewFactory("no valid amqp server connection found")
)

// OutputConfig holds the output configuration json fields and internal objects
// OutputConfig holds the configuration json fields and internal objects
type OutputConfig struct {
config.OutputConfig
URLs []string `json:"urls"` // Array of AMQP connection strings formatted per the [RabbitMQ URI Spec](http://www.rabbitmq.com/uri-spec.html).
Expand Down
13 changes: 8 additions & 5 deletions output/elastic/outputelastic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ package outputelastic

import (
"encoding/json"
"io/ioutil"
"net/http"

"github.com/Sirupsen/logrus"
"github.com/hashicorp/go-version"
"github.com/tsaikd/gogstash/config"
"github.com/tsaikd/gogstash/config/logevent"
"golang.org/x/net/context"
elastic3 "gopkg.in/olivere/elastic.v3"
elastic5 "gopkg.in/olivere/elastic.v5"
"io/ioutil"
"net/http"
)

const (
ModuleName = "elastic"
)
// ModuleName is the name used in config file
const ModuleName = "elastic"

// OutputConfig holds the configuration json fields and internal objects
type OutputConfig struct {
config.OutputConfig
URL string `json:"url"`
Expand All @@ -31,6 +32,7 @@ type OutputConfig struct {
clientVersion int // private var to hold client version to use after detection
}

// DefaultOutputConfig returns an OutputConfig struct with default values
func DefaultOutputConfig() OutputConfig {
return OutputConfig{
OutputConfig: config.OutputConfig{
Expand All @@ -42,6 +44,7 @@ func DefaultOutputConfig() OutputConfig {
}
}

// InitHandler initialize the output plugin
func InitHandler(confraw *config.ConfigRaw, logger *logrus.Logger) (retconf config.TypeOutputConfig, err error) {
conf := DefaultOutputConfig()
if err = config.ReflectConfig(confraw, &conf); err != nil {
Expand Down
12 changes: 5 additions & 7 deletions output/email/outputemail.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import (
"gopkg.in/gomail.v2"
)

// ModuleName the module name of this plugin
const (
ModuleName = "email"
)
// ModuleName is the name used in config file
const ModuleName = "email"

// OutputConfig the default output config
// OutputConfig holds the configuration json fields and internal objects
type OutputConfig struct {
config.OutputConfig
Address string `json:"address"`
Expand All @@ -29,7 +27,7 @@ type OutputConfig struct {
Password string `json:"password"`
}

// DefaultOutputConfig build the default output config
// DefaultOutputConfig returns an OutputConfig struct with default values
func DefaultOutputConfig() OutputConfig {
return OutputConfig{
OutputConfig: config.OutputConfig{
Expand All @@ -46,7 +44,7 @@ func DefaultOutputConfig() OutputConfig {
}
}

// InitHandler init the handler
// InitHandler initialize the output plugin
func InitHandler(confraw *config.ConfigRaw) (retconf config.TypeOutputConfig, err error) {
conf := DefaultOutputConfig()
if err = config.ReflectConfig(confraw, &conf); err != nil {
Expand Down
8 changes: 5 additions & 3 deletions output/prometheus/outputprometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ import (
"github.com/tsaikd/gogstash/config/logevent"
)

const (
ModuleName = "prometheus"
)
// ModuleName is the name used in config file
const ModuleName = "prometheus"

// OutputConfig holds the configuration json fields and internal objects
type OutputConfig struct {
config.OutputConfig
Address string `json:"address,omitempty"`

MsgCount prometheus.Counter `json:"-"`
}

// DefaultOutputConfig returns an OutputConfig struct with default values
func DefaultOutputConfig() OutputConfig {
return OutputConfig{
OutputConfig: config.OutputConfig{
Expand All @@ -36,6 +37,7 @@ func DefaultOutputConfig() OutputConfig {
}
}

// InitHandler initialize the output plugin
func InitHandler(confraw *config.ConfigRaw, logger *logrus.Logger) (retconf config.TypeOutputConfig, err error) {
conf := DefaultOutputConfig()
if err = config.ReflectConfig(confraw, &conf); err != nil {
Expand Down
Loading

0 comments on commit 63c44c2

Please sign in to comment.