-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (44 loc) · 1.2 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
package main
import (
"flag"
"fmt"
"os"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/szaffarano/argocd-sandbox/routes"
v "github.com/szaffarano/argocd-sandbox/version"
)
var (
showVersion bool
host string
port int
// version
version string = "dev"
commit string = "none"
)
// var AppVersion .Version
func init() {
flag.BoolVar(&showVersion, "version", false, "Show version and exit")
flag.BoolVar(&showVersion, "v", false, "Show version and exit (shorthand)")
flag.StringVar(&host, "host", "localhost", "Hostname to listen on")
flag.IntVar(&port, "port", 8080, "Port to listen on")
flag.Parse()
if showVersion {
// print version to stdout and exit
fmt.Fprintf(os.Stdout, "Version: %+v\n", v.Version{Version: version, Commit: commit})
os.Exit(0)
}
}
func main() {
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.GET("/", routes.Hello)
e.GET("/health", routes.Health)
e.GET("/version", routes.Version(v.Version{Version: version, Commit: commit}))
httpPort := os.Getenv("PORT")
if httpPort == "" {
httpPort = fmt.Sprintf("%d", port)
}
e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%s", host, httpPort)))
}