Fix colors map initialization (#1200)

This commit is contained in:
gadotroee 2022-07-12 20:05:21 +03:00 committed by GitHub
parent 4b280ecd6d
commit a3c236ff0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -5,7 +5,6 @@ import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"reflect" "reflect"
"strings"
"sync" "sync"
"time" "time"
@ -82,8 +81,7 @@ func GetGeneralStats() *GeneralStats {
func InitProtocolToColor(protocolMap map[string]*api.Protocol) { func InitProtocolToColor(protocolMap map[string]*api.Protocol) {
for item, value := range protocolMap { for item, value := range protocolMap {
splitted := strings.SplitN(item, "/", 3) protocolToColor[api.GetProtocolSummary(item).Abbreviation] = value.BackgroundColor
protocolToColor[splitted[len(splitted)-1]] = value.BackgroundColor
} }
} }

View File

@ -4,6 +4,7 @@ import (
"bufio" "bufio"
"fmt" "fmt"
"net" "net"
"strings"
"sync" "sync"
"time" "time"
@ -25,6 +26,15 @@ func (protocol *ProtocolSummary) ToString() string {
return fmt.Sprintf("%s?%s?%s", protocol.Name, protocol.Version, protocol.Abbreviation) return fmt.Sprintf("%s?%s?%s", protocol.Name, protocol.Version, protocol.Abbreviation)
} }
func GetProtocolSummary(inputString string) *ProtocolSummary {
splitted := strings.SplitN(inputString, "?", 3)
return &ProtocolSummary{
Name: splitted[0],
Version: splitted[1],
Abbreviation: splitted[2],
}
}
type Protocol struct { type Protocol struct {
ProtocolSummary ProtocolSummary
LongName string `json:"longName"` LongName string `json:"longName"`