Skip to content

Commit a844149

Browse files
Add -hostname-file flag (#65)
* Update m-lab/go to v0.1.73 * Add -hostname-file flag
1 parent a36f346 commit a844149

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.20
44

55
require (
66
github.com/go-test/deep v1.0.6
7-
github.com/m-lab/go v0.1.66
7+
github.com/m-lab/go v0.1.73
88
github.com/m-lab/tcp-info v1.5.3
99
github.com/oschwald/geoip2-golang v1.7.0
1010
github.com/prometheus/client_golang v1.12.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB
237237
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
238238
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
239239
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
240-
github.com/m-lab/go v0.1.66 h1:adDJILqKBCkd5YeVhCrrjWkjoNRtDzlDr6uizWu5/pE=
241-
github.com/m-lab/go v0.1.66/go.mod h1:O1D/EoVarJ8lZt9foANcqcKtwxHatBzUxXFFyC87aQQ=
240+
github.com/m-lab/go v0.1.73 h1:vy4MRcEyvYOhfA55V6tT/NZlrfWS0qTNJktIrLaAbmw=
241+
github.com/m-lab/go v0.1.73/go.mod h1:BirARfHWjjXHaCGNyWCm/CKW1OarjuEj8Yn6Z2rc0M4=
242242
github.com/m-lab/tcp-info v1.5.3 h1:4IspTPcNc8D8LNRvuFnID8gDiz+hxPAtYvpKZaiGGe8=
243243
github.com/m-lab/tcp-info v1.5.3/go.mod h1:bkvI4qbjB6QVC2tsLSHqf5OnIYcmuLEVjo7+8YA56Kg=
244244
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=

main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
var (
2929
datadir = flag.String("datadir", ".", "The directory to put the data in")
3030
hostname = flag.String("hostname", "", "The server hostname, used to lookup server siteinfo annotations")
31+
hostnameFile = flagx.FileBytes{}
3132
maxmindurl = flagx.URL{}
3233
routeviewv4 = flagx.URL{}
3334
routeviewv6 = flagx.URL{}
@@ -49,6 +50,7 @@ var (
4950
)
5051

5152
func init() {
53+
flag.Var(&hostnameFile, "hostname-file", "The file containing the server hostname.")
5254
flag.Var(&maxmindurl, "maxmind.url", "The URL for the file containing MaxMind IP metadata. Accepted URL schemes currently are: gs://bucket/file and file:./relativepath/file")
5355
flag.Var(&routeviewv4, "routeview-v4.url", "The URL for the RouteViewIPv4 file containing ASN metadata. gs:// and file:// schemes accepted.")
5456
flag.Var(&routeviewv6, "routeview-v6.url", "The URL for the RouteViewIPv6 file containing ASN metadata. gs:// and file:// schemes accepted.")
@@ -73,6 +75,12 @@ func main() {
7375
flag.Parse()
7476
rtx.Must(flagx.ArgsFromEnv(flag.CommandLine), "Could not get args from environment variables")
7577

78+
// If the -hostname flag was not set, try reading the hostname from the
79+
// -hostname-file.
80+
if hostnameFile.String() != "" && *hostname == "" {
81+
*hostname = hostnameFile.String()
82+
}
83+
7684
// Create the datatype directory immediately, since pusher will crash
7785
// without it.
7886
rtx.Must(os.MkdirAll(*datadir, 0755), "Could not create datatype dir %s", datadir)
@@ -87,7 +95,7 @@ func main() {
8795
//
8896
// https://siteinfo.mlab-oti.measurementlab.net/v2/sites/annotations.json
8997
h, err := host.Parse(*hostname)
90-
rtx.Must(err, "Failed to parse -hostname flag value")
98+
rtx.Must(err, "Failed to parse the provided hostname")
9199
mlabHostname := h.String()
92100

93101
defer mainCancel()

0 commit comments

Comments
 (0)