|
|
@ -1,6 +1,7 @@ |
|
|
package main |
|
|
package main |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"fmt" |
|
|
"log" |
|
|
"log" |
|
|
|
|
|
|
|
|
"github.com/brettlangdon/go-arg" |
|
|
"github.com/brettlangdon/go-arg" |
|
|
@ -10,17 +11,24 @@ import ( |
|
|
var args struct { |
|
|
var args struct { |
|
|
MaxEntries int `arg:"-m,--max,help:max number of links to keep [default: 1000]"` |
|
|
MaxEntries int `arg:"-m,--max,help:max number of links to keep [default: 1000]"` |
|
|
Bind string `arg:"-b,--bind,help:\"[host]:<port>\" to bind the server to [default: 127.0.0.1:5892]"` |
|
|
Bind string `arg:"-b,--bind,help:\"[host]:<port>\" to bind the server to [default: 127.0.0.1:5892]"` |
|
|
|
|
|
ServerURL string `arg:"-s,--server,help:base server url to generate links as (e.g. \"https://short.domain.com\") [default: \"http://<bind>\"]"` |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func main() { |
|
|
func main() { |
|
|
// Setup default args
|
|
|
// Setup default args
|
|
|
args.MaxEntries = 1000 |
|
|
args.MaxEntries = 1000 |
|
|
args.Bind = "127.0.0.1:5892" |
|
|
args.Bind = "127.0.0.1:5892" |
|
|
|
|
|
|
|
|
// Parse args from CLI
|
|
|
// Parse args from CLI
|
|
|
arg.MustParse(&args) |
|
|
arg.MustParse(&args) |
|
|
|
|
|
|
|
|
|
|
|
if args.ServerURL == "" { |
|
|
|
|
|
args.ServerURL = fmt.Sprintf("http://%s", args.Bind) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Start the server
|
|
|
// Start the server
|
|
|
server := terse.NewServer(args.Bind, args.MaxEntries) |
|
|
|
|
|
log.Fatal(server.ListenAndServe()) |
|
|
|
|
|
|
|
|
server, err := terse.NewServer(args.Bind, args.MaxEntries, args.ServerURL) |
|
|
|
|
|
if err == nil { |
|
|
|
|
|
err = server.ListenAndServe() |
|
|
|
|
|
} |
|
|
|
|
|
log.Fatal(err) |
|
|
} |
|
|
} |