1
0
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:
zu1k 2021-07-30 21:46:06 +08:00
parent a788bf35bb
commit e7ea663d27
2 changed files with 66 additions and 0 deletions

56
internal/entity/entity.go Normal file
View 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
View 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
}