mirror of
https://github.com/zu1k/nali.git
synced 2025-01-22 21:29:02 +08:00
Add type Entity
This commit is contained in:
parent
a788bf35bb
commit
e7ea663d27
56
internal/entity/entity.go
Normal file
56
internal/entity/entity.go
Normal file
@ -0,0 +1,56 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type EntityType uint
|
||||
|
||||
const (
|
||||
TypePlain = iota
|
||||
TypeIPv4
|
||||
TypeIPv6
|
||||
TypeDomain
|
||||
)
|
||||
|
||||
type Entity struct {
|
||||
Index uint
|
||||
Length uint
|
||||
Type EntityType
|
||||
|
||||
Text string
|
||||
Info string
|
||||
}
|
||||
|
||||
func (e Entity) ParseInfo() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type Entities []*Entity
|
||||
|
||||
func (es Entities) Len() int {
|
||||
return len(es)
|
||||
}
|
||||
|
||||
func (es Entities) Less(i, j int) bool {
|
||||
return es[i].Index < es[j].Index
|
||||
}
|
||||
|
||||
func (es Entities) Swap(i, j int) {
|
||||
es[i],es[j] = es[j],es[i]
|
||||
}
|
||||
|
||||
func (es Entities) String() string {
|
||||
sort.Sort(es)
|
||||
|
||||
var result strings.Builder
|
||||
for _, entity := range es {
|
||||
result.WriteString(entity.Text)
|
||||
if entity.Type!=TypePlain && len(entity.Info)>0 {
|
||||
result.WriteString("[" + entity.Info + "] ")
|
||||
}
|
||||
}
|
||||
|
||||
return result.String()
|
||||
}
|
10
internal/entity/parse.go
Normal file
10
internal/entity/parse.go
Normal file
@ -0,0 +1,10 @@
|
||||
package entity
|
||||
|
||||
// ParseLine parse a line into entities
|
||||
func ParseLine(line string) Entities {
|
||||
entities := make(Entities, 0)
|
||||
|
||||
// TODO: parse a line into entities
|
||||
|
||||
return entities
|
||||
}
|
Loading…
Reference in New Issue
Block a user