Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenhan wang
pastebin
Commits
596810c8
Commit
596810c8
authored
Jan 17, 2023
by
chenhan wang
Browse files
本地调试2,0
parent
df2a78f0
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
backend/model/init.go
View file @
596810c8
...
...
@@ -3,7 +3,7 @@ package model
import
(
//"fmt"
"time"
// "math/rand"
// "math/rand"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
...
...
@@ -26,7 +26,7 @@ func Init() {
if
err
!=
nil
{
logrus
.
Fatal
(
err
)
}
err
=
DB
.
AutoMigrate
(
&
Sid
{},
&
Url
{})
err
=
DB
.
AutoMigrate
(
&
Sid
{},
&
Url
{})
if
err
!=
nil
{
logrus
.
Fatal
(
err
)
}
...
...
@@ -52,7 +52,7 @@ func ConnectDatabase() {
}
// Backcheck content through link
//通过链接反查内容
//
通过链接反查内容
func
Findlink
(
_url
string
)
string
{
var
p
Content
err
:=
DB
.
First
(
&
p
,
"Url1 = ?"
,
_url
)
...
...
@@ -63,41 +63,41 @@ func Findlink(_url string) string {
}
// save text information
//保存文本和文件信息
func
Savetext
(
_Route
string
,
_Time
uint
,
_Passwd
string
,
_Time1
time
.
Time
,
_url
string
)
{
//
保存文本和文件信息
func
Savetext
(
_Route
string
,
_Time
uint
,
_Passwd
string
,
_Time1
time
.
Time
,
_url
string
)
{
id1
++
p
:=
Content
{
ID
:
id1
,
Route
:
_Route
,
Time
:
_Time
,
Passwd
:
_Passwd
,
Date
:
time
.
Now
(),
Time1
:
_Time1
,
Time2
:
0
,
Url1
:
_url
,
ID
:
id1
,
Route
:
_Route
,
Time
:
_Time
,
Passwd
:
_Passwd
,
Date
:
time
.
Now
(),
Time1
:
_Time1
,
Time2
:
0
,
Url1
:
_url
,
}
DB
.
Create
(
&
p
)
}
// Check whether the number of visits exceeds the threshold and the time limit
//检查是否超过总访问次数和截止时间
//
检查是否超过总访问次数和截止时间
func
Checkt
(
_Route
string
)
{
var
p
Content
err
:=
DB
.
First
(
&
p
,
"Route = ?"
,
_Route
)
err
:=
DB
.
First
(
&
p
,
"Route = ?"
,
_Route
)
if
err
!=
nil
{
logrus
.
Error
(
err
)
}
t
:=
time
.
Now
()
p
.
Time2
++
if
p
.
Time2
>
p
.
Time
||
t
.
After
(
p
.
Time1
)
{
if
p
.
Time2
>
p
.
Time
||
t
.
After
(
p
.
Time1
)
{
DB
.
Delete
(
&
p
)
}
}
//查找sessionid和url是否关联
func
Find
(
sid
string
,
_url
string
)
bool
{
//
查找sessionid和url是否关联
func
Find
(
sid
string
,
_url
string
)
bool
{
var
s
Sid
err1
:=
DB
.
First
(
&
s
,
"S = ?"
,
sid
)
.
Error
err1
:=
DB
.
First
(
&
s
,
"S = ?"
,
sid
)
.
Error
//fmt.Println(url.Url1,url.ID,"\n")
if
err1
!=
nil
{
return
false
...
...
@@ -106,7 +106,7 @@ func Find(sid string,_url string) bool {
DB
.
Model
(
&
s
)
.
Association
(
"Url1"
)
.
Find
(
&
Urls
)
for
_
,
value
:=
range
Urls
{
if
value
.
Url1
==
_url
{
return
true
return
true
}
}
return
false
...
...
@@ -124,30 +124,30 @@ func randStr(n int) string {
return string(b)
}*/
//新建用户
//
新建用户
func
Createuser
(
_User
Users
)
{
//_User.SessionId=randStr(8)
DB
.
Create
(
&
_User
)
//_User.SessionId=randStr(8)
DB
.
Create
(
&
_User
)
}
//新建链接
func
Createlink
(
sid
string
,
_passwd
string
,
_url
string
)
bool
{
//
新建链接
func
Createlink
(
sid
string
,
_passwd
string
,
_url
string
)
bool
{
var
p
Content
DB
.
First
(
&
p
,
"Url1 = ?"
,
_url
)
if
p
.
Passwd
==
_passwd
{
var
p1
Sid
err
:=
DB
.
First
(
&
p1
,
"S = ?"
,
sid
)
.
Error
if
err
!=
nil
{
sid1
:=
Sid
{
S
:
sid
,
var
p1
Sid
err
:=
DB
.
First
(
&
p1
,
"S = ?"
,
sid
)
.
Error
if
err
!=
nil
{
sid1
:=
Sid
{
S
:
sid
,
Url1
:
[]
Url
{
{
Url1
:
_url
},
{
Url1
:
_url
},
},
}
DB
.
Create
(
&
sid1
)
}
else
{
DB
.
Model
(
&
p1
)
.
Association
(
"Url1"
)
.
Append
(
&
Url
{
Url1
:
_url
})
}
}
DB
.
Create
(
&
sid1
)
}
else
{
DB
.
Model
(
&
p1
)
.
Association
(
"Url1"
)
.
Append
(
&
Url
{
Url1
:
_url
})
}
return
true
}
return
false
...
...
backend/model/test.sql
0 → 100644
View file @
596810c8
This diff is collapsed.
Click to expand it.
backend/mysql/pastebin.sql
0 → 100644
View file @
596810c8
create
database
pastebin
;
create
user
'rootp'
@
'localhost'
identified
by
'pastebingroup1'
;
grant
all
privileges
on
pastebin
.
*
to
'rootp'
@
'localhost'
;
use
pastebin
;
backend/mysql/test1.sql
0 → 100644
View file @
596810c8
-- MySQL dump 10.13 Distrib 8.0.31, for Win64 (x86_64)
--
-- Host: localhost Database: pastebin
-- ------------------------------------------------------
-- Server version 8.0.31
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */
;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */
;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */
;
/*!50503 SET NAMES utf8mb4 */
;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */
;
/*!40103 SET TIME_ZONE='+00:00' */
;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */
;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */
;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */
;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */
;
--
-- Table structure for table `contents`
--
DROP
TABLE
IF
EXISTS
`contents`
;
/*!40101 SET @saved_cs_client = @@character_set_client */
;
/*!50503 SET character_set_client = utf8mb4 */
;
CREATE
TABLE
`contents`
(
`id`
bigint
unsigned
NOT
NULL
AUTO_INCREMENT
,
`route`
longtext
,
`time`
bigint
unsigned
DEFAULT
NULL
,
`passwd`
longtext
,
`date`
datetime
(
3
)
DEFAULT
NULL
,
`size`
bigint
unsigned
DEFAULT
NULL
,
`time1`
datetime
(
3
)
DEFAULT
NULL
,
`time2`
bigint
unsigned
DEFAULT
NULL
,
`url1`
longtext
,
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb3
;
/*!40101 SET character_set_client = @saved_cs_client */
;
--
-- Dumping data for table `contents`
--
LOCK
TABLES
`contents`
WRITE
;
/*!40000 ALTER TABLE `contents` DISABLE KEYS */
;
/*!40000 ALTER TABLE `contents` ENABLE KEYS */
;
UNLOCK
TABLES
;
--
-- Table structure for table `sid_urls`
--
DROP
TABLE
IF
EXISTS
`sid_urls`
;
/*!40101 SET @saved_cs_client = @@character_set_client */
;
/*!50503 SET character_set_client = utf8mb4 */
;
CREATE
TABLE
`sid_urls`
(
`sid_id`
bigint
unsigned
NOT
NULL
,
`url_id`
bigint
unsigned
NOT
NULL
,
PRIMARY
KEY
(
`sid_id`
,
`url_id`
),
KEY
`fk_sid_urls_url`
(
`url_id`
),
CONSTRAINT
`fk_sid_urls_sid`
FOREIGN
KEY
(
`sid_id`
)
REFERENCES
`sids`
(
`id`
),
CONSTRAINT
`fk_sid_urls_url`
FOREIGN
KEY
(
`url_id`
)
REFERENCES
`urls`
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb3
;
/*!40101 SET character_set_client = @saved_cs_client */
;
--
-- Dumping data for table `sid_urls`
--
LOCK
TABLES
`sid_urls`
WRITE
;
/*!40000 ALTER TABLE `sid_urls` DISABLE KEYS */
;
/*!40000 ALTER TABLE `sid_urls` ENABLE KEYS */
;
UNLOCK
TABLES
;
--
-- Table structure for table `sids`
--
DROP
TABLE
IF
EXISTS
`sids`
;
/*!40101 SET @saved_cs_client = @@character_set_client */
;
/*!50503 SET character_set_client = utf8mb4 */
;
CREATE
TABLE
`sids`
(
`id`
bigint
unsigned
NOT
NULL
AUTO_INCREMENT
,
`created_at`
datetime
(
3
)
DEFAULT
NULL
,
`updated_at`
datetime
(
3
)
DEFAULT
NULL
,
`deleted_at`
datetime
(
3
)
DEFAULT
NULL
,
`s`
longtext
,
PRIMARY
KEY
(
`id`
),
KEY
`idx_sids_deleted_at`
(
`deleted_at`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb3
;
/*!40101 SET character_set_client = @saved_cs_client */
;
--
-- Dumping data for table `sids`
--
LOCK
TABLES
`sids`
WRITE
;
/*!40000 ALTER TABLE `sids` DISABLE KEYS */
;
/*!40000 ALTER TABLE `sids` ENABLE KEYS */
;
UNLOCK
TABLES
;
--
-- Table structure for table `urls`
--
DROP
TABLE
IF
EXISTS
`urls`
;
/*!40101 SET @saved_cs_client = @@character_set_client */
;
/*!50503 SET character_set_client = utf8mb4 */
;
CREATE
TABLE
`urls`
(
`id`
bigint
unsigned
NOT
NULL
AUTO_INCREMENT
,
`created_at`
datetime
(
3
)
DEFAULT
NULL
,
`updated_at`
datetime
(
3
)
DEFAULT
NULL
,
`deleted_at`
datetime
(
3
)
DEFAULT
NULL
,
`url1`
longtext
,
PRIMARY
KEY
(
`id`
),
KEY
`idx_urls_deleted_at`
(
`deleted_at`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb3
;
/*!40101 SET character_set_client = @saved_cs_client */
;
--
-- Dumping data for table `urls`
--
LOCK
TABLES
`urls`
WRITE
;
/*!40000 ALTER TABLE `urls` DISABLE KEYS */
;
/*!40000 ALTER TABLE `urls` ENABLE KEYS */
;
UNLOCK
TABLES
;
--
-- Table structure for table `users`
--
DROP
TABLE
IF
EXISTS
`users`
;
/*!40101 SET @saved_cs_client = @@character_set_client */
;
/*!50503 SET character_set_client = utf8mb4 */
;
CREATE
TABLE
`users`
(
`session_id`
longtext
,
`username`
longtext
,
`passwd`
longtext
,
`name`
longtext
,
`size`
bigint
unsigned
DEFAULT
NULL
,
`route`
longtext
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb3
;
/*!40101 SET character_set_client = @saved_cs_client */
;
--
-- Dumping data for table `users`
--
LOCK
TABLES
`users`
WRITE
;
/*!40000 ALTER TABLE `users` DISABLE KEYS */
;
/*!40000 ALTER TABLE `users` ENABLE KEYS */
;
UNLOCK
TABLES
;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */
;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */
;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */
;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */
;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */
;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */
;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */
;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */
;
-- Dump completed on 2023-01-17 22:07:33
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment