Permalink
Browse files

fix formatting

  • Loading branch information...
1 parent 924fe77 commit c0992cfc07f31be57435dd321d361594af7f7a2c @cyberdelia committed Feb 19, 2012
Showing with 53 additions and 53 deletions.
  1. +19 −19 statsd.go
  2. +34 −34 statsd_test.go
View
@@ -1,16 +1,16 @@
package statsd
import (
- "math/rand"
- "bufio"
+ "bufio"
+ "fmt"
"io"
+ "math/rand"
"net"
- "fmt"
)
type Client struct {
- Name string
- rw *bufio.ReadWriter
+ Name string
+ rw *bufio.ReadWriter
}
func Dial(addr string) (*Client, error) {
@@ -22,10 +22,10 @@ func Dial(addr string) (*Client, error) {
}
func newClient(name string, rw io.ReadWriter) *Client {
- c := new(Client)
- c.Name = name
- c.rw = bufio.NewReadWriter(bufio.NewReader(rw), bufio.NewWriter(rw))
- return c
+ c := new(Client)
+ c.Name = name
+ c.rw = bufio.NewReadWriter(bufio.NewReader(rw), bufio.NewWriter(rw))
+ return c
}
func (c *Client) Increment(stat string, count int, rate float64) error {
@@ -41,14 +41,14 @@ func (c *Client) Timing(stat string, delta int, rate float64) error {
}
func (c *Client) Send(stat string, rate float64, format string, args ...interface{}) error {
- if rate < 1 {
- if rand.Float64() < rate {
- format = fmt.Sprintf("%s|@%1.2f", format, rate)
- } else {
- return nil
- }
- }
- format = fmt.Sprintf("%s:%s", stat, format)
- _, err := fmt.Fprintf(c.rw, format, args...)
- return err
+ if rate < 1 {
+ if rand.Float64() < rate {
+ format = fmt.Sprintf("%s|@%1.2f", format, rate)
+ } else {
+ return nil
+ }
+ }
+ format = fmt.Sprintf("%s:%s", stat, format)
+ _, err := fmt.Fprintf(c.rw, format, args...)
+ return err
}
View
@@ -1,57 +1,57 @@
package statsd
import (
- "github.com/bmizerany/assert"
- "io"
- "testing"
- "bufio"
- "bytes"
+ "bufio"
+ "bytes"
+ "github.com/bmizerany/assert"
+ "io"
+ "testing"
)
type ReadWriter struct {
- io.Reader
- io.Writer
+ io.Reader
+ io.Writer
}
-func fake() (io.ReadWriter) {
- buffer := bytes.NewBufferString("")
- return &ReadWriter{buffer, buffer}
+func fake() io.ReadWriter {
+ buffer := bytes.NewBufferString("")
+ return &ReadWriter{buffer, buffer}
}
func readData(rw *bufio.ReadWriter) string {
- rw.Flush()
- data, _ , _ := rw.ReadLine()
- return string(data)
+ rw.Flush()
+ data, _, _ := rw.ReadLine()
+ return string(data)
}
func TestIncrement(t *testing.T) {
- c := newClient("<fake>", fake())
- err := c.Increment("incr", 1, 1)
- assert.Equal(t, err, nil)
- data := readData(c.rw)
- assert.Equal(t, data, "incr:1|c")
+ c := newClient("<fake>", fake())
+ err := c.Increment("incr", 1, 1)
+ assert.Equal(t, err, nil)
+ data := readData(c.rw)
+ assert.Equal(t, data, "incr:1|c")
}
func TestDecrement(t *testing.T) {
- c := newClient("<fake>", fake())
- err := c.Decrement("decr", 1, 1)
- assert.Equal(t, err, nil)
- data := readData(c.rw)
- assert.Equal(t, data, "decr:-1|c")
+ c := newClient("<fake>", fake())
+ err := c.Decrement("decr", 1, 1)
+ assert.Equal(t, err, nil)
+ data := readData(c.rw)
+ assert.Equal(t, data, "decr:-1|c")
}
func TestTiming(t *testing.T) {
- c := newClient("<fake>", fake())
- err := c.Timing("time", 350, 1)
- assert.Equal(t, err, nil)
- data := readData(c.rw)
- assert.Equal(t, data, "time:350|ms")
+ c := newClient("<fake>", fake())
+ err := c.Timing("time", 350, 1)
+ assert.Equal(t, err, nil)
+ data := readData(c.rw)
+ assert.Equal(t, data, "time:350|ms")
}
func TestIncrementRate(t *testing.T) {
- c := newClient("<fake>", fake())
- err := c.Increment("incr", 1, 0.99)
- assert.Equal(t, err, nil)
- data := readData(c.rw)
- assert.Equal(t, data, "incr:1|c|@0.99")
-}
+ c := newClient("<fake>", fake())
+ err := c.Increment("incr", 1, 0.99)
+ assert.Equal(t, err, nil)
+ data := readData(c.rw)
+ assert.Equal(t, data, "incr:1|c|@0.99")
+}

0 comments on commit c0992cf

Please sign in to comment.