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") fmt.Fprintf(w, "ID\t| Name\t| Last Submit\t| API Key\n")
for _, prober := range probers { for _, prober := range probers {
fmt.Fprintf(w, "%d\t| %s\t| %s\t| %s\n", fmt.Fprintf(w, "%d\t| %s\t| %s\t| %s\n",
prober.Id, prober.ID,
prober.Name, prober.Name,
time.Unix(prober.LastSubmitTs, 0).Format(time.RFC3339), time.Unix(prober.LastSubmitTs, 0).Format(time.RFC3339),
prober.ApiKey, 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() return c.Next()
} }

View file

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

View file

@ -658,11 +658,11 @@ func (repo *MoneroRepo) ProcessJob(report ProbeReport, proberId int64) error {
// recheck IP // recheck IP
if report.NodeInfo.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()) fmt.Println("WARN:", errGeoIp.Error())
} else { } else {
report.NodeInfo.ASN = ipInfo.Asn report.NodeInfo.ASN = ipInfo.ASN
report.NodeInfo.ASNName = ipInfo.AsnOrg report.NodeInfo.ASNName = ipInfo.ASNOrg
report.NodeInfo.CountryCode = ipInfo.CountryCode report.NodeInfo.CountryCode = ipInfo.CountryCode
report.NodeInfo.CountryName = ipInfo.CountryName report.NodeInfo.CountryName = ipInfo.CountryName
report.NodeInfo.City = ipInfo.City report.NodeInfo.City = ipInfo.City

View file

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