Commit 518215c7 authored by chenhan wang's avatar chenhan wang
Browse files

Merge remote-tracking branch 'origin/master1'

parents 6309d619 c479c99e
...@@ -10,10 +10,9 @@ import ( ...@@ -10,10 +10,9 @@ import (
) )
var DB *gorm.DB var DB *gorm.DB
var id1 uint = 0
func Init() {} func Init() {
func Init_() {
connectDatabase() connectDatabase()
var err error var err error
// insert auto-table // insert auto-table
...@@ -47,52 +46,43 @@ func connectDatabase() { ...@@ -47,52 +46,43 @@ func connectDatabase() {
} }
// Backcheck content through link // Backcheck content through link
func findlink(name string) string { //通过链接反查内容
var p Users func findlink(_Route string) content {
err := DB.First(&p, "Route = ?", name) var p content
err := DB.First(&p, "Route = ?", _Route)
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
return p.Name return p
} }
// save text information // save text information
func savetext(_username string, s string, t1 time.Time) { //保存文本和文件信息
p := Users{ func savetext(_Route string, _Time uint, _Passwd string,_Time1 time.Time) {
Username: _username, id1++
Name: s, p := content{
ID : id1,
Route: _Route,
Passwd: _Passwd,
Date: time.Now(), Date: time.Now(),
Time1: t1, Time1: _Time1,
Time2: 0,
} }
DB.Create(&p) DB.Create(&p)
p1 := content{
Name: s,
Time: 0,
}
DB.Create(&p1)
} }
// Check whether the number of visits exceeds the threshold // Check whether the number of visits exceeds the threshold and the time limit
func checkt(s string) { //检查是否超过总访问次数和截止时间
func checkt(_Route string) {
var p content var p content
err := DB.First(&p, "Route = ?", s) err := DB.First(&p, "Route = ?",_Route)
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
p.Time++
if p.Time > 200 {
DB.Delete(&p)
}
}
// Check whether the number of visits exceeds the time limit
func checkt1(s string) {
var p []Users
DB.Find(&p)
for i := 0; i < len(p); i++ {
t := time.Now() t := time.Now()
if p[i].Time1.After(t) { p.Time2++
if p.Time2 > p.Time||t.After(p.Time1) {
DB.Delete(&p) DB.Delete(&p)
} }
}
} }
\ No newline at end of file
...@@ -2,22 +2,23 @@ package model ...@@ -2,22 +2,23 @@ package model
import ( import (
"time" "time"
"gorm.io/gorm"
) )
type Users struct { type content struct {
gorm.Model ID uint `gorm:"primarykey"`
Username string Route string
Time uint
Passwd string Passwd string
Name string
Date time.Time Date time.Time
Size uint Size uint
Route string
Time1 time.Time Time1 time.Time
Time2 uint
} }
type content struct { type Users struct {
gorm.Model Username string
Passwd string
Name string Name string
Time uint Size uint
Route string
} }
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment