Commit 0dde3495 by zhengqiuyun86

初始化

parent c4db0a51
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
......
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)
}
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)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment