-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
72 lines (60 loc) · 1.35 KB
/
main.go
File metadata and controls
72 lines (60 loc) · 1.35 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"context"
"log"
"os"
"runtime/pprof"
"github.com/sirprodigle/linkpatrol/internal/app"
"github.com/sirprodigle/linkpatrol/internal/config"
"github.com/spf13/cobra"
)
var cfg config.Config
var rootCmd = &cobra.Command{
Use: "linkpatrol [target-url]",
Short: "Web link checker",
Long: `LinkPatrol is a tool for checking that links on web pages are accessible and valid`,
Args: cobra.MaximumNArgs(1),
RunE: run,
SilenceUsage: true,
SilenceErrors: true,
}
func init() {
cfg = config.NewConfig()
cfg.InitFlags(rootCmd)
}
func run(cmd *cobra.Command, args []string) error {
cfg.LoadFromViper()
// If target URL is provided as positional argument, use it
if len(args) > 0 {
cfg.Target = args[0]
}
if cfg.CPUProfile != "" {
f, err := os.Create(cfg.CPUProfile)
if err != nil {
log.Fatal(err)
}
defer f.Close()
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal(err)
}
defer pprof.StopCPUProfile()
}
if cfg.MemProfile != "" {
f, err := os.Create(cfg.MemProfile)
if err != nil {
log.Fatal(err)
}
defer f.Close()
if err := pprof.WriteHeapProfile(f); err != nil {
log.Fatal(err)
}
}
application := app.New(&cfg)
err := application.Run(context.Background())
return err
}
func main() {
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}