Ready to refix the volume things.
This commit is contained in:
10
Dockerfile
10
Dockerfile
@ -1,4 +1,4 @@
|
||||
# 使用1.8的golang作为母镜像
|
||||
# 使用1.9的golang作为母镜像
|
||||
FROM golang:1.9
|
||||
|
||||
# 维护者信息
|
||||
@ -10,7 +10,13 @@ WORKDIR $GOPATH/src/tank
|
||||
# 将tank项目下的所有文件移动到golang镜像中去
|
||||
COPY . $GOPATH/src/tank
|
||||
|
||||
# 开始编译
|
||||
# 日志和上传文件的目录
|
||||
VOLUME /data/log
|
||||
VOLUME /data/matter
|
||||
ENV TANK_LOG_PATH=/data/log TANK_MATTER_PATH=/data/matter
|
||||
|
||||
|
||||
# 开始下载依赖库并且进行编译
|
||||
RUN git clone https://github.com/eyebluecn/golang.org.git $GOPATH/src/golang.org \
|
||||
&& go get github.com/disintegration/imaging \
|
||||
&& go get github.com/json-iterator/go \
|
||||
|
@ -1,6 +1,8 @@
|
||||
{
|
||||
"ServerPort": 6010,
|
||||
"LogToConsole": false,
|
||||
"LogPath": "",
|
||||
"MatterPath": "",
|
||||
"MysqlPort": 3306,
|
||||
"MysqlHost": "127.0.0.1",
|
||||
"MysqlSchema": "tank",
|
||||
|
@ -345,7 +345,7 @@ func (this *AlienController) Download(writer http.ResponseWriter, request *http.
|
||||
}
|
||||
}
|
||||
|
||||
diskFile, err := os.Open(GetFilePath() + matter.Path)
|
||||
diskFile, err := os.Open(CONFIG.MatterPath + matter.Path)
|
||||
this.PanicError(err)
|
||||
defer diskFile.Close()
|
||||
// 防止中文乱码
|
||||
|
@ -41,6 +41,10 @@ var (
|
||||
ServerPort: 6010,
|
||||
//将日志输出到控制台。
|
||||
LogToConsole: true,
|
||||
//日志的保存路径,如果没有指定,默认在根目录下的log文件夹中
|
||||
LogPath: "",
|
||||
//上传的文件路径,如果没有指定,默认在根目录下的matter文件夹中
|
||||
MatterPath: "",
|
||||
//mysql相关配置。
|
||||
//数据库端口
|
||||
MysqlPort: 3306,
|
||||
@ -71,6 +75,11 @@ type Config struct {
|
||||
//将日志输出到控制台。
|
||||
LogToConsole bool
|
||||
|
||||
//日志的保存路径,要求不以/结尾。如果没有指定,默认在根目录下的log文件夹中。eg: /var/log/tank
|
||||
LogPath string
|
||||
//上传的文件路径,要求不以/结尾。如果没有指定,默认在根目录下的matter文件夹中。eg: /var/www/matter
|
||||
MatterPath string
|
||||
|
||||
//mysql相关配置。
|
||||
//数据库端口
|
||||
MysqlPort int
|
||||
@ -175,6 +184,16 @@ func LoadConfigFromEnvironment() {
|
||||
}
|
||||
}
|
||||
|
||||
tmpLogPath := os.Getenv("TANK_LOG_PATH")
|
||||
if tmpLogPath != "" {
|
||||
CONFIG.LogPath = tmpLogPath
|
||||
}
|
||||
|
||||
tmpMatterPath := os.Getenv("TANK_MATTER_PATH")
|
||||
if tmpMatterPath != "" {
|
||||
CONFIG.MatterPath = tmpMatterPath
|
||||
}
|
||||
|
||||
tmpMysqlPort := os.Getenv("TANK_MYSQL_PORT")
|
||||
if tmpMysqlPort != "" {
|
||||
i, e := strconv.Atoi(tmpMysqlPort)
|
||||
@ -226,6 +245,10 @@ func LoadConfigFromArguments() {
|
||||
//系统端口号
|
||||
LogToConsolePtr := flag.Bool("LogToConsole", CONFIG.LogToConsole, "write log to console. for debug.")
|
||||
|
||||
//日志和上传文件的路径
|
||||
LogPathPtr := flag.String("LogPath", CONFIG.LogPath, "log path")
|
||||
MatterPathPtr := flag.String("MatterPath", CONFIG.MatterPath, "matter path")
|
||||
|
||||
//mysql相关配置。
|
||||
MysqlPortPtr := flag.Int("MysqlPort", CONFIG.MysqlPort, "mysql port")
|
||||
MysqlHostPtr := flag.String("MysqlHost", CONFIG.MysqlHost, "mysql host")
|
||||
@ -249,6 +272,14 @@ func LoadConfigFromArguments() {
|
||||
CONFIG.LogToConsole = *LogToConsolePtr
|
||||
}
|
||||
|
||||
if *LogPathPtr != CONFIG.LogPath {
|
||||
CONFIG.LogPath = *LogPathPtr
|
||||
}
|
||||
|
||||
if *MatterPathPtr != CONFIG.MatterPath {
|
||||
CONFIG.MatterPath = *MatterPathPtr
|
||||
}
|
||||
|
||||
if *MysqlPortPtr != CONFIG.MysqlPort {
|
||||
CONFIG.MysqlPort = *MysqlPortPtr
|
||||
}
|
||||
@ -295,6 +326,16 @@ func PrepareConfigs() {
|
||||
//第三级. 从程序参数中读取配置项
|
||||
LoadConfigFromArguments()
|
||||
|
||||
//对于日志路径和文件路径还需要进行特殊处理
|
||||
if CONFIG.LogPath == "" {
|
||||
CONFIG.LogPath = GetHomePath() + "/log"
|
||||
}
|
||||
MakeDirAll(CONFIG.LogPath)
|
||||
if CONFIG.MatterPath == "" {
|
||||
CONFIG.MatterPath = GetHomePath() + "/matter"
|
||||
}
|
||||
MakeDirAll(CONFIG.MatterPath)
|
||||
|
||||
//验证配置项的正确性
|
||||
CONFIG.validate()
|
||||
|
||||
|
@ -226,7 +226,7 @@ func (this *MatterDao) Delete(matter *Matter) {
|
||||
this.PanicError(db.Error)
|
||||
|
||||
//删除文件
|
||||
err := os.Remove(GetFilePath() + matter.Path)
|
||||
err := os.Remove(CONFIG.MatterPath + matter.Path)
|
||||
|
||||
LogError(fmt.Sprintf("删除磁盘上的文件出错,不做任何处理"))
|
||||
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
func Log(prefix string, content string) {
|
||||
|
||||
//日志输出到文件中
|
||||
filePath := GetLogPath() + "/tank-" + time.Now().Local().Format("2006-01-02") + ".log"
|
||||
filePath := CONFIG.LogPath + "/tank-" + time.Now().Local().Format("2006-01-02") + ".log"
|
||||
f, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
fmt.Errorf("error opening file: %v", err)
|
||||
|
@ -50,45 +50,23 @@ func GetHtmlPath() string {
|
||||
return filePath
|
||||
}
|
||||
|
||||
//获取上传文件存放的位置。
|
||||
//例如:C:\Users\lishuang\AppData\Local\Temp/matter
|
||||
func GetFilePath() string {
|
||||
//如果文件夹存在就不管,不存在就创建。 例如:/var/www/matter
|
||||
func MakeDirAll(dirPath string) string {
|
||||
|
||||
homePath := GetHomePath()
|
||||
filePath := homePath + "/matter"
|
||||
exists, err := PathExists(filePath)
|
||||
exists, err := PathExists(dirPath)
|
||||
if err != nil {
|
||||
panic("判断上传文件是否存在时出错!")
|
||||
panic("判断文件是否存在时出错!")
|
||||
}
|
||||
if !exists {
|
||||
err = os.MkdirAll(filePath, 0777)
|
||||
err = os.MkdirAll(dirPath, 0666)
|
||||
if err != nil {
|
||||
panic("创建上传文件夹时出错!")
|
||||
panic("创建文件夹时出错!")
|
||||
}
|
||||
}
|
||||
|
||||
return filePath
|
||||
return dirPath
|
||||
}
|
||||
|
||||
//获取日志存放的位置。
|
||||
//例如:C:\Users\lishuang\AppData\Local\Temp/log
|
||||
func GetLogPath() string {
|
||||
|
||||
homePath := GetHomePath()
|
||||
filePath := homePath + "/log"
|
||||
exists, err := PathExists(filePath)
|
||||
if err != nil {
|
||||
panic("判断日志文件夹是否存在时出错!")
|
||||
}
|
||||
if !exists {
|
||||
err = os.MkdirAll(filePath, 0666)
|
||||
if err != nil {
|
||||
panic("创建日志文件夹时出错!")
|
||||
}
|
||||
}
|
||||
|
||||
return filePath
|
||||
}
|
||||
|
||||
//获取配置文件存放的位置
|
||||
//例如:C:\Users\lishuang\AppData\Local\Temp/conf
|
||||
@ -119,7 +97,7 @@ func GetUserFilePath(username string) (string, string) {
|
||||
//毫秒时间戳
|
||||
timestamp := now.UnixNano() / 1e6
|
||||
|
||||
filePath := GetFilePath()
|
||||
filePath := CONFIG.MatterPath
|
||||
absolutePath := fmt.Sprintf("%s/%s/%s/%d", filePath, username, datePath, timestamp)
|
||||
relativePath := fmt.Sprintf("/%s/%s/%d", username, datePath, timestamp)
|
||||
|
||||
|
Reference in New Issue
Block a user