示例#1
0
文件: init.go 项目: jango2015/OJ
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")
	}
}
示例#2
0
文件: conf.go 项目: dogeerf/tool
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")
}
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
	}
}
示例#4
0
//编辑器管理
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)
}
示例#5
0
文件: app.go 项目: JREAMLU/GoCMS
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")
}
示例#6
0
//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
		}
	}
}
示例#7
0
文件: config.go 项目: ivan-iver/iTool
// 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
}
示例#8
0
文件: init.go 项目: yuer1727/gospace
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:%s@tcp(%s)/%s?charset=utf8", guildcore_user, guildcore_password, guildcore_host, guildcore_dbname))
	if err != nil {
		revel.WARN.Printf("DB 错误:%v", err)
	}
}
示例#9
0
//根据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
}
示例#10
0
文件: init.go 项目: jango2015/OJ
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)
	}
}
示例#11
0
文件: focus.go 项目: blackmady/GoCMS
//根据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
}
示例#12
0
文件: init.go 项目: yuer1727/gospace
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()

}
示例#13
0
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")
}
示例#14
0
文件: i18n.go 项目: revel/revel
func parseMessagesFile(path string) (messageConfig *config.Config, error error) {
	messageConfig, error = config.ReadDefault(path)
	return
}
示例#15
0
//编辑内容
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")
		if len(copyfrom) > 0 {
			article.Copyfrom = copyfrom
		} else {
			article.Copyfrom = ""
		}

		var keywords string = c.Params.Get("keywords")
		if len(keywords) > 0 {
			article.Keywords = keywords
		} else {
			article.Keywords = ""
		}

		var description string = c.Params.Get("description")
		if len(description) > 0 {
			article.Description = description
		} else {

			//是否截取内容
			var add_introduce string = c.Params.Get("add_introduce")
			if add_introduce == "1" {
				var introcude_length string = c.Params.Get("introcude_length")

				Introcude_length, err := strconv.ParseInt(introcude_length, 10, 64)
				if err != nil {
					revel.WARN.Println(err)
				}

				description = utils.Html2str(content)

				article.Description = utils.Substr(description, Introcude_length)
			} else {
				article.Description = ""
			}

		}

		var relation string = c.Params.Get("relation")
		if len(relation) > 0 {
			article.Relation = relation
		} else {
			article.Relation = ""
		}

		var pagetype string = c.Params.Get("pagetype")
		if len(pagetype) > 0 {

			Pagetype, err := strconv.ParseInt(pagetype, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			article.Pagetype = Pagetype
		} else {
			article.Pagetype = 0
		}

		var maxcharperpage string = c.Params.Get("maxcharperpage")
		if len(maxcharperpage) > 0 {
			Maxcharperpage, err := strconv.ParseInt(maxcharperpage, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			article.Maxcharperpage = Maxcharperpage
		} else {
			article.Maxcharperpage = 10000
		}

		var istop string = c.Params.Get("istop")
		if len(istop) > 0 {
			Istop, err := strconv.ParseInt(istop, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			article.Istop = Istop
		} else {
			article.Istop = 0
		}

		var status string = c.Params.Get("status")
		if len(status) > 0 {
			Status, err := strconv.ParseInt(status, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			article.Status = Status
		} else {
			article.Status = 1
		}

		var iscomment string = c.Params.Get("iscomment")
		if len(iscomment) > 0 {
			Iscomment, err := strconv.ParseInt(iscomment, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			article.Iscomment = Iscomment
		} else {
			article.Status = 1
		}

		if article.Edit(Id) {

			if len(dosubmit) > 0 {
				c.Flash.Success("编辑内容成功!")
				c.Flash.Out["url"] = "/Content/list/" + cid + "/"
				return c.Redirect("/Message/")
			} else if len(dosubmit_continue) > 0 {
				c.Flash.Success("编辑内容成功!")
				c.Flash.Out["url"] = "/Content/add/" + cid + "/"
				return c.Redirect("/Message/")
			} else {
				c.Flash.Success("编辑内容成功!")
				c.Flash.Out["url"] = "/Content/list/" + cid + "/"
				return c.Redirect("/Message/")
			}

		} else {
			c.Flash.Error("编辑内容失败")
			c.Flash.Out["url"] = "/Content/edit/" + cid + "/" + id + "/"
			return c.Redirect("/Message/")
		}
	}
}
示例#16
0
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>`
	seelogEnd := `</seelog>`

	appconfig := seelogStart + outputsStart + rollingSetting + outputsEnd + formatsStart + format1 + formatsEnd + seelogEnd
	logger.Logger, _ = log.LoggerFromConfigAsBytes([]byte(appconfig))

}
示例#17
0
文件: init.go 项目: JREAMLU/GoCMS
//设置数据库
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:%s@tcp(%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:%s@tcp(%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
}
示例#18
0
文件: focus.go 项目: blackmady/GoCMS
//获取焦点图列表
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
}
示例#19
0
文件: app.go 项目: blackmady/GoCMS
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")
}
示例#20
0
//添加来源
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 {
			c.Flash.Error("请输入来源链接!")
			c.Flash.Out["url"] = "/Copyfrom/Add/"
			return c.Redirect("/Message/")
		}

		if copyfrom.Save() {

			//******************************************
			//管理员日志
			if UserID, ok := c.Session["UserID"]; ok {
				UserID, err := strconv.ParseInt(UserID, 10, 64)
				if err != nil {
					revel.WARN.Println(err)
				}

				admin := new(models.Admin)
				admin_info := admin.GetById(UserID)

				logs := new(models.Logs)
				desc := "添加来源:" + sitename + "|^|来源管理"
				logs.Save(admin_info, c.Controller, desc)
			}

			//*****************************************

			c.Flash.Success("添加来源成功!")
			c.Flash.Out["url"] = "/Copyfrom/"
			return c.Redirect("/Message/")
		} else {
			c.Flash.Error("添加来源失败")
			c.Flash.Out["url"] = "/Copyfrom/Add/"
			return c.Redirect("/Message/")
		}

	}
}
示例#21
0
//内容发布标题缩略图
func (c *Kindeditor) TitleImage(upload *models.Upload) revel.Result {
	data := make(map[string]interface{})

	//判断是否是系统的分隔符
	separator := "/"
	if os.IsPathSeparator('\\') {
		separator = "\\"
	} else {
		separator = "/"
	}

	//接收上传文件
	imgFile, header, err := c.Request.FormFile("imgFile")
	if err != nil {
		data["error"] = 1
		data["message"] = err.Error()

		return c.RenderJson(data)
	}
	defer imgFile.Close()

	//读取文件数据
	fileData, _ := ioutil.ReadAll(imgFile)

	if len(fileData) >= 1024*1024*2 {
		data["error"] = 1
		data["message"] = "你上传大小为" + utils.FileSize(len(fileData)) + ",文件应小于2M!"

		return c.RenderJson(data)
	}

	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")
	//允许上传的后缀名
	titlesuffix, _ := config_conf.String("upload", "upload.titlesuffix")

	//前台网站地址
	sitedomain, _ := config_conf.String("website", "website.sitedomain")

	//文件类型检测
	if !strings.Contains(titlesuffix, path.Ext(header.Filename)) {
		data["error"] = 1
		data["message"] = "文件只支持Office文件,图片和rar存档!"

		return c.RenderJson(data)
	}

	//前台网站调用目录
	web_save_path := fmt.Sprintf("/%s/article/%s", upload_dir, time.Now().Format("2006/01/02/"))

	//文件保存目录
	save_path := fmt.Sprintf("%s/www/%s/article/%s", basepath, upload_dir, time.Now().Format("2006/01/02/"))
	//字符串替换 /替换为系统分隔符
	save_path = strings.Replace(save_path, "/", separator, -1)

	//创建目录
	err = os.MkdirAll(save_path, os.ModePerm)
	if err != nil {
		revel.WARN.Println(err)
		data["error"] = 1
		data["message"] = "创建目录失败!"

		return c.RenderJson(data)
	}

	//新文件名
	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)

	//保存文件
	old_img := save_path + new_file_name

	err = ioutil.WriteFile(old_img, fileData, os.ModePerm)
	if err != nil {
		revel.WARN.Println(err)

		data["error"] = 1
		data["message"] = "保存图片失败!"
		return c.RenderJson(data)
	}

	//*******************图片处理****************

	//缩略图400
	thumb_name := time.Now().Format("20060102150404") + strconv.Itoa(rand_num) + "_100" + path.Ext(header.Filename)

	//内容显示图片
	web_url := web_save_path + thumb_name

	//400宽度图片生成
	thumb_135 := save_path + thumb_name
	utils.Resize(old_img, thumb_135, "100x70", "center", "white")

	//*******************图片处理****************

	data["error"] = 0
	data["url"] = sitedomain + web_url

	return c.RenderJson(data)
}
示例#22
0
文件: focus.go 项目: zacklin923/GoCMS
//添加焦点图
func (c Focus) Add(focus *models.Focus) revel.Result {

	if c.Request.Method == "GET" {

		title := "添加焦点图--GoCMS管理系统"

		FocusCate := new(models.FocusCate)
		Cate_list := FocusCate.GetCateList()

		c.Render(title, Cate_list)
		return c.RenderTemplate("Content/Focus/Add.html")

	} else {

		var cid string = c.Params.Get("cid")
		if len(cid) > 0 {

			Cid, err := strconv.ParseInt(cid, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			focus.Cid = Cid

			focusCate := new(models.FocusCate)
			focusCate_info := focusCate.GetById(Cid)

			if focusCate_info.Id <= 0 {
				c.Flash.Error("焦点图分类错误!")
				c.Flash.Out["url"] = "/Focus/Add/"
				return c.Redirect("/Message/")
			}

			//****************************************
			//图片

			//判断是否是系统的分隔符
			separator := "/"
			if os.IsPathSeparator('\\') {
				separator = "\\"
			} else {
				separator = "/"
			}

			//接收上传文件
			imgFile, header, err := c.Request.FormFile("img")
			if err != nil {
				c.Flash.Error("图片上传错误!")
				c.Flash.Out["url"] = "/Focus/Add/"
				return c.Redirect("/Message/")
			}
			defer imgFile.Close()

			//读取文件数据
			fileData, _ := ioutil.ReadAll(imgFile)

			if len(fileData) >= 1024*1024*2 {
				c.Flash.Error("你上传大小为" + utils.FileSize(len(fileData)) + ",文件应小于2M!")
				c.Flash.Out["url"] = "/Focus/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")
			//允许上传的后缀名
			titlesuffix, _ := config_conf.String("upload", "upload.titlesuffix")

			//文件类型检测
			if !strings.Contains(titlesuffix, path.Ext(header.Filename)) {
				c.Flash.Error("文件只支持图片!")
				c.Flash.Out["url"] = "/Focus/Add/"
				return c.Redirect("/Message/")
			}

			//前台网站调用目录
			web_save_path := fmt.Sprintf("/%s/focus/%s", upload_dir, time.Now().Format("2006/01/02/"))

			//文件保存目录
			save_path := fmt.Sprintf("%s/www/%s/focus/%s", basepath, upload_dir, time.Now().Format("2006/01/02/"))
			//字符串替换 /替换为系统分隔符
			save_path = strings.Replace(save_path, "/", separator, -1)

			//创建目录
			err = os.MkdirAll(save_path, os.ModePerm)
			if err != nil {
				c.Flash.Error("创建目录失败!")
				c.Flash.Out["url"] = "/Focus/Add/"
				return c.Redirect("/Message/")
			}

			//新文件名
			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)

			//保存文件
			old_img := save_path + new_file_name

			err = ioutil.WriteFile(old_img, fileData, os.ModePerm)
			if err != nil {
				revel.WARN.Println(err)
				c.Flash.Error("保存图片失败!")
				c.Flash.Out["url"] = "/Focus/Add/"
				return c.Redirect("/Message/")
			}

			thumb_name := time.Now().Format("20060102150404") + strconv.Itoa(rand_num) + "_thumb" + path.Ext(header.Filename)

			//内容显示图片
			web_url_img := web_save_path + thumb_name

			//400宽度图片生成
			thumb := save_path + thumb_name
			thumb_width := strconv.Itoa(int(focusCate_info.Width)) + "x" + strconv.Itoa(int(focusCate_info.Height))
			utils.Resize(old_img, thumb, thumb_width, "center", "white")

			focus.Img = web_url_img

			//***************************************

		} else {
			c.Flash.Error("请选择所属分类!")
			c.Flash.Out["url"] = "/Focus/Add/"
			return c.Redirect("/Message/")
		}

		UserID := utils.GetSession("UserID", c.Session)

		if len(UserID) > 0 {
			UserID, err := strconv.ParseInt(UserID, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}
			focus.Aid = UserID
		}

		var title string = c.Params.Get("title")
		if len(title) > 0 {
			focus.Title = title
		} else {
			c.Flash.Error("请输入标题!")
			c.Flash.Out["url"] = "/Focus/Add/"
			return c.Redirect("/Message/")
		}

		var url string = c.Params.Get("url")
		if len(url) > 0 {
			focus.Url = url
		} else {
			c.Flash.Error("请输入地址!")
			c.Flash.Out["url"] = "/Focus/Add/"
			return c.Redirect("/Message/")
		}

		var content string = c.Params.Get("content")
		if len(content) > 0 {
			focus.Content = content
		} else {
			c.Flash.Error("请输入摘要!")
			c.Flash.Out["url"] = "/Focus/Add/"
			return c.Redirect("/Message/")
		}

		var order string = c.Params.Get("order")
		if len(order) > 0 {

			Order, err := strconv.ParseInt(order, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			focus.Order = Order
		} else {
			focus.Order = 0
		}

		var status string = c.Params.Get("status")
		Status, err := strconv.ParseInt(status, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}

		focus.Status = Status

		if focus.Save() {
			c.Flash.Success("添加焦点图成功")
			c.Flash.Out["url"] = "/Focus/"
			return c.Redirect("/Message/")
		} else {
			c.Flash.Error("添加焦点图失败")
			c.Flash.Out["url"] = "/Focus/Add/"
			return c.Redirect("/Message/")
		}
	}
}