update file

This commit is contained in:
C菌
2022-04-28 20:40:16 +08:00
parent f810b7bc91
commit 93f354370a
13 changed files with 75 additions and 132 deletions

View File

@@ -1,6 +1,7 @@
package db
import (
"os"
"time"
"gorm.io/driver/mysql"
@@ -13,10 +14,11 @@ var (
type TinyUrl struct {
gorm.Model
LongUrl string `gorm:"size:200"`
ShortUrl string `gorm:"size:50"`
LongUrl string `gorm:"size:7713"`
ShortUrl string `gorm:"size:20"`
ExpireTime time.Time
Counter float64
AddIP string
}
type URLDetail struct {
@@ -27,7 +29,12 @@ type URLDetail struct {
func InitDb() {
// 参考 https://github.com/go-sql-driver/mysql#dsn-data-source-name 获取详情
dsn := "tinyurl:tinyurl@tcp(42.192.36.14:3306)/tinyurl?charset=utf8mb4&parseTime=True&loc=Local"
var dsn string
if len(os.Getenv("DSN")) > 1 {
dsn = os.Getenv("DSN")
} else {
dsn = "tinyurl:tinyurl@tcp(42.192.36.14:3306)/tinyurl?charset=utf8mb4&parseTime=True&loc=Local"
}
var err error
DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {

View File

@@ -85,11 +85,11 @@ func getConsoleEncoder() zapcore.Encoder {
func getFileWriter(c config.Rotate) zapcore.WriteSyncer {
logger := &lumberjack.Logger{
Filename: c.Filename,
MaxSize: c.MaxSize,
MaxAge: c.MaxAge,
MaxBackups: c.MaxBackups,
LocalTime: c.LocalTime,
Compress: c.Compress,
MaxSize: c.MaxSize, //Mb
MaxAge: c.MaxAge, //days
MaxBackups: c.MaxBackups, //int backup maximum number of old log files
LocalTime: c.LocalTime, //bool backup files is the computer's local time
Compress: c.Compress, //bool
}
return zapcore.AddSync(logger)
}