1,通过命令行自定义端口和环境
先用flag提取参数,如果要环境,就反向注进去,
如果是端口,就打到beego.Run函数里去。
2,在作router里的url解析时,如果URL中含有-中划线,用严格的string是不能匹配的。
需要去掉这个string限定。
package main import ( "flag" "fmt" _ "prismlogapi/routers" "github.com/astaxie/beego" "github.com/astaxie/beego/orm" _ "github.com/go-sql-driver/mysql" ) func main() { //orm.Debug = true runmode := flag.String("runmode", "dev", "runmode:default is dev") port := flag.String("port", "9527", "port:default is 9527") flag.Parse() beego.BConfig.RunMode = *runmode fmt.Println(beego.BConfig.RunMode) fmt.Println(port) if beego.BConfig.RunMode == "dev" { beego.BConfig.WebConfig.DirectoryIndex = true beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" } dbhost := beego.AppConfig.String("dbhost") dbport := beego.AppConfig.String("dbport") dbuser := beego.AppConfig.String("dbuser") dbpassword := beego.AppConfig.String("dbpassword") db := beego.AppConfig.String("db") orm.RegisterDriver("mysql", orm.DRMySQL) conn := dbuser + ":" + dbpassword + "@tcp(" + dbhost + ":" + dbport + ")/" + db + "?charset=utf8" fmt.Println(conn) orm.RegisterDataBase("default", "mysql", conn) orm.SetMaxIdleConns("default", 1000) orm.SetMaxOpenConns("default", 2000) beego.Run(":" + *port) }
// @Title 获取特定部署的日志 // @Description 返回多条日志 // @Param id path int true "The key for staticblock" // @Success 200 {object} models.PrismLog // @router /:app/:depverion:string/:order:int/ [get] func (u *PrismLogController) GetByAppDepOrd() { app := u.GetString(":app") depverion := u.GetString(":depverion") order, _ := u.GetInt(":order") fmt.Println(app, depverion, order, "@@@@@@@@@@@@@@@") s := models.GetPrismLogByAppDepOrd(app, depverion, order) u.Data["json"] = s u.ServeJSON()
时间: 2024-09-26 16:41:32