Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
gllm-dev committed Apr 2, 2023
1 parent 2726688 commit c72f519
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
5 changes: 5 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ package fluentio

import "github.com/fluent/fluent-logger-golang/fluent"

// Config is used to configure the Writer.
type Config struct {
fluentConfig *fluent.Config
basicConfig *BasicConfig
tag string
}

// BasicConfig is used to configure the Writer with a basic configuration.
type BasicConfig struct {
FluentHost string
FluentPort int
}

// WithBasicConfig returns a function that can be used to configure the Writer with a basic configuration.
func WithBasicConfig(host string, port int) func(*Config) {
return func(c *Config) {
c.basicConfig = &BasicConfig{
Expand All @@ -22,12 +25,14 @@ func WithBasicConfig(host string, port int) func(*Config) {
}
}

// WithFluentConfig returns a function that can be used to configure the Writer with the standard fluent-logger-golang configuration.
func WithFluentConfig(config *fluent.Config) func(*Config) {
return func(c *Config) {
c.fluentConfig = config
}
}

// WithTag returns a function that can be used to configure the Writer with a tag.
func WithTag(tag string) func(*Config) {
return func(c *Config) {
c.tag = tag
Expand Down
1 change: 1 addition & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package fluentio
import "errors"

var (
// ErrNoConfigProvided is returned when no configuration is provided.
ErrNoConfigProvided = errors.New("no config provided")
)
5 changes: 5 additions & 0 deletions fluent.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import (
"io"
)

// Writer is an io.Writer that writes to fluentd.
type Writer struct {
client *fluent.Fluent
tag string
}

var _ io.Writer = (*Writer)(nil)

// New creates a new Writer.
// It accepts a variadic number of options that can be used to configure the Writer.
// If no options are provided, it will return an error.
func New(opts ...func(config *Config)) (*Writer, error) {
config := new(Config)
for _, opt := range opts {
Expand Down Expand Up @@ -56,6 +60,7 @@ func New(opts ...func(config *Config)) (*Writer, error) {
}, nil
}

// Write is the implementation of io.Writer.
func (f *Writer) Write(p []byte) (n int, err error) {
var m map[string]interface{}
err = json.Unmarshal(p, &m)
Expand Down

0 comments on commit c72f519

Please sign in to comment.