Lowercase & upperase initialism acronyms

See https://google.github.io/styleguide/go/decisions#initialisms
This commit is contained in:
ditatompel 2024-05-30 12:46:33 +07:00
parent 5fae3d565a
commit 0b331ec6c6
No known key found for this signature in database
GPG key ID: 31D3D06D77950979
5 changed files with 32 additions and 30 deletions

View file

@ -66,7 +66,7 @@ xmr-nodes probers list -s last_submit_ts -d asc sin1`,
fmt.Fprintf(w, "ID\t| Name\t| Last Submit\t| API Key\n")
for _, prober := range probers {
fmt.Fprintf(w, "%d\t| %s\t| %s\t| %s\n",
prober.Id,
prober.ID,
prober.Name,
time.Unix(prober.LastSubmitTs, 0).Format(time.RFC3339),
prober.ApiKey,

View file

@ -25,6 +25,6 @@ func CheckProber(c *fiber.Ctx) error {
})
}
c.Locals("prober_id", prober.Id)
c.Locals("prober_id", prober.ID)
return c.Next()
}

View file

@ -7,8 +7,9 @@ import (
"github.com/oschwald/geoip2-golang"
)
// IPInfo represents IP address information from Maxmind's GeoLite2 database
type IPInfo struct {
Ip string `json:"ip"`
IP string `json:"ip"`
IsAnonymousProxy bool `json:"is_anonymous_proxy"`
IsSatelliteProvider bool `json:"is_satellite_provider"`
City string `json:"city"`
@ -21,11 +22,12 @@ type IPInfo struct {
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
AccuracyRadius uint16 `json:"accuracy_radius"`
AsnOrg string `json:"asn_org"`
Asn uint `json:"asn"`
ASNOrg string `json:"asn_org"`
ASN uint `json:"asn"`
}
func IpInfo(ipAddr string) (*IPInfo, error) {
// Info returns GeoIP information from given IP address
func Info(ipAddr string) (*IPInfo, error) {
ip := net.ParseIP(ipAddr)
if ip == nil {
return nil, errors.New("Invalid IP address")
@ -42,32 +44,32 @@ func IpInfo(ipAddr string) (*IPInfo, error) {
}
defer dbAsn.Close()
cityRecord, err := dbCity.City(ip)
city, err := dbCity.City(ip)
if err != nil {
return nil, errors.New("Cannot read GeoIP City database")
}
asnRecord, err := dbAsn.ASN(ip)
asn, err := dbAsn.ASN(ip)
if err != nil {
return nil, errors.New("Cannot read GeoIP ASN database")
}
qip := IPInfo{
Ip: ipAddr,
IsAnonymousProxy: cityRecord.Traits.IsAnonymousProxy,
IsSatelliteProvider: cityRecord.Traits.IsSatelliteProvider,
City: cityRecord.City.Names["en"],
ContinentName: cityRecord.Continent.Names["en"],
ContinentCode: cityRecord.Continent.Code,
IsInEuropeanUnion: cityRecord.Country.IsInEuropeanUnion,
CountryName: cityRecord.Country.Names["en"],
CountryCode: cityRecord.Country.IsoCode,
TimeZone: cityRecord.Location.TimeZone,
Latitude: cityRecord.Location.Latitude,
Longitude: cityRecord.Location.Longitude,
AccuracyRadius: cityRecord.Location.AccuracyRadius,
AsnOrg: asnRecord.AutonomousSystemOrganization,
Asn: asnRecord.AutonomousSystemNumber,
IP: ipAddr,
IsAnonymousProxy: city.Traits.IsAnonymousProxy,
IsSatelliteProvider: city.Traits.IsSatelliteProvider,
City: city.City.Names["en"],
ContinentName: city.Continent.Names["en"],
ContinentCode: city.Continent.Code,
IsInEuropeanUnion: city.Country.IsInEuropeanUnion,
CountryName: city.Country.Names["en"],
CountryCode: city.Country.IsoCode,
TimeZone: city.Location.TimeZone,
Latitude: city.Location.Latitude,
Longitude: city.Location.Longitude,
AccuracyRadius: city.Location.AccuracyRadius,
ASNOrg: asn.AutonomousSystemOrganization,
ASN: asn.AutonomousSystemNumber,
}
return &qip, nil

View file

@ -658,11 +658,11 @@ func (repo *MoneroRepo) ProcessJob(report ProbeReport, proberId int64) error {
// recheck IP
if report.NodeInfo.IP != "" {
if ipInfo, errGeoIp := geo.IpInfo(report.NodeInfo.IP); errGeoIp != nil {
if ipInfo, errGeoIp := geo.Info(report.NodeInfo.IP); errGeoIp != nil {
fmt.Println("WARN:", errGeoIp.Error())
} else {
report.NodeInfo.ASN = ipInfo.Asn
report.NodeInfo.ASNName = ipInfo.AsnOrg
report.NodeInfo.ASN = ipInfo.ASN
report.NodeInfo.ASNName = ipInfo.ASNOrg
report.NodeInfo.CountryCode = ipInfo.CountryCode
report.NodeInfo.CountryName = ipInfo.CountryName
report.NodeInfo.City = ipInfo.City

View file

@ -12,7 +12,7 @@ import (
type ProberRepository interface {
Add(name string) (Prober, error)
Edit(id int, name string) error
Probers(q QueryProbers) ([]Prober, error)
Probers(QueryProbers) ([]Prober, error)
CheckApi(key string) (Prober, error)
Delete(id int) error
}
@ -22,7 +22,7 @@ type ProberRepo struct {
}
type Prober struct {
Id int64 `json:"id" db:"id"`
ID int64 `json:"id" db:"id"`
Name string `json:"name" db:"name"`
ApiKey uuid.UUID `json:"api_key" db:"api_key"`
LastSubmitTs int64 `json:"last_submit_ts" db:"last_submit_ts"`
@ -140,7 +140,7 @@ func (repo *ProberRepo) Probers(q QueryProbers) ([]Prober, error) {
for row.Next() {
var p Prober
err = row.Scan(&p.Id, &p.Name, &p.ApiKey, &p.LastSubmitTs)
err = row.Scan(&p.ID, &p.Name, &p.ApiKey, &p.LastSubmitTs)
if err != nil {
return probers, err
}
@ -162,6 +162,6 @@ func (repo *ProberRepo) CheckApi(key string) (Prober, error) {
WHERE
api_key = ?
LIMIT 1`
err := repo.db.QueryRow(query, key).Scan(&p.Id, &p.Name, &p.ApiKey, &p.LastSubmitTs)
err := repo.db.QueryRow(query, key).Scan(&p.ID, &p.Name, &p.ApiKey, &p.LastSubmitTs)
return p, err
}