-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
38 lines (31 loc) · 868 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"flag"
"fmt"
"github.com/briannewsom/metamonster/fetcher"
"github.com/briannewsom/metamonster/models/metadata"
)
func main() {
/* If given a url, use it, otherwise default to defaultUrl */
var u = flag.String("url", "", "URL from which to retrieve metadata")
var format = flag.String("format", "plaintext", "Output data format. Options - [json,plaintext]")
flag.Parse()
if *u == "" {
fmt.Printf("No URL provided, please provide a url using -url=url")
} else {
m, err := fetcher.GetInfoForUrl(*u)
if err != nil {
fmt.Printf("Failed to retrieve metadata - %s", err)
return
}
switch *format {
case "plaintext":
metadata.PrintMetadata(*m)
case "json":
json, _ := m.ToJson()
fmt.Printf("%s", json)
default:
fmt.Printf("Unrecognized output format %s. Please try json or plaintext", *format)
}
}
}