Skip to content

Commit

Permalink
go fmt (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Sirianni authored May 6, 2021
1 parent 5d02efc commit 5fb66f5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
24 changes: 12 additions & 12 deletions operator/builtin/input/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package tcp
import (
"bufio"
"context"
"crypto/rand"
"crypto/tls"
"fmt"
"net"
"sync"
"time"
"crypto/rand"
"crypto/tls"

"github.com/observiq/stanza/operator"
"github.com/observiq/stanza/operator/helper"
Expand All @@ -18,11 +18,11 @@ import (
const (
// minBufferSize is the initial size used for buffering
// TCP input
minBufferSize = 64*1024
minBufferSize = 64 * 1024

// DefaultMaxBufferSize is the max buffer sized used
// if MaxBufferSize is not set
DefaultMaxBufferSize = 1024*1024
DefaultMaxBufferSize = 1024 * 1024
)

func init() {
Expand All @@ -41,20 +41,20 @@ type TCPInputConfig struct {
helper.InputConfig `yaml:",inline"`

MaxBufferSize helper.ByteSize `json:"max_buffer_size,omitempty" yaml:"max_buffer_size,omitempty"`
ListenAddress string `json:"listen_address,omitempty" yaml:"listen_address,omitempty"`
TLS TLSConfig `json:"tls,omitempty" yaml:"tls,omitempty"`
ListenAddress string `json:"listen_address,omitempty" yaml:"listen_address,omitempty"`
TLS TLSConfig `json:"tls,omitempty" yaml:"tls,omitempty"`
}

// TLSConfig is the configuration for a TLS listener
type TLSConfig struct {
// Enable forces the user of TLS
Enable bool `json:"enable,omitempty" yaml:"enable,omitempty"`
Enable bool `json:"enable,omitempty" yaml:"enable,omitempty"`

// Certificate is the file path for the certificate
Certificate string `json:"certificate,omitempty" yaml:"certificate,omitempty"`

// PrivateKey is the file path for the private key
PrivateKey string `json:"private_key,omitempty" yaml:"private_key,omitempty"`
PrivateKey string `json:"private_key,omitempty" yaml:"private_key,omitempty"`
}

// Build will build a tcp input operator.
Expand Down Expand Up @@ -136,7 +136,7 @@ func (t *TCPInput) Start() error {
}

func (t *TCPInput) configureListener() error {
if ! t.tlsEnable {
if !t.tlsEnable {
listener, err := net.Listen("tcp", t.address)
if err != nil {
return fmt.Errorf("failed to configure tcp listener: %w", err)
Expand Down Expand Up @@ -206,10 +206,10 @@ func (t *TCPInput) goHandleMessages(ctx context.Context, conn net.Conn, cancel c
defer t.wg.Done()
defer cancel()

// Initial buffer size is 64k
buf := make([]byte, 0, 64 * 1024)
// Initial buffer size is 64k
buf := make([]byte, 0, 64*1024)
scanner := bufio.NewScanner(conn)
scanner.Buffer(buf, t.maxBufferSize * 1024)
scanner.Buffer(buf, t.maxBufferSize*1024)
for scanner.Scan() {
entry, err := t.NewEntry(scanner.Text())
if err != nil {
Expand Down
36 changes: 18 additions & 18 deletions operator/builtin/input/tcp/tcp_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package tcp

import (
"os"
"crypto/tls"
"net"
"os"
"testing"
"time"
"crypto/tls"

"github.com/observiq/stanza/entry"
"github.com/observiq/stanza/operator"
Expand Down Expand Up @@ -117,26 +117,26 @@ func tlsTCPInputTest(input []byte, expected []string) func(t *testing.T) {
return func(t *testing.T) {

f, err := os.Create("test.crt")
require.NoError(t, err)
defer f.Close()
require.NoError(t, err)
defer f.Close()
defer os.Remove("test.crt")
_, err = f.WriteString(testTLSCertificate + "\n")
require.NoError(t, err)
_, err = f.WriteString(testTLSCertificate + "\n")
require.NoError(t, err)
f.Close()

f, err = os.Create("test.key")
require.NoError(t, err)
defer f.Close()
require.NoError(t, err)
defer f.Close()
defer os.Remove("test.key")
_, err = f.WriteString(testTLSPrivateKey + "\n")
require.NoError(t, err)
_, err = f.WriteString(testTLSPrivateKey + "\n")
require.NoError(t, err)
f.Close()

cfg := NewTCPInputConfig("test_id")
cfg.ListenAddress = ":0"
cfg.TLS.Enable = true
cfg.TLS.Certificate = "test.crt"
cfg.TLS.PrivateKey = "test.key"
cfg.TLS.PrivateKey = "test.key"

ops, err := cfg.Build(testutil.NewBuildContext(t))
require.NoError(t, err)
Expand Down Expand Up @@ -182,9 +182,9 @@ func tlsTCPInputTest(input []byte, expected []string) func(t *testing.T) {

func TestBuild(t *testing.T) {
cases := []struct {
name string
inputRecord TCPInputConfig
expectErr bool
name string
inputRecord TCPInputConfig
expectErr bool
}{
{
"default-auto-address",
Expand Down Expand Up @@ -237,9 +237,9 @@ func TestBuild(t *testing.T) {
MaxBufferSize: 65536,
ListenAddress: "10.0.0.1:9000",
TLS: TLSConfig{
Enable: false,
Enable: false,
Certificate: "/tmp/cert",
PrivateKey: "/tmp/key",
PrivateKey: "/tmp/key",
},
},
false,
Expand All @@ -250,9 +250,9 @@ func TestBuild(t *testing.T) {
MaxBufferSize: 65536,
ListenAddress: "10.0.0.1:9000",
TLS: TLSConfig{
Enable: true,
Enable: true,
Certificate: "/tmp/cert/missing",
PrivateKey: "/tmp/key/missing",
PrivateKey: "/tmp/key/missing",
},
},
true,
Expand Down

0 comments on commit 5fb66f5

Please sign in to comment.