Move ParsedRequest{} to gor/utils sub-package

This de-dupes the type definition used in both `listener` and `replay`.
This commit is contained in:
Dan Carley
2013-10-23 17:17:32 +01:00
parent 714307890e
commit e7c1d86bfa
3 changed files with 21 additions and 19 deletions
+3 -6
View File
@@ -15,12 +15,9 @@ import (
"os"
"strconv"
"time"
)
type ParsedRequest struct {
Timestamp int64
Request []byte
}
"github.com/buger/gor/utils"
)
// Debug enables logging only if "--verbose" flag passed
func Debug(v ...interface{}) {
@@ -97,7 +94,7 @@ func Run() {
if Settings.FileToReplayPath != "" {
go func() {
message := ParsedRequest{time.Now().UnixNano(), m.Bytes()}
message := utils.ParsedRequest{time.Now().UnixNano(), m.Bytes()}
fileEnc.Encode(message)
}()
} else {
+4 -13
View File
@@ -7,19 +7,10 @@ import (
"io/ioutil"
"log"
"fmt"
"github.com/buger/gor/utils"
)
type ParsedRequest struct {
Timestamp int64
Request []byte
}
func (self ParsedRequest) String() string {
return fmt.Sprintf("Request: %v, timestamp: %v", string(self.Request), self.Timestamp)
}
func parseReplayFile() (requests []ParsedRequest, err error) {
func parseReplayFile() (requests []utils.ParsedRequest, err error) {
requests, err = readLines(Settings.FileToReplayPath)
if err != nil {
@@ -31,7 +22,7 @@ func parseReplayFile() (requests []ParsedRequest, err error) {
// readLines reads a whole file into memory
// and returns a slice of request+timestamps.
func readLines(path string) (requests []ParsedRequest, err error) {
func readLines(path string) (requests []utils.ParsedRequest, err error) {
file, err := ioutil.ReadFile(path)
if err != nil {
@@ -42,7 +33,7 @@ func readLines(path string) (requests []ParsedRequest, err error) {
fileDec := gob.NewDecoder(fileBuf)
for err == nil {
var reqBuf ParsedRequest
var reqBuf utils.ParsedRequest
err = fileDec.Decode(&reqBuf)
if err == io.EOF {
+14
View File
@@ -0,0 +1,14 @@
package utils
import (
"fmt"
)
type ParsedRequest struct {
Timestamp int64
Request []byte
}
func (self ParsedRequest) String() string {
return fmt.Sprintf("Request: %v, timestamp: %v", string(self.Request), self.Timestamp)
}