|
|
@ -5,6 +5,7 @@ import ( |
|
|
|
"fmt" |
|
|
|
"os" |
|
|
|
"log" |
|
|
|
"time" |
|
|
|
|
|
|
|
"github.com/veonik/eokvin" |
|
|
|
) |
|
|
@ -12,11 +13,13 @@ import ( |
|
|
|
var token string |
|
|
|
var endpoint string |
|
|
|
var insecure bool |
|
|
|
var ttl time.Duration |
|
|
|
|
|
|
|
func main() { |
|
|
|
flag.StringVar(&token, "token", "", "Secret token, required") |
|
|
|
flag.StringVar(&endpoint, "endpoint", "https://eok.vin/new", "URL for the running eokvin server") |
|
|
|
flag.StringVar(&endpoint, "endpoint", "https://localhost:3000/new", "URL for the running eokvin server") |
|
|
|
flag.BoolVar(&insecure, "insecure", false,"If enabled, allows endpoint to be insecure") |
|
|
|
flag.DurationVar(&ttl, "ttl", 12 * time.Hour, "Short URL expires after this long") |
|
|
|
flag.Parse() |
|
|
|
|
|
|
|
if token == "" { |
|
|
@ -35,14 +38,13 @@ func main() { |
|
|
|
|
|
|
|
var c *eokvin.Client |
|
|
|
if !insecure { |
|
|
|
c = eokvin.NewClient(token) |
|
|
|
c = eokvin.NewClient(endpoint, token) |
|
|
|
} else { |
|
|
|
c = eokvin.NewInsecureClient(token) |
|
|
|
c = eokvin.NewInsecureClient(endpoint, token) |
|
|
|
} |
|
|
|
c.Endpoint = endpoint |
|
|
|
s, err := c.NewShortURLString(u) |
|
|
|
s, err := c.NewShortURLString(u, ttl) |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("error creating short URL: %s", err.Error()) |
|
|
|
} |
|
|
|
fmt.Println(s.String()) |
|
|
|
fmt.Printf("Short URL: %s\t(valid until %s)\n", s, time.Now().Add(ttl).Format("Jan 02 15:04 MST")) |
|
|
|
} |