fix json tags

main
Ben Grewell 4 years ago
parent 915d82f477
commit b4061779c1

@ -4,6 +4,8 @@
<list default="true" id="fc2840de-29dc-4fca-8e0e-a283562f60ca" name="Default Changelist" comment=""> <list default="true" id="fc2840de-29dc-4fca-8e0e-a283562f60ca" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/client.go" beforeDir="false" afterPath="$PROJECT_DIR$/client.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/client.go" beforeDir="false" afterPath="$PROJECT_DIR$/client.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/main.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/server.go" beforeDir="false" afterPath="$PROJECT_DIR$/server.go" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />

@ -20,7 +20,7 @@ func NewClient(host string) *Client {
length := "128KB" length := "128KB"
streams := 1 streams := 1
c := &Client{ c := &Client{
options: &ClientOptions{ Options: &ClientOptions{
JSON: &json, JSON: &json,
Proto: &proto, Proto: &proto,
TimeSec: &time, TimeSec: &time,
@ -62,121 +62,121 @@ type ClientOptions struct {
} }
type Client struct { type Client struct {
Id string `json:"id" yaml:"id" xml:"id"` Id string `json:"id" yaml:"id" xml:"id"`
Running bool `json:"running" yaml:"running" xml:"running"` Running bool `json:"running" yaml:"running" xml:"running"`
Done chan bool `json:"done" yaml:"done" xml:"done"` Done chan bool
options *ClientOptions `json:"options" yaml:"options" xml:"options"` Options *ClientOptions `json:"Options" yaml:"Options" xml:"Options"`
exitCode *int `json:"exit_code" yaml:"exit_code" xml:"exit_code"` exitCode *int
report *TestReport `json:"report" yaml:"report" xml:"report"` report *TestReport
outputStream io.ReadCloser `json:"output_stream" yaml:"output_stream" xml:"output_stream"` outputStream io.ReadCloser
errorStream io.ReadCloser `json:"error_stream" yaml:"error_stream" xml:"error_stream"` errorStream io.ReadCloser
cancel context.CancelFunc `json:"cancel" yaml:"cancel" xml:"cancel"` cancel context.CancelFunc
mode TestMode `json:"mode" yaml:"mode" xml:"mode"` mode TestMode
live bool `json:"live" yaml:"live" xml:"live"` live bool
reportingChan chan *StreamIntervalReport `json:"reporting_chan" yaml:"reporting_chan" xml:"reporting_chan"` reportingChan chan *StreamIntervalReport
reportingFile string `json:"reporting_file" yaml:"reporting_file" xml:"reporting_file"` reportingFile string
} }
func (c *Client) LoadOptionsJSON(jsonStr string) (err error) { func (c *Client) LoadOptionsJSON(jsonStr string) (err error) {
return json.Unmarshal([]byte(jsonStr), c.options) return json.Unmarshal([]byte(jsonStr), c.Options)
} }
func (c *Client) LoadOptions(options *ClientOptions) { func (c *Client) LoadOptions(options *ClientOptions) {
c.options = options c.Options = options
} }
func (c *Client) commandString() (cmd string, err error) { func (c *Client) commandString() (cmd string, err error) {
builder := strings.Builder{} builder := strings.Builder{}
if c.options.Host == nil || *c.options.Host == "" { if c.Options.Host == nil || *c.Options.Host == "" {
return "", errors.New("unable to execute client. The field 'host' is required") return "", errors.New("unable to execute client. The field 'host' is required")
} }
fmt.Fprintf(&builder, "%s -c %s", binaryLocation, c.Host()) fmt.Fprintf(&builder, "%s -c %s", binaryLocation, c.Host())
if c.options.Port != nil { if c.Options.Port != nil {
fmt.Fprintf(&builder, " -p %d", c.Port()) fmt.Fprintf(&builder, " -p %d", c.Port())
} }
if c.options.Format != nil && *c.options.Format != ' ' { if c.Options.Format != nil && *c.Options.Format != ' ' {
fmt.Fprintf(&builder, " -f %c", c.Format()) fmt.Fprintf(&builder, " -f %c", c.Format())
} }
if c.options.Interval != nil { if c.Options.Interval != nil {
fmt.Fprintf(&builder, " -i %d", c.Interval()) fmt.Fprintf(&builder, " -i %d", c.Interval())
} }
if c.options.Proto != nil && *c.options.Proto == PROTO_UDP { if c.Options.Proto != nil && *c.Options.Proto == PROTO_UDP {
fmt.Fprintf(&builder, " -u") fmt.Fprintf(&builder, " -u")
} }
if c.options.Bandwidth != nil { if c.Options.Bandwidth != nil {
fmt.Fprintf(&builder, " -b %s", c.Bandwidth()) fmt.Fprintf(&builder, " -b %s", c.Bandwidth())
} }
if c.options.TimeSec != nil { if c.Options.TimeSec != nil {
fmt.Fprintf(&builder, " -t %d", c.TimeSec()) fmt.Fprintf(&builder, " -t %d", c.TimeSec())
} }
if c.options.Bytes != nil { if c.Options.Bytes != nil {
fmt.Fprintf(&builder, " -n %s", c.Bytes()) fmt.Fprintf(&builder, " -n %s", c.Bytes())
} }
if c.options.BlockCount != nil { if c.Options.BlockCount != nil {
fmt.Fprintf(&builder, " -k %s", c.BlockCount()) fmt.Fprintf(&builder, " -k %s", c.BlockCount())
} }
if c.options.Length != nil { if c.Options.Length != nil {
fmt.Fprintf(&builder, " -l %s", c.Length()) fmt.Fprintf(&builder, " -l %s", c.Length())
} }
if c.options.Streams != nil { if c.Options.Streams != nil {
fmt.Fprintf(&builder, " -P %d", c.Streams()) fmt.Fprintf(&builder, " -P %d", c.Streams())
} }
if c.options.Reverse != nil && *c.options.Reverse { if c.Options.Reverse != nil && *c.Options.Reverse {
builder.WriteString(" -R") builder.WriteString(" -R")
} }
if c.options.Window != nil { if c.Options.Window != nil {
fmt.Fprintf(&builder, " -w %s", c.Window()) fmt.Fprintf(&builder, " -w %s", c.Window())
} }
if c.options.MSS != nil { if c.Options.MSS != nil {
fmt.Fprintf(&builder, " -M %d", c.MSS()) fmt.Fprintf(&builder, " -M %d", c.MSS())
} }
if c.options.NoDelay != nil && *c.options.NoDelay { if c.Options.NoDelay != nil && *c.Options.NoDelay {
builder.WriteString(" -N") builder.WriteString(" -N")
} }
if c.options.Version6 != nil && *c.options.Version6 { if c.Options.Version6 != nil && *c.Options.Version6 {
builder.WriteString(" -6") builder.WriteString(" -6")
} }
if c.options.TOS != nil { if c.Options.TOS != nil {
fmt.Fprintf(&builder, " -S %d", c.TOS()) fmt.Fprintf(&builder, " -S %d", c.TOS())
} }
if c.options.ZeroCopy != nil && *c.options.ZeroCopy { if c.Options.ZeroCopy != nil && *c.Options.ZeroCopy {
builder.WriteString(" -Z") builder.WriteString(" -Z")
} }
if c.options.OmitSec != nil { if c.Options.OmitSec != nil {
fmt.Fprintf(&builder, " -O %d", c.OmitSec()) fmt.Fprintf(&builder, " -O %d", c.OmitSec())
} }
if c.options.Prefix != nil { if c.Options.Prefix != nil {
fmt.Fprintf(&builder, " -T %s", c.Prefix()) fmt.Fprintf(&builder, " -T %s", c.Prefix())
} }
if c.options.LogFile != nil && *c.options.LogFile != "" { if c.Options.LogFile != nil && *c.Options.LogFile != "" {
fmt.Fprintf(&builder, " --logfile %s", c.LogFile()) fmt.Fprintf(&builder, " --logfile %s", c.LogFile())
} }
if c.options.JSON != nil && *c.options.JSON { if c.Options.JSON != nil && *c.Options.JSON {
builder.WriteString(" -J") builder.WriteString(" -J")
} }
if c.options.IncludeServer != nil && *c.options.IncludeServer { if c.Options.IncludeServer != nil && *c.Options.IncludeServer {
builder.WriteString(" --get-server-output") builder.WriteString(" --get-server-output")
} }
@ -184,275 +184,275 @@ func (c *Client) commandString() (cmd string, err error) {
} }
func (c *Client) Host() string { func (c *Client) Host() string {
if c.options.Host == nil { if c.Options.Host == nil {
return "" return ""
} }
return *c.options.Host return *c.Options.Host
} }
func (c *Client) SetHost(host string) { func (c *Client) SetHost(host string) {
c.options.Host = &host c.Options.Host = &host
} }
func (c *Client) Port() int { func (c *Client) Port() int {
if c.options.Port == nil { if c.Options.Port == nil {
return 5201 return 5201
} }
return *c.options.Port return *c.Options.Port
} }
func (c *Client) SetPort(port int) { func (c *Client) SetPort(port int) {
c.options.Port = &port c.Options.Port = &port
} }
func (c *Client) Format() rune { func (c *Client) Format() rune {
if c.options.Format == nil { if c.Options.Format == nil {
return ' ' return ' '
} }
return *c.options.Format return *c.Options.Format
} }
func (c *Client) SetFormat(format rune) { func (c *Client) SetFormat(format rune) {
c.options.Format = &format c.Options.Format = &format
} }
func (c *Client) Interval() int { func (c *Client) Interval() int {
if c.options.Interval == nil { if c.Options.Interval == nil {
return 1 return 1
} }
return *c.options.Interval return *c.Options.Interval
} }
func (c *Client) SetInterval(interval int) { func (c *Client) SetInterval(interval int) {
c.options.Interval = &interval c.Options.Interval = &interval
} }
func (c *Client) Proto() Protocol { func (c *Client) Proto() Protocol {
if c.options.Proto == nil { if c.Options.Proto == nil {
return PROTO_TCP return PROTO_TCP
} }
return *c.options.Proto return *c.Options.Proto
} }
func (c *Client) SetProto(proto Protocol) { func (c *Client) SetProto(proto Protocol) {
c.options.Proto = &proto c.Options.Proto = &proto
} }
func (c *Client) Bandwidth() string { func (c *Client) Bandwidth() string {
if c.options.Bandwidth == nil && c.Proto() == PROTO_TCP { if c.Options.Bandwidth == nil && c.Proto() == PROTO_TCP {
return "0" return "0"
} else if c.options.Bandwidth == nil && c.Proto() == PROTO_UDP { } else if c.Options.Bandwidth == nil && c.Proto() == PROTO_UDP {
return "1M" return "1M"
} }
return *c.options.Bandwidth return *c.Options.Bandwidth
} }
func (c *Client) SetBandwidth(bandwidth string) { func (c *Client) SetBandwidth(bandwidth string) {
c.options.Bandwidth = &bandwidth c.Options.Bandwidth = &bandwidth
} }
func (c *Client) TimeSec() int { func (c *Client) TimeSec() int {
if c.options.TimeSec == nil { if c.Options.TimeSec == nil {
return 10 return 10
} }
return *c.options.TimeSec return *c.Options.TimeSec
} }
func (c *Client) SetTimeSec(timeSec int) { func (c *Client) SetTimeSec(timeSec int) {
c.options.TimeSec = &timeSec c.Options.TimeSec = &timeSec
} }
func (c *Client) Bytes() string { func (c *Client) Bytes() string {
if c.options.Bytes == nil { if c.Options.Bytes == nil {
return "" return ""
} }
return *c.options.Bytes return *c.Options.Bytes
} }
func (c *Client) SetBytes(bytes string) { func (c *Client) SetBytes(bytes string) {
c.options.Bytes = &bytes c.Options.Bytes = &bytes
} }
func (c *Client) BlockCount() string { func (c *Client) BlockCount() string {
if c.options.BlockCount == nil { if c.Options.BlockCount == nil {
return "" return ""
} }
return *c.options.BlockCount return *c.Options.BlockCount
} }
func (c *Client) SetBlockCount(blockCount string) { func (c *Client) SetBlockCount(blockCount string) {
c.options.BlockCount = &blockCount c.Options.BlockCount = &blockCount
} }
func (c *Client) Length() string { func (c *Client) Length() string {
if c.options.Length == nil { if c.Options.Length == nil {
if c.Proto() == PROTO_UDP { if c.Proto() == PROTO_UDP {
return "1460" return "1460"
} else { } else {
return "128K" return "128K"
} }
} }
return *c.options.Length return *c.Options.Length
} }
func (c *Client) SetLength(length string) { func (c *Client) SetLength(length string) {
c.options.Length = &length c.Options.Length = &length
} }
func (c *Client) Streams() int { func (c *Client) Streams() int {
if c.options.Streams == nil { if c.Options.Streams == nil {
return 1 return 1
} }
return *c.options.Streams return *c.Options.Streams
} }
func (c *Client) SetStreams(streamCount int) { func (c *Client) SetStreams(streamCount int) {
c.options.Streams = &streamCount c.Options.Streams = &streamCount
} }
func (c *Client) Reverse() bool { func (c *Client) Reverse() bool {
if c.options.Reverse == nil { if c.Options.Reverse == nil {
return false return false
} }
return *c.options.Reverse return *c.Options.Reverse
} }
func (c *Client) SetReverse(reverse bool) { func (c *Client) SetReverse(reverse bool) {
c.options.Reverse = &reverse c.Options.Reverse = &reverse
} }
func (c *Client) Window() string { func (c *Client) Window() string {
if c.options.Window == nil { if c.Options.Window == nil {
return "" return ""
} }
return *c.options.Window return *c.Options.Window
} }
func (c *Client) SetWindow(window string) { func (c *Client) SetWindow(window string) {
c.options.Window = &window c.Options.Window = &window
} }
func (c *Client) MSS() int { func (c *Client) MSS() int {
if c.options.MSS == nil { if c.Options.MSS == nil {
return 1460 return 1460
} }
return *c.options.MSS return *c.Options.MSS
} }
func (c *Client) SetMSS(mss int) { func (c *Client) SetMSS(mss int) {
c.options.MSS = &mss c.Options.MSS = &mss
} }
func (c *Client) NoDelay() bool { func (c *Client) NoDelay() bool {
if c.options.NoDelay == nil { if c.Options.NoDelay == nil {
return false return false
} }
return *c.options.NoDelay return *c.Options.NoDelay
} }
func (c *Client) SetNoDelay(noDelay bool) { func (c *Client) SetNoDelay(noDelay bool) {
c.options.NoDelay = &noDelay c.Options.NoDelay = &noDelay
} }
func (c *Client) Version4() bool { func (c *Client) Version4() bool {
if c.options.Version6 == nil && c.options.Version4 == nil { if c.Options.Version6 == nil && c.Options.Version4 == nil {
return true return true
} else if c.options.Version6 != nil && *c.options.Version6 == true { } else if c.Options.Version6 != nil && *c.Options.Version6 == true {
return false return false
} }
return *c.options.Version4 return *c.Options.Version4
} }
func (c *Client) SetVersion4(set bool) { func (c *Client) SetVersion4(set bool) {
c.options.Version4 = &set c.Options.Version4 = &set
} }
func (c *Client) Version6() bool { func (c *Client) Version6() bool {
if c.options.Version6 == nil { if c.Options.Version6 == nil {
return false return false
} }
return *c.options.Version6 return *c.Options.Version6
} }
func (c *Client) SetVersion6(set bool) { func (c *Client) SetVersion6(set bool) {
c.options.Version6 = &set c.Options.Version6 = &set
} }
func (c *Client) TOS() int { func (c *Client) TOS() int {
if c.options.TOS == nil { if c.Options.TOS == nil {
return 0 return 0
} }
return *c.options.TOS return *c.Options.TOS
} }
func (c *Client) SetTOS(value int) { func (c *Client) SetTOS(value int) {
c.options.TOS = &value c.Options.TOS = &value
} }
func (c *Client) ZeroCopy() bool { func (c *Client) ZeroCopy() bool {
if c.options.ZeroCopy == nil { if c.Options.ZeroCopy == nil {
return false return false
} }
return *c.options.ZeroCopy return *c.Options.ZeroCopy
} }
func (c *Client) SetZeroCopy(set bool) { func (c *Client) SetZeroCopy(set bool) {
c.options.ZeroCopy = &set c.Options.ZeroCopy = &set
} }
func (c *Client) OmitSec() int { func (c *Client) OmitSec() int {
if c.options.OmitSec == nil { if c.Options.OmitSec == nil {
return 0 return 0
} }
return *c.options.OmitSec return *c.Options.OmitSec
} }
func (c *Client) SetOmitSec(value int) { func (c *Client) SetOmitSec(value int) {
c.options.OmitSec = &value c.Options.OmitSec = &value
} }
func (c *Client) Prefix() string { func (c *Client) Prefix() string {
if c.options.Prefix == nil { if c.Options.Prefix == nil {
return "" return ""
} }
return *c.options.Prefix return *c.Options.Prefix
} }
func (c *Client) SetPrefix(prefix string) { func (c *Client) SetPrefix(prefix string) {
c.options.Prefix = &prefix c.Options.Prefix = &prefix
} }
func (c *Client) LogFile() string { func (c *Client) LogFile() string {
if c.options.LogFile == nil { if c.Options.LogFile == nil {
return "" return ""
} }
return *c.options.LogFile return *c.Options.LogFile
} }
func (c *Client) SetLogFile(logfile string) { func (c *Client) SetLogFile(logfile string) {
c.options.LogFile = &logfile c.Options.LogFile = &logfile
} }
func (c *Client) JSON() bool { func (c *Client) JSON() bool {
if c.options.JSON == nil { if c.Options.JSON == nil {
return false return false
} }
return *c.options.JSON return *c.Options.JSON
} }
func (c *Client) SetJSON(set bool) { func (c *Client) SetJSON(set bool) {
c.options.JSON = &set c.Options.JSON = &set
} }
func (c *Client) IncludeServer() bool { func (c *Client) IncludeServer() bool {
if c.options.IncludeServer == nil { if c.Options.IncludeServer == nil {
return false return false
} }
return *c.options.IncludeServer return *c.Options.IncludeServer
} }
func (c *Client) SetIncludeServer(set bool) { func (c *Client) SetIncludeServer(set bool) {
c.options.IncludeServer = &set c.Options.IncludeServer = &set
} }
func (c *Client) ExitCode() *int { func (c *Client) ExitCode() *int {
@ -487,7 +487,7 @@ func (c *Client) SetModeLive() <-chan *StreamIntervalReport {
} }
func (c *Client) Start() (err error) { func (c *Client) Start() (err error) {
//todo: Need to build the string based on the options above that are set //todo: Need to build the string based on the Options above that are set
cmd, err := c.commandString() cmd, err := c.commandString()
if err != nil { if err != nil {
return err return err

@ -1,10 +1,10 @@
package main package main
import ( import (
//"fmt" //"fmt"
//"github.com/BGrewell/go-conversions" //"github.com/BGrewell/go-conversions"
//"github.com/BGrewell/go-iperf" //"github.com/BGrewell/go-iperf"
//"time" //"time"
) )
func main() { func main() {

@ -20,18 +20,18 @@ func NewServer() *Server {
} }
type Server struct { type Server struct {
Id string `json:"id" yaml:"id" xml:"id"` Id string `json:"id" yaml:"id" xml:"id"`
OneOff *bool `json:"one_off" yaml:"one_off" xml:"one_off"` OneOff *bool `json:"one_off" yaml:"one_off" xml:"one_off"`
ExitCode *int `json:"exit_code" yaml:"exit_code" xml:"exit_code"` ExitCode *int `json:"exit_code" yaml:"exit_code" xml:"exit_code"`
Port *int `json:"port" yaml:"port" xml:"port"` Port *int `json:"port" yaml:"port" xml:"port"`
Format *rune `json:"format" yaml:"format" xml:"format"` Format *rune `json:"format" yaml:"format" xml:"format"`
Interval *int `json:"interval" yaml:"interval" xml:"interval"` Interval *int `json:"interval" yaml:"interval" xml:"interval"`
JSON *bool `json:"json" yaml:"json" xml:"json"` JSON *bool `json:"json" yaml:"json" xml:"json"`
LogFile *string `json:"log_file" yaml:"log_file" xml:"log_file"` LogFile *string `json:"log_file" yaml:"log_file" xml:"log_file"`
Running bool `json:"running" yaml:"running" xml:"running"` Running bool `json:"running" yaml:"running" xml:"running"`
outputStream io.ReadCloser `json:"output_stream" yaml:"output_stream" xml:"output_stream"` outputStream io.ReadCloser `json:"output_stream" yaml:"output_stream" xml:"output_stream"`
errorStream io.ReadCloser `json:"error_stream" yaml:"error_stream" xml:"error_stream"` errorStream io.ReadCloser `json:"error_stream" yaml:"error_stream" xml:"error_stream"`
cancel context.CancelFunc `json:"cancel" yaml:"cancel" xml:"cancel"` cancel context.CancelFunc `json:"cancel" yaml:"cancel" xml:"cancel"`
} }
func (s *Server) Start() (err error) { func (s *Server) Start() (err error) {

Loading…
Cancel
Save