Newer
Older
"path/filepath"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/constantmdl"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/filemdl"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/loggermdl"
"github.com/kardianos/osext"
)
// GetServer will return the webserver pointer
func GetServer() *gin.Engine {
// TODO: use sync.Once
server := gin.New()
return server
}
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
// GetServerWithStaticConfig will return the webserver pointer.
// It will also register static middleware
func GetServerWithStaticConfig(staticDirectoryRelativePath string) *gin.Engine {
// TODO: use sync.Once
server := gin.New()
staticPath := checkAndCreateStaticDirectory(staticDirectoryRelativePath)
if staticPath != "" {
staticGroup := server.Group(constantmdl.STATIC_URL)
// //staticGroup.Use(jwt.Auth("models.JWTKey"))
staticGroup.Static("/", staticPath)
}
return server
}
// checkAndCreateStaticDirectory will create static directory to
// serve the static contents. Directory will be created at the same location where executable is located
func checkAndCreateStaticDirectory(staticDirectoryRelativePath string) string {
staticDirectoryPath := ""
if staticDirectoryRelativePath == "" {
staticDirectoryRelativePath = constantmdl.STATIC_DIRECTORY_NAME
}
executablePath, exePathError := osext.Executable()
if exePathError != nil {
loggermdl.LogError("error while fetching executable path : ", exePathError)
return ""
}
dirPath := filepath.Dir(executablePath)
staticDirectoryPath = dirPath + "/" + staticDirectoryRelativePath
exists := filemdl.FileAvailabilityCheck(staticDirectoryPath)
if exists {
loggermdl.LogInfo("static directory already exists: ", staticDirectoryPath)
return staticDirectoryPath
}
loggermdl.LogInfo("static directory does not exists. creating the new : ", staticDirectoryPath)
directoryCreationError := filemdl.CreateDirectory(staticDirectoryPath)
if directoryCreationError != nil {
loggermdl.LogError("error while creating static directory : ", directoryCreationError)
return ""
}
return staticDirectoryPath
return ""
}