2017-04-21 18:20:35 +08:00
|
|
|
|
// package conf 为配置相关.
|
|
|
|
|
package conf
|
|
|
|
|
|
2017-04-27 18:19:37 +08:00
|
|
|
|
import (
|
|
|
|
|
"strings"
|
2017-05-11 13:39:34 +08:00
|
|
|
|
|
2018-08-15 15:33:22 +08:00
|
|
|
|
"fmt"
|
2021-03-17 15:59:05 +08:00
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
|
|
"github.com/astaxie/beego"
|
2017-04-27 18:19:37 +08:00
|
|
|
|
)
|
2017-04-21 18:20:35 +08:00
|
|
|
|
|
|
|
|
|
// 登录用户的Session名
|
|
|
|
|
const LoginSessionName = "LoginSessionName"
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
const CaptchaSessionName = "__captcha__"
|
2017-05-01 12:15:55 +08:00
|
|
|
|
|
2018-01-18 19:54:05 +08:00
|
|
|
|
const RegexpEmail = "^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
|
2017-04-23 12:48:46 +08:00
|
|
|
|
|
2017-06-13 18:02:50 +08:00
|
|
|
|
//允许用户名中出现点号
|
2021-03-25 10:04:15 +08:00
|
|
|
|
const RegexpAccount = `^[a-zA-Z][a-zA-Z0-9\.-]{2,50}$`
|
2017-04-23 12:48:46 +08:00
|
|
|
|
|
2017-04-24 18:25:17 +08:00
|
|
|
|
// PageSize 默认分页条数.
|
2018-01-26 17:17:38 +08:00
|
|
|
|
const PageSize = 10
|
2017-04-24 18:25:17 +08:00
|
|
|
|
|
|
|
|
|
// 用户权限
|
|
|
|
|
const (
|
|
|
|
|
// 超级管理员.
|
2018-11-05 18:50:01 +08:00
|
|
|
|
MemberSuperRole SystemRole = iota
|
2017-04-24 18:25:17 +08:00
|
|
|
|
//普通管理员.
|
2018-11-05 18:50:01 +08:00
|
|
|
|
MemberAdminRole
|
2017-04-24 18:25:17 +08:00
|
|
|
|
//普通用户.
|
2018-11-05 18:50:01 +08:00
|
|
|
|
MemberGeneralRole
|
2017-04-24 18:25:17 +08:00
|
|
|
|
)
|
|
|
|
|
|
2018-11-05 18:50:01 +08:00
|
|
|
|
//系统角色
|
|
|
|
|
type SystemRole int
|
|
|
|
|
|
2017-04-24 18:25:17 +08:00
|
|
|
|
const (
|
|
|
|
|
// 创始人.
|
2018-11-05 18:50:01 +08:00
|
|
|
|
BookFounder BookRole = iota
|
2017-04-24 18:25:17 +08:00
|
|
|
|
//管理者
|
2018-11-05 18:50:01 +08:00
|
|
|
|
BookAdmin
|
2017-04-24 18:25:17 +08:00
|
|
|
|
//编辑者.
|
2018-11-05 18:50:01 +08:00
|
|
|
|
BookEditor
|
2017-04-24 18:25:17 +08:00
|
|
|
|
//观察者
|
2018-11-05 18:50:01 +08:00
|
|
|
|
BookObserver
|
2017-04-24 18:25:17 +08:00
|
|
|
|
)
|
|
|
|
|
|
2018-11-05 18:50:01 +08:00
|
|
|
|
//项目角色
|
|
|
|
|
type BookRole int
|
|
|
|
|
|
2017-06-09 18:14:55 +08:00
|
|
|
|
const (
|
2018-01-26 17:17:38 +08:00
|
|
|
|
LoggerOperate = "operate"
|
|
|
|
|
LoggerSystem = "system"
|
2017-06-09 18:14:55 +08:00
|
|
|
|
LoggerException = "exception"
|
2018-01-26 17:17:38 +08:00
|
|
|
|
LoggerDocument = "document"
|
2017-06-09 18:14:55 +08:00
|
|
|
|
)
|
2017-05-26 14:19:27 +08:00
|
|
|
|
const (
|
|
|
|
|
//本地账户校验
|
|
|
|
|
AuthMethodLocal = "local"
|
|
|
|
|
//LDAP用户校验
|
2018-01-26 17:17:38 +08:00
|
|
|
|
AuthMethodLDAP = "ldap"
|
2017-05-26 14:19:27 +08:00
|
|
|
|
)
|
2018-01-26 17:17:38 +08:00
|
|
|
|
|
2017-05-05 15:04:31 +08:00
|
|
|
|
var (
|
2017-05-11 13:39:34 +08:00
|
|
|
|
VERSION string
|
|
|
|
|
BUILD_TIME string
|
|
|
|
|
GO_VERSION string
|
2017-05-05 15:04:31 +08:00
|
|
|
|
)
|
|
|
|
|
|
2018-01-26 17:17:38 +08:00
|
|
|
|
var (
|
|
|
|
|
ConfigurationFile = "./conf/app.conf"
|
|
|
|
|
WorkingDirectory = "./"
|
2018-07-11 11:30:48 +08:00
|
|
|
|
LogFile = "./runtime/logs"
|
2018-11-05 18:50:01 +08:00
|
|
|
|
BaseUrl = ""
|
|
|
|
|
AutoLoadDelay = 0
|
2018-01-26 17:17:38 +08:00
|
|
|
|
)
|
|
|
|
|
|
2017-04-21 18:20:35 +08:00
|
|
|
|
// app_key
|
2017-05-11 13:39:34 +08:00
|
|
|
|
func GetAppKey() string {
|
2018-08-24 15:05:15 +08:00
|
|
|
|
return beego.AppConfig.DefaultString("app_key", "mindoc")
|
2017-04-21 18:20:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
func GetDatabasePrefix() string {
|
|
|
|
|
return beego.AppConfig.DefaultString("db_prefix", "md_")
|
2017-04-23 12:48:46 +08:00
|
|
|
|
}
|
2017-05-05 15:04:31 +08:00
|
|
|
|
|
2017-04-23 12:48:46 +08:00
|
|
|
|
//获取默认头像
|
|
|
|
|
func GetDefaultAvatar() string {
|
2018-03-25 19:33:37 +08:00
|
|
|
|
return URLForWithCdnImage(beego.AppConfig.DefaultString("avatar", "/static/images/headimgurl.jpg"))
|
2017-04-25 20:05:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-03 14:22:05 +08:00
|
|
|
|
//获取阅读令牌长度.
|
2017-04-25 20:05:59 +08:00
|
|
|
|
func GetTokenSize() int {
|
2017-05-11 13:39:34 +08:00
|
|
|
|
return beego.AppConfig.DefaultInt("token_size", 12)
|
2017-04-25 20:05:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-03 14:22:05 +08:00
|
|
|
|
//获取默认文档封面.
|
2017-04-25 20:05:59 +08:00
|
|
|
|
func GetDefaultCover() string {
|
2018-07-11 11:30:48 +08:00
|
|
|
|
|
2018-03-25 19:33:37 +08:00
|
|
|
|
return URLForWithCdnImage(beego.AppConfig.DefaultString("cover", "/static/images/book.jpg"))
|
2017-04-27 18:19:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-03 14:22:05 +08:00
|
|
|
|
//获取允许的商城文件的类型.
|
2017-05-11 13:39:34 +08:00
|
|
|
|
func GetUploadFileExt() []string {
|
|
|
|
|
ext := beego.AppConfig.DefaultString("upload_file_ext", "png|jpg|jpeg|gif|txt|doc|docx|pdf")
|
|
|
|
|
|
|
|
|
|
temp := strings.Split(ext, "|")
|
|
|
|
|
|
|
|
|
|
exts := make([]string, len(temp))
|
|
|
|
|
|
2017-04-27 18:19:37 +08:00
|
|
|
|
i := 0
|
2017-05-11 13:39:34 +08:00
|
|
|
|
for _, item := range temp {
|
2017-04-27 18:19:37 +08:00
|
|
|
|
if item != "" {
|
|
|
|
|
exts[i] = item
|
|
|
|
|
i++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return exts
|
|
|
|
|
}
|
2018-01-26 17:17:38 +08:00
|
|
|
|
|
2018-01-18 19:54:05 +08:00
|
|
|
|
// 获取上传文件允许的最大值
|
|
|
|
|
func GetUploadFileSize() int64 {
|
2018-01-26 17:17:38 +08:00
|
|
|
|
size := beego.AppConfig.DefaultString("upload_file_size", "0")
|
2018-01-18 19:54:05 +08:00
|
|
|
|
|
2018-01-26 17:17:38 +08:00
|
|
|
|
if strings.HasSuffix(size, "MB") {
|
|
|
|
|
if s, e := strconv.ParseInt(size[0:len(size)-2], 10, 64); e == nil {
|
2018-01-18 19:54:05 +08:00
|
|
|
|
return s * 1024 * 1024
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-26 17:17:38 +08:00
|
|
|
|
if strings.HasSuffix(size, "GB") {
|
|
|
|
|
if s, e := strconv.ParseInt(size[0:len(size)-2], 10, 64); e == nil {
|
2018-01-18 19:54:05 +08:00
|
|
|
|
return s * 1024 * 1024 * 1024
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-26 17:17:38 +08:00
|
|
|
|
if strings.HasSuffix(size, "KB") {
|
|
|
|
|
if s, e := strconv.ParseInt(size[0:len(size)-2], 10, 64); e == nil {
|
2018-01-18 19:54:05 +08:00
|
|
|
|
return s * 1024
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-26 17:17:38 +08:00
|
|
|
|
if s, e := strconv.ParseInt(size, 10, 64); e == nil {
|
2018-01-18 19:54:05 +08:00
|
|
|
|
return s * 1024
|
|
|
|
|
}
|
2018-01-26 17:17:38 +08:00
|
|
|
|
return 0
|
2018-01-18 19:54:05 +08:00
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
|
2018-07-12 18:44:02 +08:00
|
|
|
|
//是否启用导出
|
|
|
|
|
func GetEnableExport() bool {
|
2018-11-05 18:50:01 +08:00
|
|
|
|
return beego.AppConfig.DefaultBool("enable_export", true)
|
2018-07-12 18:44:02 +08:00
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
|
2018-07-10 16:26:25 +08:00
|
|
|
|
//同一项目导出线程的并发数
|
|
|
|
|
func GetExportProcessNum() int {
|
2018-11-05 18:50:01 +08:00
|
|
|
|
exportProcessNum := beego.AppConfig.DefaultInt("export_process_num", 1)
|
2018-07-10 16:26:25 +08:00
|
|
|
|
|
|
|
|
|
if exportProcessNum <= 0 || exportProcessNum > 4 {
|
|
|
|
|
exportProcessNum = 1
|
|
|
|
|
}
|
2021-03-17 15:59:05 +08:00
|
|
|
|
return exportProcessNum
|
2018-07-10 16:26:25 +08:00
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
|
2018-07-10 16:26:25 +08:00
|
|
|
|
//导出项目队列的并发数量
|
|
|
|
|
func GetExportLimitNum() int {
|
2018-11-05 18:50:01 +08:00
|
|
|
|
exportLimitNum := beego.AppConfig.DefaultInt("export_limit_num", 1)
|
2018-07-10 16:26:25 +08:00
|
|
|
|
|
|
|
|
|
if exportLimitNum < 0 {
|
|
|
|
|
exportLimitNum = 1
|
|
|
|
|
}
|
2021-03-17 15:59:05 +08:00
|
|
|
|
return exportLimitNum
|
2018-07-10 16:26:25 +08:00
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
|
2018-07-10 16:26:25 +08:00
|
|
|
|
//等待导出队列的长度
|
|
|
|
|
func GetExportQueueLimitNum() int {
|
2018-11-05 18:50:01 +08:00
|
|
|
|
exportQueueLimitNum := beego.AppConfig.DefaultInt("export_queue_limit_num", 10)
|
2018-07-10 16:26:25 +08:00
|
|
|
|
|
|
|
|
|
if exportQueueLimitNum <= 0 {
|
|
|
|
|
exportQueueLimitNum = 100
|
|
|
|
|
}
|
|
|
|
|
return exportQueueLimitNum
|
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
|
2018-07-11 11:30:48 +08:00
|
|
|
|
//默认导出项目的缓存目录
|
|
|
|
|
func GetExportOutputPath() string {
|
2018-11-05 18:50:01 +08:00
|
|
|
|
exportOutputPath := filepath.Join(beego.AppConfig.DefaultString("export_output_path", filepath.Join(WorkingDirectory, "cache")), "books")
|
2018-07-11 11:30:48 +08:00
|
|
|
|
|
|
|
|
|
return exportOutputPath
|
|
|
|
|
}
|
2017-05-05 15:04:31 +08:00
|
|
|
|
|
2017-05-03 14:22:05 +08:00
|
|
|
|
//判断是否是允许商城的文件类型.
|
2017-05-11 13:39:34 +08:00
|
|
|
|
func IsAllowUploadFileExt(ext string) bool {
|
2017-04-27 18:19:37 +08:00
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if strings.HasPrefix(ext, ".") {
|
2017-04-27 18:19:37 +08:00
|
|
|
|
ext = string(ext[1:])
|
|
|
|
|
}
|
|
|
|
|
exts := GetUploadFileExt()
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
for _, item := range exts {
|
2018-09-11 15:57:03 +08:00
|
|
|
|
if item == "*" {
|
2018-11-05 18:50:01 +08:00
|
|
|
|
return true
|
2018-09-11 15:57:03 +08:00
|
|
|
|
}
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if strings.EqualFold(item, ext) {
|
|
|
|
|
return true
|
2017-04-27 18:19:37 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
2017-05-03 14:22:05 +08:00
|
|
|
|
}
|
2018-03-13 19:20:50 +08:00
|
|
|
|
|
|
|
|
|
//重写生成URL的方法,加上完整的域名
|
|
|
|
|
func URLFor(endpoint string, values ...interface{}) string {
|
2018-11-05 18:50:01 +08:00
|
|
|
|
baseUrl := beego.AppConfig.DefaultString("baseurl", "")
|
2021-03-17 15:59:05 +08:00
|
|
|
|
pathUrl := beego.URLFor(endpoint, values...)
|
2018-03-13 19:20:50 +08:00
|
|
|
|
|
2018-11-15 19:54:25 +08:00
|
|
|
|
if baseUrl == "" {
|
|
|
|
|
baseUrl = BaseUrl
|
|
|
|
|
}
|
|
|
|
|
if strings.HasPrefix(pathUrl, "http://") {
|
|
|
|
|
return pathUrl
|
|
|
|
|
}
|
|
|
|
|
if strings.HasPrefix(pathUrl, "/") && strings.HasSuffix(baseUrl, "/") {
|
|
|
|
|
return baseUrl + pathUrl[1:]
|
|
|
|
|
}
|
|
|
|
|
if !strings.HasPrefix(pathUrl, "/") && !strings.HasSuffix(baseUrl, "/") {
|
|
|
|
|
return baseUrl + "/" + pathUrl
|
|
|
|
|
}
|
2021-03-17 15:59:05 +08:00
|
|
|
|
return baseUrl + beego.URLFor(endpoint, values...)
|
2018-11-15 19:54:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 15:59:05 +08:00
|
|
|
|
func URLForNotHost(endpoint string, values ...interface{}) string {
|
2018-11-15 19:54:25 +08:00
|
|
|
|
baseUrl := beego.AppConfig.DefaultString("baseurl", "")
|
2021-03-17 15:59:05 +08:00
|
|
|
|
pathUrl := beego.URLFor(endpoint, values...)
|
2018-11-15 19:54:25 +08:00
|
|
|
|
|
2018-03-13 19:20:50 +08:00
|
|
|
|
if baseUrl == "" {
|
2018-11-14 19:03:27 +08:00
|
|
|
|
baseUrl = "/"
|
2018-03-13 19:20:50 +08:00
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
if strings.HasPrefix(pathUrl, "http://") {
|
2018-03-13 19:20:50 +08:00
|
|
|
|
return pathUrl
|
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
if strings.HasPrefix(pathUrl, "/") && strings.HasSuffix(baseUrl, "/") {
|
2018-03-13 19:20:50 +08:00
|
|
|
|
return baseUrl + pathUrl[1:]
|
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
if !strings.HasPrefix(pathUrl, "/") && !strings.HasSuffix(baseUrl, "/") {
|
2018-03-13 19:20:50 +08:00
|
|
|
|
return baseUrl + "/" + pathUrl
|
|
|
|
|
}
|
2021-03-17 15:59:05 +08:00
|
|
|
|
return baseUrl + beego.URLFor(endpoint, values...)
|
2018-03-13 19:20:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-05 18:50:01 +08:00
|
|
|
|
func URLForWithCdnImage(p string) string {
|
2018-03-13 19:20:50 +08:00
|
|
|
|
if strings.HasPrefix(p, "http://") || strings.HasPrefix(p, "https://") {
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
cdn := beego.AppConfig.DefaultString("cdnimg", "")
|
|
|
|
|
//如果没有设置cdn,则使用baseURL拼接
|
|
|
|
|
if cdn == "" {
|
2018-11-14 12:02:52 +08:00
|
|
|
|
baseUrl := beego.AppConfig.DefaultString("baseurl", "/")
|
|
|
|
|
|
2018-11-05 18:50:01 +08:00
|
|
|
|
if strings.HasPrefix(p, "/") && strings.HasSuffix(baseUrl, "/") {
|
2018-03-13 19:20:50 +08:00
|
|
|
|
return baseUrl + p[1:]
|
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
if !strings.HasPrefix(p, "/") && !strings.HasSuffix(baseUrl, "/") {
|
2018-03-13 19:20:50 +08:00
|
|
|
|
return baseUrl + "/" + p
|
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
return baseUrl + p
|
2018-03-13 19:20:50 +08:00
|
|
|
|
}
|
|
|
|
|
if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") {
|
|
|
|
|
return cdn + string(p[1:])
|
|
|
|
|
}
|
|
|
|
|
if !strings.HasPrefix(p, "/") && !strings.HasSuffix(cdn, "/") {
|
|
|
|
|
return cdn + "/" + p
|
|
|
|
|
}
|
|
|
|
|
return cdn + p
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-05 18:50:01 +08:00
|
|
|
|
func URLForWithCdnCss(p string, v ...string) string {
|
2018-03-13 19:20:50 +08:00
|
|
|
|
cdn := beego.AppConfig.DefaultString("cdncss", "")
|
|
|
|
|
if strings.HasPrefix(p, "http://") || strings.HasPrefix(p, "https://") {
|
|
|
|
|
return p
|
|
|
|
|
}
|
2018-08-15 15:33:22 +08:00
|
|
|
|
filePath := WorkingDir(p)
|
|
|
|
|
|
2018-11-05 18:50:01 +08:00
|
|
|
|
if f, err := os.Stat(filePath); err == nil && !strings.Contains(p, "?") && len(v) > 0 && v[0] == "version" {
|
|
|
|
|
p = p + fmt.Sprintf("?v=%s", f.ModTime().Format("20060102150405"))
|
2018-08-15 15:33:22 +08:00
|
|
|
|
}
|
2018-03-13 19:20:50 +08:00
|
|
|
|
//如果没有设置cdn,则使用baseURL拼接
|
|
|
|
|
if cdn == "" {
|
2018-11-14 12:02:52 +08:00
|
|
|
|
baseUrl := beego.AppConfig.DefaultString("baseurl", "/")
|
|
|
|
|
|
2018-11-05 18:50:01 +08:00
|
|
|
|
if strings.HasPrefix(p, "/") && strings.HasSuffix(baseUrl, "/") {
|
2018-03-13 19:20:50 +08:00
|
|
|
|
return baseUrl + p[1:]
|
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
if !strings.HasPrefix(p, "/") && !strings.HasSuffix(baseUrl, "/") {
|
2018-03-13 19:20:50 +08:00
|
|
|
|
return baseUrl + "/" + p
|
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
return baseUrl + p
|
2018-03-13 19:20:50 +08:00
|
|
|
|
}
|
|
|
|
|
if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") {
|
|
|
|
|
return cdn + string(p[1:])
|
|
|
|
|
}
|
|
|
|
|
if !strings.HasPrefix(p, "/") && !strings.HasSuffix(cdn, "/") {
|
|
|
|
|
return cdn + "/" + p
|
|
|
|
|
}
|
|
|
|
|
return cdn + p
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-05 18:50:01 +08:00
|
|
|
|
func URLForWithCdnJs(p string, v ...string) string {
|
2018-03-13 19:20:50 +08:00
|
|
|
|
cdn := beego.AppConfig.DefaultString("cdnjs", "")
|
|
|
|
|
if strings.HasPrefix(p, "http://") || strings.HasPrefix(p, "https://") {
|
|
|
|
|
return p
|
|
|
|
|
}
|
2018-08-15 15:33:22 +08:00
|
|
|
|
|
|
|
|
|
filePath := WorkingDir(p)
|
|
|
|
|
|
2018-11-05 18:50:01 +08:00
|
|
|
|
if f, err := os.Stat(filePath); err == nil && !strings.Contains(p, "?") && len(v) > 0 && v[0] == "version" {
|
|
|
|
|
p = p + fmt.Sprintf("?v=%s", f.ModTime().Format("20060102150405"))
|
2018-08-15 15:33:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-13 19:20:50 +08:00
|
|
|
|
//如果没有设置cdn,则使用baseURL拼接
|
|
|
|
|
if cdn == "" {
|
2018-11-14 12:02:52 +08:00
|
|
|
|
baseUrl := beego.AppConfig.DefaultString("baseurl", "/")
|
|
|
|
|
|
2018-11-05 18:50:01 +08:00
|
|
|
|
if strings.HasPrefix(p, "/") && strings.HasSuffix(baseUrl, "/") {
|
2018-03-13 19:20:50 +08:00
|
|
|
|
return baseUrl + p[1:]
|
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
if !strings.HasPrefix(p, "/") && !strings.HasSuffix(baseUrl, "/") {
|
2018-03-13 19:20:50 +08:00
|
|
|
|
return baseUrl + "/" + p
|
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
return baseUrl + p
|
2018-03-13 19:20:50 +08:00
|
|
|
|
}
|
|
|
|
|
if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") {
|
|
|
|
|
return cdn + string(p[1:])
|
|
|
|
|
}
|
|
|
|
|
if !strings.HasPrefix(p, "/") && !strings.HasSuffix(cdn, "/") {
|
|
|
|
|
return cdn + "/" + p
|
|
|
|
|
}
|
|
|
|
|
return cdn + p
|
2018-07-11 14:18:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func WorkingDir(elem ...string) string {
|
|
|
|
|
|
2018-11-05 18:50:01 +08:00
|
|
|
|
elems := append([]string{WorkingDirectory}, elem...)
|
2018-07-11 14:18:27 +08:00
|
|
|
|
|
|
|
|
|
return filepath.Join(elems...)
|
2018-08-24 15:05:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-05 18:50:01 +08:00
|
|
|
|
func init() {
|
|
|
|
|
if p, err := filepath.Abs("./conf/app.conf"); err == nil {
|
2018-08-24 15:05:15 +08:00
|
|
|
|
ConfigurationFile = p
|
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
if p, err := filepath.Abs("./"); err == nil {
|
2018-08-24 15:05:15 +08:00
|
|
|
|
WorkingDirectory = p
|
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
if p, err := filepath.Abs("./runtime/logs"); err == nil {
|
2018-08-24 15:05:15 +08:00
|
|
|
|
LogFile = p
|
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
}
|