/
main.go
57 lines (45 loc) · 1.22 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
package main
import (
"flag"
"fmt"
"os"
_ "github.com/maps90/cleanstack/internal/presenter"
"github.com/labstack/echo/middleware"
"github.com/maps90/cleanstack/pkg/datasources/mysql"
"github.com/maps90/cleanstack/pkg/transport/httpx"
"github.com/spf13/viper"
)
var (
cfgFile *string
cfgPort *string
)
func init() {
cfgFile = flag.String("config", "config.yaml", "config file (default is {WORKSPACE}/config.yaml)")
cfgPort = flag.String("port", "3000", "default port is :3000")
flag.Parse()
// Use config file from the flag.
viper.SetConfigFile(*cfgFile)
viper.AutomaticEnv() // read in environment variables that match
// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
}
// mysql initialize
mysql.Init()
}
func main() {
// instantiate new httpx package
instance := httpx.New()
instance.HideBanner = true
instance.SetPort(":" + *cfgPort)
instance.Use(
middleware.RequestID(),
middleware.Logger(),
middleware.Recover(),
middleware.Gzip(),
)
// override http error handler with exception package
instance.Echo.HTTPErrorHandler = httpx.ErrorHandler
// serve the http server
instance.Serve()
}