Commit 0dde3495 by zhengqiuyun86

初始化

parent c4db0a51
package conf package conf
import "git.168cad.top/zhengqiuyun/rym-util/util"
type Config struct { type Config struct {
ServerName string ServerName string
Env string Env string
HttpPort int
LogLevel string LogLevel string
LogColorful bool LogColorful bool
LogResponseLength int LogResponseLength int
...@@ -16,10 +19,26 @@ type Config struct { ...@@ -16,10 +19,26 @@ type Config struct {
} }
func BaseConfig(conf Config) { func BaseConfig(conf Config) {
if util.IsEmpty(&conf.ServerName) {
panic("ServerName error")
} else {
ServerName = conf.ServerName ServerName = conf.ServerName
}
if util.IsEmpty(&conf.Env) {
panic("Env error")
} else {
Env = conf.Env 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 LogLevel = conf.LogLevel
}
LogColorful = conf.LogColorful LogColorful = conf.LogColorful
LogResponseLength = conf.LogResponseLength LogResponseLength = conf.LogResponseLength
LogShowSql = conf.LogShowSql LogShowSql = conf.LogShowSql
...@@ -32,13 +51,14 @@ func BaseConfig(conf Config) { ...@@ -32,13 +51,14 @@ func BaseConfig(conf Config) {
} }
//Base conf //Base conf
var ServerName = "" var ServerName string
var Env = "" var Env string
var HttpPort int
//log conf //log conf
var LogLevel = "DEBUG" var LogLevel = "DEBUG"
var LogColorful = true //日志是否开启彩色打印 var LogColorful = true
var LogResponseLength = 10 var LogResponseLength int
var LogShowSql = true var LogShowSql = true
//Redis conf //Redis conf
......
package main package main
import ( import (
"fmt" "git.168cad.top/zhengqiuyun/rym-util/conf"
"git.168cad.top/zhengqiuyun/rym-util/es" "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/mysqlrym"
"git.168cad.top/zhengqiuyun/rym-util/redis" "git.168cad.top/zhengqiuyun/rym-util/redis"
"git.168cad.top/zhengqiuyun/rym-util/router" "git.168cad.top/zhengqiuyun/rym-util/router"
) )
func main() { func main() {
conf.BaseConfig(conf.Config{
ServerName: "rym-framework",
Env: "dev",
HttpPort: 1024,
})
mysqlrym.TestLog() mysqlrym.TestLog()
es.TestLog() es.TestLog()
redis.TestLog() redis.TestLog()
c := router.InitGinEngine() c := router.InitGinEngine()
portAddr := fmt.Sprintf(":%d", 8080) router.Run(c)
log.Info(fmt.Sprintf("web start in port%s", portAddr))
err := c.Run(portAddr)
if err != nil {
panic(err)
}
} }
package router package router
import ( 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/router/validator"
"git.168cad.top/zhengqiuyun/rym-util/util"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/render" "github.com/gin-gonic/gin/render"
"net/http" "net/http"
...@@ -18,3 +22,18 @@ func InitGinEngine() *gin.Engine { ...@@ -18,3 +22,18 @@ func InitGinEngine() *gin.Engine {
validator.RegisterValidate() validator.RegisterValidate()
return c 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