forked from kujtimiihoxha/kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (70 loc) · 2.64 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
73
74
75
76
package main
import (
"os"
"path"
"path/filepath"
"runtime"
"strings"
"github.com/kujtimiihoxha/kit/cmd"
"github.com/kujtimiihoxha/kit/utils"
"github.com/sirupsen/logrus"
"github.com/spf13/afero"
"github.com/spf13/viper"
)
func main() {
setDefaults()
viper.AutomaticEnv()
gosrc := strings.TrimSuffix(utils.GetGOPATH(), afero.FilePathSeparator ) + afero.FilePathSeparator + "src" + afero.FilePathSeparator
pwd, err := os.Getwd()
if err != nil {
logrus.Error(err)
return
}
gosrc, err = filepath.EvalSymlinks(gosrc)
if err != nil {
logrus.Error(err)
return
}
pwd, err = filepath.EvalSymlinks(pwd)
if err != nil {
logrus.Error(err)
return
}
if !strings.HasPrefix(pwd, gosrc) {
logrus.Error("The project must be in the $GOPATH/src folder for the generator to work.")
return
}
cmd.Execute()
}
func setDefaults() {
viper.SetDefault("gk_service_path_format", path.Join("%s", "pkg", "service"))
viper.SetDefault("gk_cmd_service_path_format", path.Join("%s", "cmd", "service"))
viper.SetDefault("gk_cmd_path_format", path.Join("%s", "cmd"))
viper.SetDefault("gk_endpoint_path_format", path.Join("%s", "pkg", "endpoint"))
viper.SetDefault("gk_http_path_format", path.Join("%s", "pkg", "http"))
viper.SetDefault("gk_http_client_path_format", path.Join("%s", "client", "http"))
viper.SetDefault("gk_grpc_client_path_format", path.Join("%s", "client", "grpc"))
viper.SetDefault("gk_client_cmd_path_format", path.Join("%s", "cmd", "client"))
viper.SetDefault("gk_grpc_path_format", path.Join("%s", "pkg", "grpc"))
viper.SetDefault("gk_grpc_pb_path_format", path.Join("%s", "pkg", "grpc", "pb"))
viper.SetDefault("gk_service_file_name", "service.go")
viper.SetDefault("gk_service_middleware_file_name", "middleware.go")
viper.SetDefault("gk_endpoint_base_file_name", "endpoint_gen.go")
viper.SetDefault("gk_endpoint_file_name", "endpoint.go")
viper.SetDefault("gk_endpoint_middleware_file_name", "middleware.go")
viper.SetDefault("gk_http_file_name", "handler.go")
viper.SetDefault("gk_http_base_file_name", "handler_gen.go")
viper.SetDefault("gk_cmd_base_file_name", "service_gen.go")
viper.SetDefault("gk_cmd_svc_file_name", "service.go")
viper.SetDefault("gk_http_client_file_name", "http.go")
viper.SetDefault("gk_grpc_client_file_name", "grpc.go")
viper.SetDefault("gk_grpc_pb_file_name", "%s.proto")
viper.SetDefault("gk_grpc_base_file_name", "handler_gen.go")
viper.SetDefault("gk_grpc_file_name", "handler.go")
if runtime.GOOS == "windows" {
viper.SetDefault("gk_grpc_compile_file_name", "compile.bat")
} else {
viper.SetDefault("gk_grpc_compile_file_name", "compile.sh")
}
viper.SetDefault("gk_service_struct_prefix", "basic")
}