Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rym-util
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhengqiuyun
rym-util
Commits
0dde3495
Commit
0dde3495
authored
Aug 10, 2022
by
zhengqiuyun86
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
初始化
parent
c4db0a51
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
13 deletions
+51
-13
conf.go
conf/conf.go
+25
-5
main.go
main.go
+7
-8
router.go
router/router.go
+19
-0
No files found.
conf/conf.go
View file @
0dde3495
package
conf
import
"git.168cad.top/zhengqiuyun/rym-util/util"
type
Config
struct
{
ServerName
string
Env
string
HttpPort
int
LogLevel
string
LogColorful
bool
LogResponseLength
int
...
...
@@ -16,10 +19,26 @@ type Config struct {
}
func
BaseConfig
(
conf
Config
)
{
if
util
.
IsEmpty
(
&
conf
.
ServerName
)
{
panic
(
"ServerName error"
)
}
else
{
ServerName
=
conf
.
ServerName
}
if
util
.
IsEmpty
(
&
conf
.
Env
)
{
panic
(
"Env error"
)
}
else
{
Env
=
conf
.
Env
}
if
conf
.
HttpPort
<
1024
{
panic
(
"HttpPort error"
)
}
else
{
HttpPort
=
conf
.
HttpPort
}
if
util
.
IsEmpty
(
&
conf
.
LogLevel
)
{
LogLevel
=
"DEBUG"
}
else
{
LogLevel
=
conf
.
LogLevel
}
LogColorful
=
conf
.
LogColorful
LogResponseLength
=
conf
.
LogResponseLength
LogShowSql
=
conf
.
LogShowSql
...
...
@@ -32,13 +51,14 @@ func BaseConfig(conf Config) {
}
//Base conf
var
ServerName
=
""
var
Env
=
""
var
ServerName
string
var
Env
string
var
HttpPort
int
//log conf
var
LogLevel
=
"DEBUG"
var
LogColorful
=
true
//日志是否开启彩色打印
var
LogResponseLength
=
10
var
LogColorful
=
true
var
LogResponseLength
int
var
LogShowSql
=
true
//Redis conf
...
...
main.go
View file @
0dde3495
package
main
import
(
"
fmt
"
"
git.168cad.top/zhengqiuyun/rym-util/conf
"
"git.168cad.top/zhengqiuyun/rym-util/es"
"git.168cad.top/zhengqiuyun/rym-util/log"
"git.168cad.top/zhengqiuyun/rym-util/mysqlrym"
"git.168cad.top/zhengqiuyun/rym-util/redis"
"git.168cad.top/zhengqiuyun/rym-util/router"
)
func
main
()
{
conf
.
BaseConfig
(
conf
.
Config
{
ServerName
:
"rym-framework"
,
Env
:
"dev"
,
HttpPort
:
1024
,
})
mysqlrym
.
TestLog
()
es
.
TestLog
()
redis
.
TestLog
()
c
:=
router
.
InitGinEngine
()
portAddr
:=
fmt
.
Sprintf
(
":%d"
,
8080
)
log
.
Info
(
fmt
.
Sprintf
(
"web start in port%s"
,
portAddr
))
err
:=
c
.
Run
(
portAddr
)
if
err
!=
nil
{
panic
(
err
)
}
router
.
Run
(
c
)
}
router/router.go
View file @
0dde3495
package
router
import
(
"fmt"
"git.168cad.top/zhengqiuyun/rym-util/conf"
"git.168cad.top/zhengqiuyun/rym-util/log"
"git.168cad.top/zhengqiuyun/rym-util/router/validator"
"git.168cad.top/zhengqiuyun/rym-util/util"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/render"
"net/http"
...
...
@@ -18,3 +22,18 @@ func InitGinEngine() *gin.Engine {
validator
.
RegisterValidate
()
return
c
}
func
Run
(
c
*
gin
.
Engine
)
{
portAddr
:=
""
arg1
:=
util
.
Args
(
1
)
if
arg1
==
""
{
portAddr
=
fmt
.
Sprintf
(
":%d"
,
conf
.
HttpPort
)
}
else
{
portAddr
=
fmt
.
Sprintf
(
":%s"
,
arg1
)
}
log
.
Info
(
fmt
.
Sprintf
(
"web start in port%s"
,
portAddr
))
err
:=
c
.
Run
(
portAddr
)
if
err
!=
nil
{
panic
(
err
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment