// Edge implement Item interface package main import ( "fmt" "strconv" ) // TODO: handle arc__ and details__ fields type Edge struct { Id string `yaml:"id" json:"id"` Source string `yaml:"source" json:"source"` Target string `yaml:"target" json:"target"` MainStat string `yaml:"mainstat,omitempty" json:"mainstat,omitempty"` MainStatQuery string `yaml:"mainstatquery,omitempty" json:"mainstatquery,omitempty"` MainStatFormat string `yaml:"mainstatformat,omitempty" json:"mainstatformat,omitempty"` SecondaryStat string `yaml:"secondarystat,omitempty" json:"secondarystat,omitempty"` SecondaryStatQuery string `yaml:"secondarystatquery,omitempty" json:"secondarystatquery,omitempty"` SecondaryStatFormat string `yaml:"secondarystatformat,omitempty" json:"secondarystatformat,omitempty"` Color string `yaml:"color,omitempty" json:"color,omitempty"` Thickness int `yaml:"thickness,omitempty" json:"thickness,omitempty"` HighLighted bool `yaml:"highlighted,omitempty" json:"hightlighted,omitempty"` StrokeDashArray float32 `yaml:"strokeDasharray,omitempty" json:"strokeDasharray,omitempty"` } func (e Edge) GetId() string { return e.Id } func (e Edge) GetMainStat() string { return e.MainStat } func (e Edge) GetSecondaryStat() string { return e.SecondaryStat } func (e Edge) GetMainStatQuery() string { return e.MainStatQuery } func (e Edge) GetSecondaryStatQuery() string { return e.SecondaryStatQuery } func (e Edge) GetMainStatFormat() string { return e.MainStatFormat } func (e Edge) GetSecondaryStatFormat() string { return e.SecondaryStatFormat } func (e *Edge) SetMainStat(stat string) { e.MainStat = fmt.Sprintf("%s", stat) } func (e *Edge) SetSecondaryStat(stat string) { e.SecondaryStat = fmt.Sprintf("%s", stat) } // Custom marshaler to not send (main|secondary)statquery func (e Edge) MarshalJSON() ([]byte, error) { jsonRes := `{"id":"` + e.Id + `","source":"` + e.Source + `","target":"` + e.Target + `"` if len(e.MainStat) > 0 { jsonRes += `,"mainstat":"` + e.MainStat + `"` } if len(e.SecondaryStat) > 0 { jsonRes += `,"secondarystat":"` + e.SecondaryStat + `"` } if len(e.Color) > 0 { jsonRes += `,"color":"` + e.Color + `"` } if e.Thickness > 0 { jsonRes += `,"thickness":` + strconv.Itoa(e.Thickness) } if e.HighLighted { jsonRes += `,"highlighted":true` } // TODO : e.StrokeDashArray jsonRes += `}` return []byte(jsonRes), nil }