feat: build wahrwelt A/D toolkit
This commit is contained in:
1 parent
303438d206
commit
653924d8c6
564 files changed
+36310
-49998
No files matched your search
@@ -0,0 +1,72 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
|
||||
logspb "github.com/c4t-but-s4d/neo/v2/proto/go/logs"
|
||||
)
|
||||
|
||||
func NewLogLineFromValues(vals map[string]interface{}) (*LogLine, error) {
|
||||
var line LogLine
|
||||
if err := mapstructure.Decode(vals, &line); err != nil {
|
||||
return nil, fmt.Errorf("разбор структуры строки журнала: %w", err)
|
||||
}
|
||||
return &line, nil
|
||||
}
|
||||
|
||||
func NewLogLineFromProto(p *logspb.LogLine) *LogLine {
|
||||
return &LogLine{
|
||||
Exploit: p.Exploit,
|
||||
Version: strconv.FormatInt(p.Version, 10),
|
||||
Message: p.Message,
|
||||
Level: p.Level,
|
||||
Team: p.Team,
|
||||
}
|
||||
}
|
||||
|
||||
type LogLine struct {
|
||||
Exploit string `mapstructure:"exploit"`
|
||||
Version string `mapstructure:"version"`
|
||||
Message string `mapstructure:"message"`
|
||||
Level string `mapstructure:"level"`
|
||||
Team string `mapstructure:"team"`
|
||||
}
|
||||
|
||||
func (l *LogLine) String() string {
|
||||
return fmt.Sprintf("Line(%s.v%s)", l.Exploit, l.Version)
|
||||
}
|
||||
|
||||
func (l *LogLine) DumpValues() (map[string]interface{}, error) {
|
||||
res := make(map[string]interface{})
|
||||
if err := mapstructure.Decode(l, &res); err != nil {
|
||||
return nil, fmt.Errorf("кодирование структуры строки журнала: %w", err)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (l *LogLine) EstimateSize() int {
|
||||
const (
|
||||
estNum = 5
|
||||
estDenom = 4
|
||||
structSize = 8 * 5
|
||||
)
|
||||
sizeEst := structSize + len(l.Exploit) + len(l.Version) + len(l.Message) + len(l.Level) + len(l.Team)
|
||||
return sizeEst * estNum / estDenom
|
||||
}
|
||||
|
||||
func (l *LogLine) ToProto() (*logspb.LogLine, error) {
|
||||
version, err := strconv.ParseInt(l.Version, 10, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("преобразование версии %v: %w", l.Version, err)
|
||||
}
|
||||
return &logspb.LogLine{
|
||||
Exploit: l.Exploit,
|
||||
Version: version,
|
||||
Message: l.Message,
|
||||
Level: l.Level,
|
||||
Team: l.Team,
|
||||
}, nil
|
||||
}
|
||||
Reference in new issue
Block a user