update file
This commit is contained in:
13
pkg/db/db.go
13
pkg/db/db.go
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user