Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shorten icingadb/v1.AddressBin#Value() #801

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions pkg/icingadb/v1/host.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package v1

import (
"bytes"
"database/sql/driver"
"github.com/icinga/icinga-go-library/database"
"github.com/icinga/icinga-go-library/types"
Expand All @@ -28,23 +27,16 @@ type AddressBin struct {
Host *Host `db:"-"`
}

var v4InV6Prefix = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff}

// Value implements the driver.Valuer interface.
func (ab AddressBin) Value() (driver.Value, error) {
if ab.Host == nil {
return nil, nil
}

ip := net.ParseIP(ab.Host.Address)
if ip == nil {
if ip := net.ParseIP(ab.Host.Address).To4(); ip == nil {
return nil, nil
}

if ip = bytes.TrimPrefix(ip, v4InV6Prefix); len(ip) == 4 {
return []byte(ip), nil
} else {
return nil, nil
return []byte(ip), nil
}
}

Expand Down
Loading