String and not pointers (#68)

This commit is contained in:
gadotroee 2021-06-07 15:19:12 +03:00 committed by GitHub
parent 8b4d813bd8
commit fcf27e7c4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 17 deletions

View File

@ -97,8 +97,8 @@ func saveHarToDb(entry *har.Entry, sender string) {
serviceName, urlPath, serviceHostName := getServiceNameFromUrl(entry.Request.URL) serviceName, urlPath, serviceHostName := getServiceNameFromUrl(entry.Request.URL)
entryId := primitive.NewObjectID().Hex() entryId := primitive.NewObjectID().Hex()
var ( var (
resolvedSource *string resolvedSource string
resolvedDestination *string resolvedDestination string
) )
if k8sResolver != nil { if k8sResolver != nil {
resolvedSource = k8sResolver.Resolve(sender) resolvedSource = k8sResolver.Resolve(sender)

View File

@ -90,12 +90,10 @@ func GetHARs(c *fiber.Ctx) error {
harsObject := map[string]*models.ExtendedHAR{} harsObject := map[string]*models.ExtendedHAR{}
for _, entryData := range entries { for _, entryData := range entries {
harEntryObject := []byte(entryData.Entry)
var harEntry har.Entry var harEntry har.Entry
_ = json.Unmarshal(harEntryObject, &harEntry) _ = json.Unmarshal([]byte(entryData.Entry), &harEntry)
sourceOfEntry := *entryData.ResolvedSource sourceOfEntry := entryData.ResolvedSource
if harOfSource, ok := harsObject[sourceOfEntry]; ok { if harOfSource, ok := harsObject[sourceOfEntry]; ok {
harOfSource.Log.Entries = append(harOfSource.Log.Entries, &harEntry) harOfSource.Log.Entries = append(harOfSource.Log.Entries, &harEntry)
} else { } else {
@ -137,8 +135,8 @@ func GetEntry(c *fiber.Ctx) error {
unmarshallErr := json.Unmarshal([]byte(entryData.Entry), &fullEntry) unmarshallErr := json.Unmarshal([]byte(entryData.Entry), &fullEntry)
utils.CheckErr(unmarshallErr) utils.CheckErr(unmarshallErr)
if entryData.ResolvedDestination != nil { if entryData.ResolvedDestination != "" {
fullEntry.Request.URL = utils.SetHostname(fullEntry.Request.URL, *entryData.ResolvedDestination) fullEntry.Request.URL = utils.SetHostname(fullEntry.Request.URL, entryData.ResolvedDestination)
} }
return c.Status(fiber.StatusOK).JSON(fullEntry) return c.Status(fiber.StatusOK).JSON(fullEntry)

View File

@ -21,8 +21,8 @@ type MizuEntry struct {
Service string `json:"service" gorm:"column:service"` Service string `json:"service" gorm:"column:service"`
Timestamp int64 `json:"timestamp" gorm:"column:timestamp"` Timestamp int64 `json:"timestamp" gorm:"column:timestamp"`
Path string `json:"path" gorm:"column:path"` Path string `json:"path" gorm:"column:path"`
ResolvedSource *string `json:"resolvedSource,omitempty" gorm:"column:resolvedSource"` ResolvedSource string `json:"resolvedSource,omitempty" gorm:"column:resolvedSource"`
ResolvedDestination *string `json:"resolvedDestination,omitempty" gorm:"column:resolvedDestination"` ResolvedDestination string `json:"resolvedDestination,omitempty" gorm:"column:resolvedDestination"`
} }
type BaseEntryDetails struct { type BaseEntryDetails struct {
@ -38,7 +38,7 @@ type BaseEntryDetails struct {
type EntryData struct { type EntryData struct {
Entry string `json:"entry,omitempty"` Entry string `json:"entry,omitempty"`
ResolvedDestination *string `json:"resolvedDestination,omitempty" gorm:"column:resolvedDestination"` ResolvedDestination string `json:"resolvedDestination,omitempty" gorm:"column:resolvedDestination"`
} }
type EntriesFilter struct { type EntriesFilter struct {

View File

@ -33,12 +33,12 @@ func (resolver *Resolver) Start(ctx context.Context) {
} }
} }
func (resolver *Resolver) Resolve(name string) *string { func (resolver *Resolver) Resolve(name string) string {
resolvedName, isFound := resolver.nameMap[name] resolvedName, isFound := resolver.nameMap[name]
if !isFound { if !isFound {
return nil return ""
} }
return &resolvedName return resolvedName
} }
func (resolver *Resolver) watchPods(ctx context.Context) error { func (resolver *Resolver) watchPods(ctx context.Context) error {

View File

@ -65,9 +65,9 @@ func SetHostname(address, newHostname string) string {
func GetResolvedBaseEntry(entry models.MizuEntry) models.BaseEntryDetails { func GetResolvedBaseEntry(entry models.MizuEntry) models.BaseEntryDetails {
entryUrl := entry.Url entryUrl := entry.Url
service := entry.Service service := entry.Service
if entry.ResolvedDestination != nil { if entry.ResolvedDestination != "" {
entryUrl = SetHostname(entryUrl, *entry.ResolvedDestination) entryUrl = SetHostname(entryUrl, entry.ResolvedDestination)
service = SetHostname(service, *entry.ResolvedDestination) service = SetHostname(service, entry.ResolvedDestination)
} }
return models.BaseEntryDetails{ return models.BaseEntryDetails{
Id: entry.EntryId, Id: entry.EntryId,