mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-10 18:38:22 +00:00
Add Service Port Helpers
This commit is contained in:
parent
16a9fec479
commit
2afe7341c1
1 changed files with 23 additions and 1 deletions
|
@ -1,6 +1,9 @@
|
|||
package definitions
|
||||
|
||||
import "encoding/json"
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
Type ServiceType `json:"type"`
|
||||
|
@ -10,6 +13,25 @@ type Service struct {
|
|||
DPortStart *uint32 `json:"dport_start,omitempty"`
|
||||
DPortEnd *uint32 `json:"dport_end,omitempty"`
|
||||
ICMPCode *uint32 `json:"icmp_code,omitempty"`
|
||||
Children *[]string `json:"children,omitempty"`
|
||||
}
|
||||
|
||||
func (s Service) GetSPort() string {
|
||||
if *s.SPortStart == 0 {
|
||||
return ""
|
||||
} else if *s.SPortEnd == 0 {
|
||||
return fmt.Sprintf("sport %d", *s.SPortStart)
|
||||
}
|
||||
return fmt.Sprintf("sport %d - %d", *s.SPortStart, *s.SPortEnd)
|
||||
}
|
||||
|
||||
func (s Service) GetDPort() string {
|
||||
if *s.DPortStart == 0 {
|
||||
return ""
|
||||
} else if *s.DPortEnd == 0 {
|
||||
return fmt.Sprintf("dport %d", *s.DPortStart)
|
||||
}
|
||||
return fmt.Sprintf("dport %d - %d", *s.DPortStart, *s.DPortEnd)
|
||||
}
|
||||
|
||||
type ServiceType int
|
||||
|
|
Loading…
Add table
Reference in a new issue