Skip to content

Commit 76c67c0

Browse files
Zellyn Hunterwillnorris
authored andcommitted
cmd/golink: add --hostname flag
Add a `--hostname` flag to allow changing the hostname from "go". May be necessary if your workplace already has "go" links.
1 parent 0755e37 commit 76c67c0

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

golink.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var (
3737
sqlitefile = flag.String("sqlitedb", "", "path of SQLite database to store links")
3838
dev = flag.String("dev-listen", "", "if non-empty, listen on this addr and run in dev mode; auto-set sqlitedb if empty and don't use tsnet")
3939
snapshot = flag.String("snapshot", "", "file path of snapshot file")
40+
hostname = flag.String("hostname", "go", "service name (defaults to 'go')")
4041
)
4142

4243
var stats struct {
@@ -112,8 +113,12 @@ func Run() error {
112113
log.Fatal(http.ListenAndServe(*dev, nil))
113114
}
114115

116+
if *hostname == "" {
117+
return errors.New("--hostname, if specified, cannot be empty")
118+
}
119+
115120
srv := &tsnet.Server{
116-
Hostname: "go",
121+
Hostname: *hostname,
117122
Logf: func(format string, args ...any) {},
118123
}
119124
if *verbose {
@@ -129,7 +134,7 @@ func Run() error {
129134
return err
130135
}
131136

132-
log.Printf("Serving http://go/ ...")
137+
log.Printf("Serving http://%s/ ...", *hostname)
133138
if err := http.Serve(l80, nil); err != nil {
134139
return err
135140
}
@@ -353,7 +358,7 @@ type expandEnv struct {
353358
var expandFuncMap = texttemplate.FuncMap{
354359
"PathEscape": url.PathEscape,
355360
"QueryEscape": url.QueryEscape,
356-
"TrimSuffix": strings.TrimSuffix,
361+
"TrimSuffix": strings.TrimSuffix,
357362
}
358363

359364
// expandLink returns the expanded long URL to redirect to, executing any

0 commit comments

Comments
 (0)