generated from whiteducksoftware/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (59 loc) · 1.92 KB
/
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
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 (
"embed"
"fmt"
"os"
"strings"
"github.com/StiviiK/go-modules-http-proxy/cmd"
"github.com/StiviiK/go-modules-http-proxy/config"
"github.com/StiviiK/go-modules-http-proxy/pkg/html"
"github.com/urfave/cli/v2"
// Commands
_ "github.com/StiviiK/go-modules-http-proxy/cmd/noop"
_ "github.com/StiviiK/go-modules-http-proxy/cmd/serve"
)
// Version is set by an LDFLAG at build time representing the git tag or commit
// for the current release
var Version = "N/A"
// BuildTime is set by an LDFLAG at build time representing the timestamp at
// the time of build
var BuildTime = "N/A"
// assets is a map of embedded assets
//go:embed assets/*
var assets embed.FS
func init() {
defer panicHandler()
config.Set("Go Modules HTTP Proxy", Version, BuildTime)
// Parse the HTML assets
html.ParseTemplate(assets)
}
func main() {
app := cli.NewApp()
app.Name = "Go Modules HTTP Proxy"
app.Commands = *cmd.Retrieve()
// All non-successful output should be written to stderr
app.Writer = os.Stdout
app.ErrWriter = os.Stderr
if err := app.Run(os.Args); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", config.Version())
fmt.Fprintf(os.Stderr, "Release Date: %s\n\n", config.ReleaseDate())
fmt.Fprintf(os.Stderr, "%+v", err)
}
}
func panicHandler() {
if r := recover(); r != nil {
if os.Getenv("DEBUG") == "1" {
fmt.Fprintf(os.Stderr, "%s\n", config.Version())
fmt.Fprintf(os.Stderr, "Release Date: %s\n\n", config.ReleaseDate())
panic(r)
} else {
fmt.Fprintf(os.Stderr, "%s\n", config.Version())
fmt.Fprintf(os.Stderr, "Release Date: %s\n\n", config.ReleaseDate())
fmt.Fprintln(os.Stderr, "Something unexpected happened.")
fmt.Fprintln(os.Stderr, "If you want to help us debug the problem, please run:")
fmt.Fprintf(os.Stderr, "DEBUG=1 %s\n", strings.Join(os.Args, " "))
fmt.Fprintln(os.Stderr, "and send the output to https://github.com/StiviiK/go-modules-http-proxy")
os.Exit(2)
}
}
}