This commit is contained in:
C菌
2022-04-28 03:15:01 +08:00
parent c113e38d82
commit 94cd2ce218
28 changed files with 1059 additions and 14 deletions

View File

@@ -14,7 +14,9 @@ type Config struct {
}
type Server struct {
Addr string `yaml:"addr"`
Addr string `yaml:"addr"`
Domain string `yaml:"domain"`
Lru_Size int `yaml:"lru_size"`
}
type Log struct {
@@ -34,7 +36,7 @@ type Rotate struct {
}
type Data struct {
DB DB `yaml:"database"`
DB `yaml:"database"`
Redis `yaml:"redis"`
}

View File

@@ -12,10 +12,9 @@ var (
)
type TinyUrl struct {
ID int64
OriginUrl string
TinyUrl string
CreatTime time.Time
gorm.Model
LongUrl string `gorm:"size:200"`
ShortUrl string `gorm:"size:50"`
ExpireTime time.Time
Counter float64
}
@@ -26,7 +25,7 @@ type URLDetail struct {
ExpirationInMinutes time.Duration `json:"expiration_in_minutes"`
}
func initDB() {
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 err error
@@ -34,4 +33,7 @@ func initDB() {
if err != nil {
panic(err)
}
if err := DB.AutoMigrate(&TinyUrl{}); err != nil {
panic(err)
}
}