Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
MKCLOS
Core Development Platform
corepkgv2
Commits
6115a99c
Commit
6115a99c
authored
6 years ago
by
Sandeep S. Shewalkar
Browse files
Options
Downloads
Patches
Plain Diff
Get Gin server with Static middleware configuration
parent
7ba0d9bc
Branches
GinWithConfig
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
constantmdl/constantmdl.go
+4
-0
constantmdl/constantmdl.go
httpservermdl/httpservermdl.go
+57
-0
httpservermdl/httpservermdl.go
with
61 additions
and
0 deletions
constantmdl/constantmdl.go
+
4
−
0
View file @
6115a99c
...
...
@@ -48,3 +48,7 @@ const (
// HTTP400ERROR is used to check 400 status
const
HTTP400ERROR
=
400
//Configuration for GetServerWithStaticConfig
const
STATIC_DIRECTORY_NAME
=
"dsf"
const
STATIC_URL
=
"/dsf"
This diff is collapsed.
Click to expand it.
httpservermdl/httpservermdl.go
+
57
−
0
View file @
6115a99c
package
httpservermdl
import
(
"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/gin-gonic/gin"
"github.com/kardianos/osext"
)
// GetServer will return the webserver pointer
...
...
@@ -10,3 +16,54 @@ func GetServer() *gin.Engine {
server
:=
gin
.
New
()
return
server
}
// 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
""
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets