本文整理汇总了Golang中github.com/revel/config.ReadDefault函数的典型用法代码示例。如果您正苦于以下问题:Golang ReadDefault函数的具体用法?Golang ReadDefault怎么用?Golang ReadDefault使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadDefault函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: initConfig
func initConfig() {
engine = models.Engine()
c, err := config.ReadDefault("conf/misc.conf")
if err != nil {
panic(err)
}
smtpConfig.Username, err = c.String("smtp", "username")
if err != nil {
panic(err)
}
smtpConfig.Password, _ = c.String("smtp", "password")
smtpConfig.Host, _ = c.String("smtp", "host")
smtpConfig.Addr, _ = c.String("smtp", "address")
admin, err = c.String("app", "admin")
if err != nil {
panic(err)
}
c, err = config.ReadDefault("conf/app.conf")
if err != nil {
panic(err)
}
appAddr, err = c.String("", "http.addr")
appPort, err = c.String("", "http.port")
if appAddr == "" || appPort == "" {
panic("init fail,can not get address and port from conf/misc.conf")
}
}
开发者ID:jango2015,项目名称:OJ,代码行数:27,代码来源:init.go
示例2: main
func main() {
fmt.Printf("==============================================================\n")
var err error
hostname, _ := os.Hostname()
_ = hostname
cnfPath := "./conf.conf"
path, _ := GetCurrPath()
println(path)
c, err := config.ReadDefault(cnfPath)
CheckErr(err, "read config")
s := NewSection("mail", cnfPath, c)
s.SetValue("username", "gold")
s.SetValue("password", "")
s.SetValue("domain", "monitor.spriteapp.com")
s.SetValue("port", "25")
s.SetValue("to", "[email protected];")
err = s.PersistenceConfig()
CheckErr(err, "save config")
c, err = config.ReadDefault(cnfPath)
userName, err := c.String("mail", "username")
CheckErr(err, "get value mail->username")
println(userName)
fmt.Printf("==============================================================\n")
}
开发者ID:dogeerf,项目名称:tool,代码行数:31,代码来源:conf.go
示例3: readESConfFile
func (esb *ElasticsearchStorageBackendImp) readESConfFile() {
if c, err := config.ReadDefault(esb.ConfigurationFilesImplPtr.GetESConfFile()); err != nil {
esb.LoggerImplPtr.Error("unable to read es-conf.conf file switching to defualt")
esb.BaseUrl = "http://0.0.0.0:9200"
} else {
var protocol string = "http"
var ipaddress string = "0.0.0.0"
var port string = "9200"
if temp, err := c.String("ES_SERVER", "protocol"); err == nil {
protocol = temp
}
if temp, err := c.String("ES_SERVER", "server"); err == nil && temp != "ES_ENDPOINT" {
ipaddress = temp
}
if temp, err := c.String("ES_SERVER", "restport"); err == nil && temp != "ES_REST_PORT" {
port = temp
}
if temp, err := c.String("ES_SERVER", "username"); err == nil {
esb.Username = temp
}
if temp, err := c.String("ES_SERVER", "password"); err == nil {
esb.Password = temp
}
esb.BaseUrl = protocol + "://" + ipaddress + ":" + port
}
}
开发者ID:maskofG,项目名称:anticyberbullying,代码行数:31,代码来源:ElasticsearchStorageBackendImpl.go
示例4: Manager
//编辑器管理
func (c *Kindeditor) Manager(upload *models.Upload) revel.Result {
file := make(map[string]interface{})
//判断是否是系统的分隔符
separator := "/"
if os.IsPathSeparator('\\') {
separator = "\\"
} else {
separator = "/"
}
basepath, _ := filepath.Abs("")
config_file := (revel.BasePath + "/conf/config.conf")
config_file = strings.Replace(config_file, "/", separator, -1)
config_conf, _ := config.ReadDefault(config_file)
//上传文件目录
upload_dir, _ := config_conf.String("upload", "upload.dir")
//允许上传的后缀名
filesuffix, _ := config_conf.String("upload", "upload.filesuffix")
revel.WARN.Println(filesuffix)
//前台网站地址
sitedomain, _ := config_conf.String("website", "website.sitedomain")
//根目录路径,可以指定绝对路径,比如 /var/www/attached/
root_path := fmt.Sprintf("%s/www/%s/", basepath, upload_dir)
//根目录URL,可以指定绝对路径,比如 http://www.yoursite.com/attached/
root_url := sitedomain + upload_dir
//目录名
dir_name := c.Params.Get("dir")
if dir_name != "" {
root_path += dir_name + "/"
root_url += dir_name + "/"
}
//相对于根目录的上一级目录
file["moveup_dir_path"] = ""
//相对于根目录的当前目录
file["current_dir_path"] = ""
//当前目录的URL
file["current_url"] = ""
//文件数
file["total_count"] = 10
//文件列表数组
file["file_list"] = ""
return c.RenderJson(file)
}
开发者ID:blackmady,项目名称:GoCMS,代码行数:58,代码来源:kindeditor.go
示例5: Main
func (c App) Main(admin *models.Admin) revel.Result {
title := "首页--GoCMS管理系统"
if UserID, ok := c.Session["UserID"]; ok {
UserID, err := strconv.ParseInt(UserID, 10, 64)
if err != nil {
revel.WARN.Println(err)
}
admin_info := admin.GetById(UserID)
//判断是否是系统的分隔符
separator := "/"
if os.IsPathSeparator('\\') {
separator = "\\"
} else {
separator = "/"
}
config_file := (revel.BasePath + "/conf/config.conf")
config_file = strings.Replace(config_file, "/", separator, -1)
config_conf, _ := config.ReadDefault(config_file)
system_info := make(map[string]string)
//版本
version, _ := config_conf.String("website", "website.version")
system_info["version"] = version
//前台网站地址
sitedomain, _ := config_conf.String("website", "website.sitedomain")
system_info["sitedomain"] = sitedomain
//操作系统
system_info["os"] = strings.ToUpper(runtime.GOOS + " " + runtime.GOARCH)
//Go版本
system_info["go_varsion"] = strings.ToUpper(runtime.Version())
//MySQL版本
system_info["mysql_varsion"] = admin.GetMysqlVer()
//快捷面板
admin_panel := new(models.Admin_Panel)
panel_list := admin_panel.GetPanelList(admin_info)
c.Render(title, admin_info, system_info, panel_list)
} else {
c.Render(title)
}
return c.RenderTemplate("App/Main.html")
}
开发者ID:JREAMLU,项目名称:GoCMS,代码行数:54,代码来源:app.go
示例6: readlcrestServerConfig
//readlcrestServiceConfig reads the lcrest-conf.conf file to initialized our log-courier-rest service for running
// our HTTP REST service
func (serv *RestServer) readlcrestServerConfig() {
if c, err := config.ReadDefault(serv.ConfigurationFileListPtr.GetRestConfFile()); err != nil {
serv.LoggerPtr.Error("unable to read rest-conf.conf file- switching to defualt Address: %s Port: %s ",
serv.IpAddress, serv.Port)
} else {
if temp, err := c.String("REST", "host"); err == nil && temp != "" && temp != "REST_HOST_ADDRESS" {
serv.IpAddress = temp
}
if temp, err := c.String("REST", "port"); err == nil && temp != "" && temp != "REST_PORT" {
serv.Port = temp
}
}
}
开发者ID:maskofG,项目名称:anticyberbullying,代码行数:16,代码来源:server.go
示例7: NewConfig
// Crea una nueva estructura tipo Config
func NewConfig() (config *Config, err error) {
config = &Config{Filename: filename}
if config.Pwd, err = os.Getwd(); err != nil {
fmt.Errorf("| Error | %v \n", err)
panic(err)
}
var file = config.File()
// fmt.Printf("App | Config will be loaded from %v \n", file)
if config.Config, err = c.ReadDefault(file); err != nil {
fmt.Errorf("| Error | %v \n", err)
panic(err)
}
// fmt.Println("App | Config loaded successfully! \n")
config.IsProduction = strings.EqualFold(config.Default("env"), production)
return
}
开发者ID:ivan-iver,项目名称:iTool,代码行数:18,代码来源:config.go
示例8: InitDB
func InitDB() {
separator := utils.OsSeparator()
config_file := revel.BasePath + separator + "conf" + separator + "databases.conf"
c, _ := config.ReadDefault(config_file)
guildcore_driver, _ := c.String("database", "db.guild_core.driver")
guildcore_dbname, _ := c.String("database", "db.guild_core.dbname")
guildcore_user, _ := c.String("database", "db.guild_core.user")
guildcore_password, _ := c.String("database", "db.guild_core.password")
guildcore_host, _ := c.String("database", "db.guild_core.host")
var err error
DB, err = xorm.NewEngine(guildcore_driver, fmt.Sprintf("%s:%[email protected](%s)/%s?charset=utf8", guildcore_user, guildcore_password, guildcore_host, guildcore_dbname))
if err != nil {
revel.WARN.Printf("DB 错误:%v", err)
}
}
开发者ID:yuer1727,项目名称:gospace,代码行数:18,代码来源:init.go
示例9: GetById
//根据Id获取内容信息
func (a *Article) GetById(Id int64) *Article {
article := new(Article)
//返回的结果为两个参数,一个has为该条记录是否存在,
//第二个参数err为是否有错误。不管err是否为nil,has都有可能为true或者false。
has, err := DB_Read.Id(Id).Get(article)
if err != nil {
revel.WARN.Println(has)
revel.WARN.Printf("错误: %v", err)
} else {
admin := new(Admin)
article.Admin = admin.GetById(article.Aid)
//所属栏目
category := new(Category)
article.Category = category.GetById(article.Cid)
if article.Thumb != "" {
//判断是否是系统的分隔符
separator := "/"
if os.IsPathSeparator('\\') {
separator = "\\"
} else {
separator = "/"
}
config_file := (revel.BasePath + "/conf/config.conf")
config_file = strings.Replace(config_file, "/", separator, -1)
config_conf, _ := config.ReadDefault(config_file)
//前台网站地址
sitedomain, _ := config_conf.String("website", "website.sitedomain")
article.Thumb = sitedomain + article.Thumb
}
//相关文章
if len(article.Relation) > 0 {
DB_Write.Where("id in (" + article.Relation + ")").Find(&article.RelationList)
}
}
return article
}
开发者ID:blackmady,项目名称:GoCMS,代码行数:45,代码来源:article.go
示例10: init
func init() {
var err error
c, err := config.ReadDefault("conf/misc.conf")
if err != nil {
panic(err)
}
if c == nil {
panic("conf path not founded.")
}
user, _ := c.String("postgres", "user")
password, _ := c.String("postgres", "password")
dbname, _ := c.String("postgres", "dbname")
sslmode, _ := c.String("postgres", "sslmode")
host, _ := c.String("postgres", "host")
port, _ := c.String("postgres", "port")
dataSource := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s host=%s port=%s", user, password, dbname, sslmode, host, port)
engine, err = xorm.NewEngine("postgres", dataSource)
if err != nil {
panic(err)
}
showSQL, _ := c.Bool("postgres", "show_sql")
/*
showErr, _ := c.Bool("postgres", "show_err")
showDebug, _ := c.Bool("postgres", "show_debug")
showWarn, _ := c.Bool("postgres", "show_warn")
*/
engine.ShowSQL = showSQL
fmt.Println("show SQL", showSQL)
/*
engine.ShowWarn = showWarn
engine.ShowErr = showErr
engine.ShowDebug = showDebug
*/
err = engine.Sync(
new(Source),
new(Problem),
new(User),
new(Solve),
)
if err != nil {
panic(err)
}
}
开发者ID:jango2015,项目名称:OJ,代码行数:43,代码来源:init.go
示例11: GetById
//根据Id获取内容信息
func (c *Focus) GetById(Id int64) *Focus {
focus := new(Focus)
//返回的结果为两个参数,一个has为该条记录是否存在,
//第二个参数err为是否有错误。不管err是否为nil,has都有可能为true或者false。
has, err := DB_Read.Id(Id).Get(focus)
if err != nil {
revel.WARN.Println(has)
revel.WARN.Printf("错误: %v", err)
} else {
admin := new(Admin)
focus.Admin = admin.GetById(focus.Aid)
//所属分类
focuscate := new(FocusCate)
focus.Focuscate = focuscate.GetById(focus.Cid)
if focus.Img != "" {
//判断是否是系统的分隔符
separator := "/"
if os.IsPathSeparator('\\') {
separator = "\\"
} else {
separator = "/"
}
config_file := (revel.BasePath + "/conf/config.conf")
config_file = strings.Replace(config_file, "/", separator, -1)
config_conf, _ := config.ReadDefault(config_file)
//前台网站地址
sitedomain, _ := config_conf.String("website", "website.sitedomain")
focus.Img = sitedomain + focus.Img
}
}
return focus
}
开发者ID:blackmady,项目名称:GoCMS,代码行数:39,代码来源:focus.go
示例12: InitBizService
func InitBizService() {
separator := utils.OsSeparator()
config_file := revel.BasePath + separator + "conf" + separator + "api.conf"
c, _ := config.ReadDefault(config_file)
/*
bizService.addr=127.0.0.1:9151
bizService.caller=guild.website
bizService.secretkey=04ab5c51ew81c353g4dc2y0d2f6x51ma
*/
bizService_addr, _ := c.String("api", "bizService.addr")
bizService_caller, _ := c.String("api", "bizService.caller")
bizService_secretkey, _ := c.String("api", "db.guild_core.user")
BizAddress = "http://" + bizService_addr
BizCaller = bizService_caller
BizSecretKey = bizService_secretkey
Md5Ctx = md5.New()
}
开发者ID:yuer1727,项目名称:gospace,代码行数:23,代码来源:init.go
示例13: Index
func (c Copyfrom) Index(copyfrom *models.Copyfrom) revel.Result {
title := "来源管理--GoCMS管理系统"
var page string = c.Params.Get("page")
//判断是否是系统的分隔符
separator := "/"
if os.IsPathSeparator('\\') {
separator = "\\"
} else {
separator = "/"
}
config_file := (revel.BasePath + "/conf/config.conf")
config_file = strings.Replace(config_file, "/", separator, -1)
config_conf, _ := config.ReadDefault(config_file)
//前台网站地址
sitedomain, _ := config_conf.String("website", "website.sitedomain")
if len(page) > 0 {
Page, err := strconv.ParseInt(page, 10, 64)
if err != nil {
revel.WARN.Println(err)
}
copyfrom_list, pages := copyfrom.GetByAll(Page, 10)
c.Render(title, copyfrom_list, sitedomain, pages)
} else {
copyfrom_list, pages := copyfrom.GetByAll(1, 10)
c.Render(title, copyfrom_list, sitedomain, pages)
}
return c.RenderTemplate("Extend/Copyfrom/Index.html")
}
开发者ID:zacklin923,项目名称:GoCMS,代码行数:37,代码来源:copyfrom.go
示例14: parseMessagesFile
func parseMessagesFile(path string) (messageConfig *config.Config, error error) {
messageConfig, error = config.ReadDefault(path)
return
}
开发者ID:revel,项目名称:revel,代码行数:4,代码来源:i18n.go
示例15: Edit
//编辑内容
func (c Content) Edit(article *models.Article) revel.Result {
if c.Request.Method == "GET" {
title := "内容--GoCMS编辑内容"
var cid string = c.Params.Get("cid")
var id string = c.Params.Get("id")
if len(cid) > 0 {
Cid, err := strconv.ParseInt(cid, 10, 64)
if err != nil {
revel.WARN.Println(err)
}
Id, err := strconv.ParseInt(id, 10, 64)
if err != nil {
revel.WARN.Println(err)
}
//内容
article_info := article.GetById(Id)
//栏目信息
category := new(models.Category)
category_info := category.GetById(Cid)
//来源
copyfrom := new(models.Copyfrom)
copyfrom_list := copyfrom.GetRoleList()
c.Render(title, cid, category_info, article_info, copyfrom_list)
return c.RenderTemplate("Content/Manage/Edit.html")
} else {
c.Render(title, cid)
return c.RenderTemplate("Content/Manage/Edit.html")
}
} else {
var dosubmit string = c.Params.Get("dosubmit")
var dosubmit_continue string = c.Params.Get("dosubmit_continue")
var cid string = c.Params.Get("cid")
var id string = c.Params.Get("id")
Id, err := strconv.ParseInt(id, 10, 64)
if err != nil {
revel.WARN.Println(err)
}
var title string = c.Params.Get("title")
if len(title) > 0 {
article.Title = title
} else {
c.Flash.Error("请输入标题!")
c.Flash.Out["url"] = "/Content/Add/" + cid + "/"
return c.Redirect("/Message/")
}
var style_color string = c.Params.Get("style_color")
article.Color = style_color
var style_font_weight string = c.Params.Get("style_font_weight")
article.Font = style_font_weight
var thumb string = c.Params.Get("thumb")
if len(thumb) > 0 {
//判断是否是系统的分隔符
separator := "/"
if os.IsPathSeparator('\\') {
separator = "\\"
} else {
separator = "/"
}
config_file := (revel.BasePath + "/conf/config.conf")
config_file = strings.Replace(config_file, "/", separator, -1)
config_conf, _ := config.ReadDefault(config_file)
//前台网站地址
sitedomain, _ := config_conf.String("website", "website.sitedomain")
thumb = strings.Replace(thumb, sitedomain, "", -1)
article.Thumb = thumb
} else {
article.Thumb = ""
}
var content string = c.Params.Get("content")
if len(content) > 0 {
article.Content = content
} else {
c.Flash.Error("请输入内容!")
c.Flash.Out["url"] = "/Content/Add/" + cid + "/"
return c.Redirect("/Message/")
}
var copyfrom string = c.Params.Get("copyfrom")
//.........这里部分代码省略.........
开发者ID:blackmady,项目名称:GoCMS,代码行数:101,代码来源:content.go
示例16: init
func (logger *LoggerImpl) init(ConfigurationFileListPtr ConfigurationFilesInterface, filename string) {
logger.RelativeFileName = filename
logger.ConfigurationFileListPtr = ConfigurationFileListPtr
logger.IsLogRotationEnabled = false
logger.LogsFolder = "/var/log/log-courier-rest"
logger.LogFiles = []string{}
logger.LogMinLevel = "INFO"
logger.LogMaxLevel = "ERROR"
logger.LogFormat = "%Date %Time [%LEVEL] %Msg%n"
logger.LogRotationAttributes = LogRotationMetadata{RotationType: "size", MaxRollNumber: 5, Properties: map[string]string{}}
if c, err := config.ReadDefault(logger.ConfigurationFileListPtr.GetLoggerConfFile()); err != nil {
log.Errorf("unable to read lc-logger.conf file configPath:%s ", logger.ConfigurationFileListPtr.GetLoggerConfFile())
} else {
logger.LogConfigurationFile = logger.ConfigurationFileListPtr.GetLoggerConfFile()
if temp, err := c.String("LC_LOGGER", "logrotation"); err == nil {
if strings.ToLower(strings.TrimSpace(temp)) == "enabled" {
logger.IsLogRotationEnabled = true
} else {
logger.IsLogRotationEnabled = false
}
}
if temp, err := c.String("LC_LOGGER", "logfolder"); err == nil {
logger.LogsFolder = temp
}
if temp, err := c.String("LC_LOGGER", "minloglevel"); err == nil {
logger.LogMinLevel = strings.ToUpper(strings.TrimSpace(temp))
}
if temp, err := c.String("LC_LOGGER", "maxloglevel"); err == nil {
logger.LogMaxLevel = strings.ToUpper(strings.TrimSpace(temp))
}
if temp, err := c.String("LC_LOGGER", "logformat"); err == nil {
logger.LogFormat = temp
}
if temp, err := c.String("LC_LOGGER", "rotation_interval_type"); err == nil {
logger.LogRotationAttributes.RotationType = strings.ToLower(strings.TrimSpace(temp))
}
if temp, err := c.String("LC_LOGGER", "max_rotated_files"); err == nil {
if logger.LogRotationAttributes.MaxRollNumber, err = strconv.Atoi(temp); err != nil {
logger.LogRotationAttributes.MaxRollNumber = 5
}
}
if logger.LogRotationAttributes.RotationType == "size" {
logger.LogRotationAttributes.Properties["rotation_size_limit_inbytes"] = "26214400"
if temp, err := c.String("LC_LOGGER", "rotation_size_limit"); err == nil {
patternObj, _ := regexp.Compile(LogFileSizePattern)
if foundBool := patternObj.MatchString(temp); foundBool {
sizeAttribs := patternObj.FindAllString(temp, -1)
var bytes int = 0
var multiplier int = 1
var err error
if bytes, err = strconv.Atoi(sizeAttribs[0]); err != nil {
bytes = 26214400
} else {
multiplierStr := strings.ToUpper(sizeAttribs[1])
switch multiplierStr {
case "B":
multiplier = 1
case "KB":
multiplier = 1024
case "MB":
multiplier = 1024 * 1024
case "GB":
multiplier = 1024 * 1024 * 1024
case "TB":
multiplier = 1024 * 1024 * 1024 * 1024
default:
multiplier = 1
}
bytes = bytes * multiplier
logger.LogRotationAttributes.Properties["rotation_size_limit_inbytes"] = strconv.Itoa(bytes)
}
}
}
}
}
logger.LogFiles = append(logger.LogFiles, logger.LogsFolder+"/"+logger.RelativeFileName+".log")
seelogStart := `<seelog minlevel="` + strings.ToLower(logger.LogMinLevel) + `" maxlevel="` + strings.ToLower(logger.LogMaxLevel) + `">`
outputsStart := `<outputs formatid="common">`
rollingSetting := ``
if logger.IsLogRotationEnabled {
if logger.LogRotationAttributes.RotationType == "size" {
rollingSetting = `<rollingfile type="size" filename="` + logger.LogFiles[0] + `" maxsize="` +
logger.LogRotationAttributes.Properties["rotation_size_limit_inbytes"] + `" maxrolls="` + strconv.Itoa(logger.LogRotationAttributes.MaxRollNumber) + `"/>`
}
}
formatsStart := `<formats>`
format1 := `<format id="common" format="` + logger.LogFormat + `" />`
formatsEnd := `</formats>`
outputsEnd := `</outputs>`
//.........这里部分代码省略.........
开发者ID:maskofG,项目名称:anticyberbullying,代码行数:101,代码来源:LoggerImpl.go
示例17: InitDB
//设置数据库
func InitDB() {
//判断是否是系统的分隔符
separator := "/"
if os.IsPathSeparator('\\') {
separator = "\\"
} else {
separator = "/"
}
config_file := (revel.BasePath + "/conf/databases.conf")
config_file = strings.Replace(config_file, "/", separator, -1)
c, _ := config.ReadDefault(config_file)
read_driver, _ := c.String("database", "db.read.driver")
read_dbname, _ := c.String("database", "db.read.dbname")
read_user, _ := c.String("database", "db.read.user")
read_password, _ := c.String("database", "db.read.password")
read_host, _ := c.String("database", "db.read.host")
//read_prefix, _ := c.String("database", "db.read.prefix")
//数据库链接
var err error
DB_Read, err = xorm.NewEngine(read_driver, fmt.Sprintf("%s:%[email protected](%s)/%s?charset=utf8", read_user, read_password, read_host, read_dbname))
if err != nil {
revel.WARN.Printf("DB_Read错误: %v", err)
}
write_driver, _ := c.String("database", "db.write.driver")
write_dbname, _ := c.String("database", "db.write.dbname")
write_user, _ := c.String("database", "db.write.user")
write_password, _ := c.String("database", "db.write.password")
write_host, _ := c.String("database", "db.write.host")
//write_prefix, _ := c.String("database", "db.write.prefix")
DB_Write, err = xorm.NewEngine(write_driver, fmt.Sprintf("%s:%[email protected](%s)/%s?charset=utf8", write_user, write_password, write_host, write_dbname))
if err != nil {
revel.WARN.Printf("DB_Write错误: %v", err)
}
//缓存方式是存放到内存中,缓存struct的记录数为1000条
//cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), 1000)
//DB_Read.SetDefaultCacher(cacher)
//DB_Write.SetDefaultCacher(cacher)
//控制台打印SQL语句
//DB_Read.ShowSQL = true
//DB_Write.ShowSQL = true
//控制台打印调试信息
//DB_Read.ShowDebug = true
//DB_Write.ShowDebug = true
//控制台打印错误信息
//DB_Read.ShowErr = true
//DB_Write.ShowErr = true
//控制台打印警告信息
//DB_Read.ShowWarn = true
//DB_Read.ShowWarn = true
}
开发者ID:JREAMLU,项目名称:GoCMS,代码行数:62,代码来源:init.go
示例18: GetByAll
//获取焦点图列表
func (c *Focus) GetByAll(search string, Page int64, Perpage int64) (focus_arr []*Focus, html template.HTML, where map[string]interface{}) {
focus_list := []*Focus{}
//查询条件
var WhereStr string = " 1 AND "
if len(search) > 0 {
//解码
where = utils.DecodeSegment(search)
revel.WARN.Println(where)
if where["cid"] != "" {
WhereStr += " `cid`='" + fmt.Sprintf("%d", where["cid"]) + "' AND "
}
if where["keyword"] != "" {
//关键字
keyword := fmt.Sprintf("%s", where["keyword"])
WhereStr += " `title` like '%" + keyword + "%' AND "
}
}
WhereStr += " 1 "
//查询总数
focus := new(Focus)
Total, err := DB_Read.Where(WhereStr).Count(focus)
if err != nil {
revel.WARN.Printf("错误: %v", err)
}
//分页
Pager := new(utils.Page)
Pager.SubPage_link = "/Focus/"
Pager.Nums = Total
Pager.Perpage = Perpage
Pager.Current_page = Page
Pager.SubPage_type = 2
pages := Pager.Show()
//查询数据
DB_Read.Where(WhereStr).Limit(int(Perpage), int((Page-1)*Pager.Perpage)).Desc("id").Find(&focus_list)
if len(focus_list) > 0 {
admin := new(Admin)
focuscate := new(FocusCate)
for i, v := range focus_list {
focus_list[i].Admin = admin.GetById(v.Aid)
//所属栏目
focus_list[i].Focuscate = focuscate.GetById(v.Cid)
if v.Img != "" {
//判断是否是系统的分隔符
separator := "/"
if os.IsPathSeparator('\\') {
separator = "\\"
} else {
separator = "/"
}
config_file := (revel.BasePath + "/conf/config.conf")
config_file = strings.Replace(config_file, "/", separator, -1)
config_conf, _ := config.ReadDefault(config_file)
//前台网站地址
sitedomain, _ := config_conf.String("website", "website.sitedomain")
v.Img = sitedomain + v.Img
}
}
}
return focus_list, pages, where
}
开发者ID:blackmady,项目名称:GoCMS,代码行数:78,代码来源:focus.go
示例19: Main
func (c App) Main(admin *models.Admin) revel.Result {
title := "首页--GoCMS管理系统"
UserID := utils.GetSession("UserID", c.Session)
if len(UserID) > 0 {
UserID, err := strconv.ParseInt(UserID, 10, 64)
if err != nil {
revel.WARN.Println(err)
}
admin_info := admin.GetById(UserID)
//判断是否是系统的分隔符
separator := "/"
if os.IsPathSeparator('\\') {
separator = "\\"
} else {
separator = "/"
}
config_file := (revel.BasePath + "/conf/config.conf")
config_file = strings.Replace(config_file, "/", separator, -1)
config_conf, _ := config.ReadDefault(config_file)
system_info := make(map[string]string)
//版本
version, _ := config_conf.String("website", "website.version")
system_info["version"] = version
//前台网站地址
sitedomain, _ := config_conf.String("website", "website.sitedomain")
system_info["sitedomain"] = sitedomain
//操作系统
system_info["os"] = strings.ToUpper(runtime.GOOS + " " + runtime.GOARCH)
//Go版本
system_info["go_varsion"] = strings.ToUpper(runtime.Version())
//Revel版本
system_info["revel_varsion"] = strings.ToUpper("Revel 0.11")
//MySQL版本
system_info["mysql_varsion"] = admin.GetMysqlVer()
//服务器监控
// memory_info, _ := gopsutil.VirtualMemory()
// system_info["main_server_total_memory"] = utils.FileSize(int(memory_info.Total))
// system_info["main_server_free_memory"] = utils.FileSize(int(memory_info.Free))
// system_info["main_server_available_memory"] = utils.FileSize(int(memory_info.Available))
// system_info["main_server_UsedPercent_memory"] = fmt.Sprintf("%10.2f%%", memory_info.UsedPercent)
// host, _ := gopsutil.HostInfo()
// system_info["main_server_Hostname"] = host.Hostname
// system_info["main_server_OS"] = host.OS
// system_info["main_server_Platform"] = host.Platform
// system_info["main_server_PlatformVersion"] = host.PlatformVersion
// system_info["main_server_PlatformFamily"] = host.PlatformFamily
//快捷面板
admin_panel := new(models.Admin_Panel)
panel_list := admin_panel.GetPanelList(admin_info)
c.Render(title, admin_info, system_info, panel_list)
} else {
c.Render(title)
}
return c.RenderTemplate("App/Main.html")
}
开发者ID:blackmady,项目名称:GoCMS,代码行数:73,代码来源:app.go
示例20: Add
//添加来源
func (c Copyfrom) Add(copyfrom *models.Copyfrom) revel.Result {
if c.Request.Method == "GET" {
title := "添加来源--GoCMS管理系统"
c.Render(title)
return c.RenderTemplate("Extend/Copyfrom/Add.html")
} else {
//接收上传文件
thumb, header, err := c.Request.FormFile("thumb")
if err != nil {
//来源logo
copyfrom.Thumb = ""
} else {
defer thumb.Close()
//判断是否是系统的分隔符
separator := "/"
if os.IsPathSeparator('\\') {
separator = "\\"
} else {
separator = "/"
}
fileData, _ := ioutil.ReadAll(thumb)
if len(fileData) >= 1024*1024*2 {
c.Flash.Error("你上传大小为" + utils.FileSize(len(fileData)) + ",文件应小于2M!")
c.Flash.Out["url"] = "/Copyfrom/Add/"
return c.Redirect("/Message/")
}
basepath, _ := filepath.Abs("")
config_file := (revel.BasePath + "/conf/config.conf")
config_file = strings.Replace(config_file, "/", separator, -1)
config_conf, _ := config.ReadDefault(config_file)
//上传文件目录
upload_dir, _ := config_conf.String("upload", "upload.dir")
//允许上传的后缀名
filesuffix, _ := config_conf.String("upload", "upload.filesuffix")
//文件类型检测
if !strings.Contains(filesuffix, path.Ext(header.Filename)) {
c.Flash.Error("文件只支持图片!")
c.Flash.Out["url"] = "/Copyfrom/Add/"
return c.Redirect("/Message/")
}
//文件保存目录
web_save_path := fmt.Sprintf("/%s/copyfrom/%s", upload_dir, time.Now().Format("2006/01/02/"))
save_path := fmt.Sprintf("%s/www/%s/copyfrom/%s", basepath, upload_dir, time.Now().Format("2006/01/02/"))
//字符串替换 /替换为系统分隔符
save_path = strings.Replace(save_path, "/", separator, -1)
//新文件名
rand.Seed(time.Now().UnixNano())
rand_num := rand.Intn(99999)
new_file_name := time.Now().Format("20060102150404") + strconv.Itoa(rand_num) + path.Ext(header.Filename)
//创建目录
error := os.MkdirAll(save_path, os.ModePerm)
if error != nil {
c.Flash.Error(error.Error())
c.Flash.Out["url"] = "/Copyfrom/Add/"
return c.Redirect("/Message/")
}
//保存文件
file_dir := save_path + new_file_name
save_url := web_save_path + new_file_name
e := ioutil.WriteFile(file_dir, fileData, os.ModePerm)
if e != nil {
c.Flash.Error(e.Error())
c.Flash.Out["url"] = "/Copyfrom/Add/"
return c.Redirect("/Message/")
}
//来源logo
copyfrom.Thumb = save_url
}
//来源名称
var sitename string = c.Params.Get("sitename")
if len(sitename) > 0 {
copyfrom.Sitename = sitename
} else {
c.Flash.Error("请输入来源名称!")
c.Flash.Out["url"] = "/Copyfrom/Add/"
return c.Redirect("/Message/")
}
//来源链接
var siteurl string = c.Params.Get("siteurl")
if len(siteurl) > 0 {
copyfrom.Siteurl = siteurl
} else {
//.........这里部分代码省略.........
开发者ID:zacklin923,项目名称:GoCMS,代码行数:101,代码来源:copyfrom.go
注:本文中的github.com/revel/config.ReadDefault函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论