本文整理汇总了Golang中github.com/astaxie/beego.Critical函数的典型用法代码示例。如果您正苦于以下问题:Golang Critical函数的具体用法?Golang Critical怎么用?Golang Critical使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Critical函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: setEngine
func setEngine() {
dbName := utils.Cfg.MustValue("db", "name")
dbPwd := utils.Cfg.MustValue("db", "pwd_"+runtime.GOOS)
if runtime.GOOS == "darwin" {
u, err := user.Current()
if err != nil {
beego.Critical("models.init -> fail to get user:", err.Error())
os.Exit(2)
}
dbPwd = utils.Cfg.MustValue("db", "pwd_"+runtime.GOOS+"_"+u.Username)
}
var err error
x, err = xorm.NewEngine("mysql", fmt.Sprintf("%v:%[email protected]%v/%v?charset=utf8",
utils.Cfg.MustValue("db", "user"), dbPwd,
utils.Cfg.MustValue("db", "host"), dbName))
if err != nil {
beego.Critical("models.init -> fail to conntect database:", err.Error())
os.Exit(2)
}
if beego.RunMode != "pro" {
x.ShowDebug = true
x.ShowErr = true
//x.ShowSQL = true
}
beego.Trace("Initialized database ->", dbName)
}
开发者ID:juju2013,项目名称:gowalker,代码行数:30,代码来源:models.go
示例2: dbInit
func dbInit() {
orm.RegisterModel(new(UserInfo), new(UserStatus), new(UserRecord))
//register mysql driver
err := orm.RegisterDriver("mysql", orm.DR_MySQL)
if err != nil {
beego.Critical(err)
}
//register default database
if !localSwitch {
orm.RegisterDataBase("default", "mysql", "autelan:[email protected](rdsrenv7vrenv7v.mysql.rds.aliyuncs.com:3306)/umsdb?charset=utf8&&loc=Asia%2FShanghai")
} else {
dbIp := beego.AppConfig.String("DbIp")
dbPort := beego.AppConfig.String("DbPort")
dbName := beego.AppConfig.String("DbName")
dbUser := beego.AppConfig.String("DbUser")
dbPassword := beego.AppConfig.String("DbPassword")
dbUrl := dbUser + ":" + dbPassword +
"@tcp(" + dbIp + ":" + dbPort + ")/" +
dbName + "?charset=utf8&loc=Asia%2FShanghai"
beego.Debug("dbUrl=", dbUrl)
err = orm.RegisterDataBase("default", "mysql", dbUrl)
if err != nil {
beego.Critical(err)
}
}
orm.SetMaxIdleConns("default", 30)
orm.SetMaxOpenConns("default", 30)
ormer = orm.NewOrm()
}
开发者ID:tcdog001,项目名称:ums,代码行数:35,代码来源:db.go
示例3: save
func (n *NoteEntry) save() bool {
appDataDb, err := leveldb.OpenFile(Configs["conf/db.conf"].String("app::path"), nil)
if err != nil {
beego.Error(err)
beego.Critical("unable to open " + Configs["conf/db.conf"].String("app::path"))
return false
}
defer appDataDb.Close()
tmp := int64(1014)
if urlCountStr, err := appDataDb.Get([]byte("urlCount"), nil); err == nil {
tmp, _ = strconv.ParseInt(string(urlCountStr), 10, 64)
}
if tmp < urlCount && appDataDb.Put([]byte("urlCount"), []byte(strconv.FormatInt(urlCount, 10)), nil) != nil {
beego.Critical("unable to save to db")
return false
}
urlDb, err := leveldb.OpenFile(Configs["conf/db.conf"].String("url::path"), nil)
if err != nil {
beego.Critical("unable to open " + Configs["conf/db.conf"].String("url::path"))
return false
}
defer urlDb.Close()
if buf, err := json.Marshal(n.toPublic()); err != nil {
beego.Error("unable to Marshal object", n)
return false
} else {
urlDb.Put([]byte(n.url), buf, nil)
}
return true
}
开发者ID:aholic,项目名称:note.cstdlib.com,代码行数:35,代码来源:note.go
示例4: init
func init() {
//register all tables
orm.RegisterModel(new(Userinfo), new(Admininfo), new(Deviceinfo), new(Historyinfo), new(Command), new(OperationRecord), new(Alarm), new(Script))
//register mysql driver
err := orm.RegisterDriver("mysql", orm.DR_MySQL)
if err != nil {
beego.Critical(err)
}
//register default database
dbIp := beego.AppConfig.String("DbIp")
dbPort := beego.AppConfig.String("DbPort")
dbName := beego.AppConfig.String("DbName")
dbUser := beego.AppConfig.String("DbUser")
dbPassword := beego.AppConfig.String("DbPassword")
dbUrl := dbUser + ":" + dbPassword + "@tcp(" + dbIp + ":" + dbPort + ")/" + dbName + "?charset=utf8&loc=Asia%2FShanghai"
beego.Debug("dbUrl=", dbUrl)
err = orm.RegisterDataBase("default", "mysql", dbUrl)
if err != nil {
beego.Critical(err)
}
//orm.RegisterDataBase("default", "mysql", "root:[email protected]/lte_test?charset=utf8&&loc=Asia%2FShanghai")
orm.SetMaxIdleConns("default", 30)
orm.SetMaxOpenConns("default", 30)
}
开发者ID:tcdog001,项目名称:szm_lms,代码行数:27,代码来源:init.go
示例5: main
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
beego.SetLogFuncCall(true)
beego.SessionOn = true
goth.UseProviders(
gplus.New(
beego.AppConfig.String("CLIENT_ID"),
beego.AppConfig.String("CLIENT_SECRET"),
beego.AppConfig.String("CLIENT_CALLBACK"),
),
)
SessionTimeout, err := beego.AppConfig.Int("SESSION_TIMEOUT")
if err != nil {
beego.Critical(err)
}
SessionRefreshInterval, err := beego.AppConfig.Int("SESSION_REFRESH_INTERVAL")
if err != nil {
beego.Critical(err)
}
goJwt.Conf = goJwt.JwtConf{
PrivateKeyFile: beego.AppConfig.String("PrivateKeyFile"),
PublicKeyFile: beego.AppConfig.String("PublicKeyFile"),
Algorithm: beego.AppConfig.String("Algorithm"),
SessionSecret: beego.AppConfig.String("SESSION_SECRET"),
SessionName: beego.AppConfig.String("SESSION_NAME"),
SessionTimeout: SessionTimeout,
SessionRefreshInterval: SessionRefreshInterval,
}
goJwt.Configure()
goJwt.Store = sessions.NewCookieStore([]byte(beego.AppConfig.String("SESSION_SECRET")))
ldapPort, err := beego.AppConfig.Int("Ldap_port")
if err != nil {
beego.Critical(err)
}
tim.Conf = tim.LdapConf{
Ldap_server: beego.AppConfig.String("Ldap_server"),
Ldap_port: uint16(ldapPort),
Base_dn: beego.AppConfig.String("Base_dn"),
Ldap_user: beego.AppConfig.String("Ldap_user"),
Ldap_pass: beego.AppConfig.String("Ldap_pass"),
}
beego.SetStaticPath("/public", "static")
if err != nil {
beego.Critical("Cannot connect to Redis: ", err)
return
}
beego.Run()
}
开发者ID:ovino,项目名称:goSkeleton,代码行数:52,代码来源:main.go
示例6: RegisterDB
func RegisterDB() {
//register all tables
orm.RegisterModel(new(Deviceinfo), new(Userinfo), new(Admininfo))
//register mysql driver
err := orm.RegisterDriver("mysql", orm.DR_MySQL)
if err != nil {
beego.Critical(err)
}
//register default database lte_security
err = orm.RegisterDataBase("default", "mysql", "root:[email protected](192.168.15.155:3306)/lte_security?charset=utf8&loc=Asia%2FShanghai")
//orm.RegisterDataBase("default", "mysql", "root:@/lte_security?charset=utf8&loc=Asia%2FShanghai")
if err != nil {
beego.Critical(err)
}
}
开发者ID:tcdog001,项目名称:LTE_Security,代码行数:15,代码来源:models.go
示例7: init
func init() {
err := cbes.RegisterModel(new(License))
if err != nil {
beego.Critical(err)
}
}
开发者ID:laura-h,项目名称:inventory-tool,代码行数:7,代码来源:license.go
示例8: init
func init() {
err := cbes.RegisterModel(new(Folder))
if err != nil {
beego.Critical(err)
}
}
开发者ID:laura-h,项目名称:inventory-tool,代码行数:7,代码来源:folder.go
示例9: registerDatabase
func registerDatabase() {
beego.Debug(beego.AppConfig.String("elasticsearch::url"))
settings := new(cbes.Settings)
settings.ElasticSearch.Urls = []string{beego.AppConfig.String("elasticsearch::url")}
settings.ElasticSearch.Index = beego.AppConfig.String("elasticsearch::index")
settings.ElasticSearch.NumberOfShards = 5
settings.ElasticSearch.NumberOfReplicas = 1
settings.ElasticSearch.RefreshInterval = "10ms"
settings.ElasticSearch.CheckOnStartup = true
settings.CouchBase.Host = beego.AppConfig.String("couchbase::host")
settings.CouchBase.UserName = beego.AppConfig.String("couchbase::username")
settings.CouchBase.Pass = beego.AppConfig.String("couchbase::password")
bucket := new(cbes.Bucket)
bucket.Name = beego.AppConfig.String("couchbase::bucket")
bucket.Pass = ""
bucket.OperationTimeout = 5 // seconds
settings.CouchBase.Bucket = bucket
viewsOptions := new(cbes.ViewsOptions)
viewsOptions.UpdateInterval = 5000
viewsOptions.UpdateMinChanges = 5
viewsOptions.ReplicaUpdateMinChanges = 5
settings.CouchBase.ViewsOptions = viewsOptions
err := cbes.RegisterDataBase(settings)
if err != nil {
beego.Critical(err)
}
}
开发者ID:laura-h,项目名称:inventory-tool,代码行数:33,代码来源:main.go
示例10: init
func init() {
err := cbes.RegisterModel(new(SecurityGroup))
if err != nil {
beego.Critical(err)
}
}
开发者ID:laura-h,项目名称:inventory-tool,代码行数:7,代码来源:security-group.go
示例11: Connect
//数据库连接
func Connect() {
var dns string
db_type := beego.AppConfig.String("db_type")
db_host := beego.AppConfig.String("db_host")
db_port := beego.AppConfig.String("db_port")
db_user := beego.AppConfig.String("db_user")
db_pass := beego.AppConfig.String("db_pass")
db_name := beego.AppConfig.String("db_name")
db_path := beego.AppConfig.String("db_path")
db_sslmode := beego.AppConfig.String("db_sslmode")
switch db_type {
case "mysql":
orm.RegisterDriver("mysql", orm.DR_MySQL)
dns = fmt.Sprintf("%s:%[email protected](%s:%s)/%s?charset=utf8", db_user, db_pass, db_host, db_port, db_name)
break
case "postgres":
orm.RegisterDriver("postgres", orm.DR_Postgres)
dns = fmt.Sprintf("dbname=%s host=%s user=%s password=%s port=%s sslmode=%s", db_name, db_host, db_user, db_pass, db_port, db_sslmode)
case "sqlite3":
orm.RegisterDriver("sqlite3", orm.DR_Sqlite)
if db_path == "" {
db_path = "./"
}
dns = fmt.Sprintf("%s%s.db", db_path, db_name)
break
default:
beego.Critical("Database driver is not allowed:", db_type)
}
orm.RegisterDataBase("default", db_type, dns)
}
开发者ID:kerneltravel,项目名称:admin,代码行数:31,代码来源:AdminInit.go
示例12: createdb
/**
* 创建数据库
*/
func createdb() {
fmt.Printf("run dbport \n")
db_type := beego.AppConfig.String("dbdriver")
db_host := beego.AppConfig.String("dbhost")
db_port := beego.AppConfig.String("dbport")
db_user := beego.AppConfig.String("dbuser")
db_pass := beego.AppConfig.String("dbpass")
db_name := beego.AppConfig.String("dbname")
var dns string
var sqlstring string
switch db_type {
case "mysql":
dns = fmt.Sprintf("%s:%[email protected](%s:%s)/?charset=utf8", db_user, db_pass, db_host, db_port)
sqlstring = fmt.Sprintf("CREATE DATABASE if not exists `%s` CHARSET utf8 COLLATE utf8_general_ci", db_name)
break
default:
beego.Critical("Database driver is not allowed:", db_type)
}
db, err := sql.Open(db_type, dns)
if err != nil {
panic(err.Error())
}
r, err := db.Exec(sqlstring)
if err != nil {
log.Println(err)
log.Println(r)
} else {
log.Println("Database ", db_name, " created")
}
defer db.Close()
}
开发者ID:lvzhongyi,项目名称:canku,代码行数:36,代码来源:syncdb.go
示例13: initMaps
func initMaps() {
if !com.IsFile(_NAV_TREE_PATH) {
beego.Critical(_NAV_TREE_PATH, "does not exist")
return
}
initDocMap()
initBlogMap()
}
开发者ID:rails0330,项目名称:beeweb,代码行数:9,代码来源:models.go
示例14: init
func init() {
orm.RegisterModel(new(Userinfo), new(Admininfo), new(Deviceinfo))
err := orm.RegisterDriver("mysql", orm.DR_MySQL)
if err != nil {
beego.Critical(err)
}
dbIp := beego.AppConfig.String("DbIp")
dbPort := beego.AppConfig.String("DbPort")
dbName := beego.AppConfig.String("DbName")
dbUser := beego.AppConfig.String("DbUser")
dbPassword := beego.AppConfig.String("DbPassword")
dbUrl := dbUser + ":" + dbPassword + "@tcp(" + dbIp + ":" + dbPort + ")/" + dbName + "?charset=utf8&loc=Asia%2FShanghai"
beego.Debug("dbUrl=", dbUrl)
err = orm.RegisterDataBase("default", "mysql", dbUrl)
if err != nil {
beego.Critical(err)
}
}
开发者ID:tcdog001,项目名称:szm_lss,代码行数:22,代码来源:models.go
示例15: ConnectDB
//连接数据库
func ConnectDB() {
db_type := beego.AppConfig.String("db::type")
db_host := beego.AppConfig.String("db::host")
db_port := beego.AppConfig.String("db::port")
db_user := beego.AppConfig.String("db::user")
db_pass := beego.AppConfig.String("db::pass")
db_name := beego.AppConfig.String("db::name")
db_path := beego.AppConfig.String("db::path")
db_sslmode := beego.AppConfig.String("db::sslmode")
var dsn string
switch db_type {
case "mysql":
orm.RegisterDriver("mysql", orm.DR_MySQL)
dsn = fmt.Sprintf("%s:%[email protected](%s:%s)/%s?charset=utf8", db_user, db_pass, db_host, db_port, db_name)
dsn += "&loc=Asia%2FShanghai"
break
case "postgres":
orm.RegisterDriver("postgres", orm.DR_Postgres)
dsn = fmt.Sprintf("dbname=%s host=%s user=%s password=%s port=%s sslmode=%s", db_name, db_host, db_user, db_pass, db_port, db_sslmode)
case "sqlite3":
orm.RegisterDriver("sqlite3", orm.DR_Sqlite)
if db_path == "" {
db_path = "./"
}
dsn = fmt.Sprintf("%s%s.db", db_path, db_name)
break
default:
beego.Critical("Database driver not support: ", db_type)
}
orm.RegisterDataBase("default", db_type, dsn)
//打印查询日志
orm.Debug, _ = beego.AppConfig.Bool("db::orm_debug")
o = orm.NewOrm()
// 数据库别名
name := "default"
// 不强制重新建数据库
force := false
// 打印执行过程
verbose := true
// 遇到错误立即返回
err := orm.RunSyncdb(name, force, verbose)
if err != nil {
beego.Error(err)
}
}
开发者ID:kevinxu001,项目名称:survey,代码行数:51,代码来源:db.go
示例16: main
func main() {
//Open orm debug mode
orm.Debug = false
//Auto create tables
err := orm.RunSyncdb("default", false, true)
if err != nil {
beego.Critical("sycndb error! Error:", err)
}
//Start app
beego.Trace("LTE_Security start running...")
beego.Run()
}
开发者ID:tcdog001,项目名称:szm_lss,代码行数:14,代码来源:main.go
示例17: init
func init() {
appDataDb, err := leveldb.OpenFile(Configs["conf/db.conf"].String("app::path"), nil)
if err != nil {
beego.Critical("unable to open " + Configs["conf/db.conf"].String("app::path"))
}
defer appDataDb.Close()
urlCountStr, err := appDataDb.Get([]byte("urlCount"), nil)
if err != nil {
urlCount = int64(1014)
} else {
urlCount, _ = strconv.ParseInt(string(urlCountStr), 10, 64)
}
}
开发者ID:aholic,项目名称:note.cstdlib.com,代码行数:14,代码来源:note.go
示例18: createDB
//创建数据库
func createDB() {
db_type := beego.AppConfig.String("db::type")
db_host := beego.AppConfig.String("db::host")
db_port := beego.AppConfig.String("db::port")
db_user := beego.AppConfig.String("db::user")
db_pass := beego.AppConfig.String("db::pass")
db_name := beego.AppConfig.String("db::name")
db_path := beego.AppConfig.String("db::path")
db_sslmode := beego.AppConfig.String("db::sslmode")
var dsn string
var sqlstring string
switch db_type {
case "mysql":
dsn = fmt.Sprintf("%s:%[email protected](%s:%s)/?charset=utf8&loc=Asia%2FShanghai", db_user, db_pass, db_host, db_port)
dsn += "&loc=Asia%2FShanghai"
sqlstring = fmt.Sprintf("CREATE DATABASE if not exists `%s` CHARSET utf8 COLLATE utf8_general_ci", db_name)
break
case "postgres":
dsn = fmt.Sprintf("host=%s user=%s password=%s port=%s sslmode=%s", db_host, db_user, db_pass, db_port, db_sslmode)
sqlstring = fmt.Sprintf("CREATE DATABASE %s", db_name)
break
case "sqlite3":
if db_path == "" {
db_path = "./"
}
dsn = fmt.Sprintf("%s%s.db", db_path, db_name)
os.Remove(dsn)
sqlstring = "create table init (n varchar(32));drop table init;"
break
default:
beego.Critical("Database driver not support: ", db_type)
}
db, err := sql.Open(db_type, dsn)
defer db.Close()
if err != nil {
panic(err.Error())
}
r, err := db.Exec(sqlstring)
if err != nil {
log.Println(err)
log.Println(r)
} else {
log.Println("Database ", db_name, " created")
}
}
开发者ID:kevinxu001,项目名称:survey,代码行数:49,代码来源:db.go
示例19: init
func init() {
//获取当天时间
now := time.Now().Format("2006-01-02")
file, err := os.OpenFile("/Users/mac/mygo/src/blog/log/"+now+".log", os.O_RDWR|os.O_APPEND, 0644)
if err != nil {
fd, err := os.Create("/Users/mac/mygo/src/blog/log/" + now + ".log")
if err != nil {
beego.Critical("openfile beepkg.log:", err)
return
}
lg := log.New(fd, "", log.Ldate|log.Ltime)
beego.SetLogger(lg)
}
lg := log.New(file, "", log.Ldate|log.Ltime)
beego.SetLogger(lg)
}
开发者ID:hobartcui,项目名称:blogs,代码行数:16,代码来源:log.go
示例20: createDB
//创建数据库
func createDB() {
db_type := beego.AppConfig.String("db.type")
db_host := beego.AppConfig.String("db.host")
db_port := beego.AppConfig.String("db.port")
db_user := beego.AppConfig.String("db.user")
db_pass := beego.AppConfig.String("db.password")
db_name := beego.AppConfig.String("db.name")
db_path := beego.AppConfig.String("db.path")
db_sslmode := beego.AppConfig.String("db.sslmode")
var dns string
var sqlstring string
switch db_type {
case "mysql":
dns = fmt.Sprintf("%s:%[email protected](%s:%s)/?charset=utf8", db_user, db_pass, db_host, db_port)
sqlstring = fmt.Sprintf("CREATE DATABASE if not exists `%s` CHARSET utf8 COLLATE utf8_general_ci", db_name)
break
case "postgres":
dns = fmt.Sprintf("host=%s user=%s password=%s port=%s sslmode=%s", db_host, db_user, db_pass, db_port, db_sslmode)
sqlstring = fmt.Sprintf("CREATE DATABASE %s", db_name)
break
// case "sqlite3":
// if db_path == "" {
// db_path = "./"
// }
// dns = fmt.Sprintf("%s%s.db", db_path, db_name)
// os.Remove(dns)
// sqlstring = "create table init (n varchar(32));drop table init;"
// break
default:
beego.Critical("Database driver is not allowed:", db_type)
}
db, err := sql.Open(db_type, dns)
if err != nil {
panic(err.Error())
}
r, err := db.Exec(sqlstring)
if err != nil {
log.Println(err)
log.Println(r)
} else {
log.Println("Database ", db_name, " created")
}
defer db.Close()
}
开发者ID:yankaics,项目名称:shopoms,代码行数:48,代码来源:syncdb.go
注:本文中的github.com/astaxie/beego.Critical函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论