rework shared config structs

main
Ben Grewell 4 years ago
parent a8e4e5c15e
commit dcfd84cf13

@ -2,7 +2,11 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<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$/report.go" beforeDir="false" afterPath="$PROJECT_DIR$/report.go" 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$/reporter_linux.go" beforeDir="false" afterPath="$PROJECT_DIR$/reporter_linux.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/server.go" beforeDir="false" afterPath="$PROJECT_DIR$/server.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/shared.go" beforeDir="false" afterPath="$PROJECT_DIR$/shared.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" />

@ -21,7 +21,9 @@ func NewClient(host string) *Client {
streams := 1 streams := 1
c := &Client{ c := &Client{
options: &ClientOptions{ options: &ClientOptions{
SharedOptions: SharedOptions{
JSON: &json, JSON: &json,
},
Proto: &proto, Proto: &proto,
TimeSec: &time, TimeSec: &time,
Length: &length, Length: &length,
@ -54,8 +56,6 @@ type ClientOptions struct {
ZeroCopy *bool ZeroCopy *bool
OmitSec *int OmitSec *int
Prefix *string Prefix *string
JSON *bool
LogFile *string
IncludeServer *bool IncludeServer *bool
} }
@ -86,6 +86,18 @@ func (c *Client) commandString() (cmd string, err error) {
} }
fmt.Fprintf(&builder, "%s -c %s", binaryLocation, c.Host()) fmt.Fprintf(&builder, "%s -c %s", binaryLocation, c.Host())
if c.options.Port != nil {
fmt.Fprintf(&builder, " -p %d", c.Port())
}
if c.options.Format != nil || *c.options.Format != ' ' {
fmt.Fprintf(&builder, " -f %c", c.Format())
}
if c.options.Interval != nil {
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")
} }
@ -176,6 +188,39 @@ func (c *Client) SetHost(host string) {
c.options.Host = &host c.options.Host = &host
} }
func (c *Client) Port() int {
if c.options.Port == nil {
return 5201
}
return *c.options.Port
}
func (c *Client) SetPort(port int) {
c.options.Port = &port
}
func (c *Client) Format() rune {
if c.options.Format == nil {
return ' '
}
return *c.options.Format
}
func (c *Client) SetFormat(format rune) {
c.options.Format = &format
}
func (c *Client) Interval() int {
if c.options.Interval == nil {
return 1
}
return *c.options.Interval
}
func (c *Client) SetInterval(interval int) {
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

@ -9,7 +9,14 @@ import (
) )
func NewServer() *Server { func NewServer() *Server {
s := &Server{} defaultPort := 5201
defaultInterval := 1
s := &Server{
SharedOptions: SharedOptions{
Port: &defaultPort,
Interval: &defaultInterval,
},
}
s.Id = uuid.New().String() s.Id = uuid.New().String()
return s return s
} }

@ -17,6 +17,8 @@ type SharedOptions struct {
Port *int Port *int
Format *rune Format *rune
Interval *int Interval *int
JSON *bool
LogFile *string
} }
type DebugScanner struct { type DebugScanner struct {

Loading…
Cancel
Save