forked from PasteUs/PasteMeGoBackend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request PasteUs#92 from LucienShui/chore/go1.16_supported
go1.16 supported Interface Paste supported
- Loading branch information
Showing
17 changed files
with
228 additions
and
358 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ jobs: | |
|
||
strategy: | ||
matrix: | ||
go_version: [1.12] | ||
go_version: [1.16] | ||
os: [ubuntu-latest] | ||
|
||
steps: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
### Get nothing | ||
GET {{host}}/?method=beat | ||
Accept: application/json | ||
|
||
### Get example | ||
GET {{host}}/example | ||
Accept: application/json | ||
|
||
### Create custom read once paste | ||
PUT {{host}}/example | ||
Content-Type: application/json | ||
Accept: application/json | ||
|
||
{ | ||
"lang": "plain", | ||
"content": "Hello World!" | ||
} | ||
|
||
### Create permanent | ||
POST {{host}} | ||
Content-Type: application/json | ||
Accept: application/json | ||
|
||
{ | ||
"lang": "plain", | ||
"content": "Hello World!" | ||
} | ||
|
||
### Get example | ||
GET {{host}}/100 | ||
Accept: application/json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
module github.com/PasteUs/PasteMeGoBackend | ||
|
||
go 1.12 | ||
go 1.16 | ||
|
||
require ( | ||
github.com/gin-gonic/gin v1.6.3 | ||
github.com/go-playground/validator/v10 v10.3.0 // indirect | ||
github.com/go-sql-driver/mysql v1.5.0 | ||
github.com/golang/protobuf v1.4.2 // indirect | ||
github.com/gin-gonic/gin v1.7.2 | ||
github.com/go-playground/validator/v10 v10.7.0 // indirect | ||
github.com/go-sql-driver/mysql v1.6.0 | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/jinzhu/gorm v1.9.16 | ||
github.com/json-iterator/go v1.1.10 // indirect | ||
github.com/mattn/go-sqlite3 v1.14.2 | ||
github.com/json-iterator/go v1.1.11 // indirect | ||
github.com/leodido/go-urn v1.2.1 // indirect | ||
github.com/mattn/go-isatty v0.0.13 // indirect | ||
github.com/mattn/go-sqlite3 v1.14.7 | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.1 // indirect | ||
github.com/ugorji/go v1.2.6 // indirect | ||
github.com/wonderivan/logger v1.0.0 | ||
golang.org/x/sys v0.0.0-20200828194041-157a740278f4 // indirect | ||
google.golang.org/protobuf v1.25.0 // indirect | ||
gopkg.in/yaml.v2 v2.3.0 // indirect | ||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect | ||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect | ||
golang.org/x/text v0.3.6 // indirect | ||
google.golang.org/protobuf v1.27.1 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"dev": { | ||
"host": "http://localhost:8000" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package model | ||
|
||
import ( | ||
"errors" | ||
"github.com/PasteUs/PasteMeGoBackend/util/convert" | ||
"time" | ||
) | ||
|
||
type IPaste interface { | ||
Save() error | ||
Get() error | ||
Delete() error | ||
GetContent() string | ||
GetLang() string | ||
GetPassword() string | ||
} | ||
|
||
type AbstractPaste struct { | ||
IPaste | ||
Lang string `json:"lang" gorm:"type:varchar(16)"` // 语言类型 | ||
Content string `json:"content" gorm:"type:mediumtext"` // 内容,最大长度为 16777215(2^24-1) 个字符 | ||
Password string `json:"password" gorm:"type:varchar(32)"` // 密码 | ||
ClientIP string `gorm:"type:varchar(64)"` // 用户 IP | ||
CreatedAt time.Time // 存储记录的创建时间 | ||
} | ||
|
||
func (paste *AbstractPaste) GetContent() string { | ||
return paste.Content | ||
} | ||
|
||
func (paste *AbstractPaste) GetPassword() string { | ||
return paste.Password | ||
} | ||
|
||
func (paste *AbstractPaste) GetLang() string { | ||
return paste.Password | ||
} | ||
|
||
func (paste *AbstractPaste) beforeSave() error { | ||
if paste.Content == "" { | ||
return errors.New("empty content") // 内容为空,返回错误信息 "empty content" | ||
} | ||
if paste.Lang == "" { | ||
return errors.New("empty lang") // 语言类型为空,返回错误信息 "empty lang" | ||
} | ||
if paste.Password != "" { | ||
paste.Password = convert.String2md5(paste.Password) // 加密存储,设置密码 | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,32 @@ | ||
/* | ||
@File: paste.go | ||
@Contact: lucien@lucien.ink | ||
@Licence: (C)Copyright 2019 Lucien Shui | ||
@Modify Time @Author @Version @Description | ||
------------ ------- -------- ----------- | ||
2019-06-23 14:03 Lucien 1.0 None | ||
*/ | ||
package model | ||
|
||
import ( | ||
"errors" | ||
"github.com/PasteUs/PasteMeGoBackend/util/convert" | ||
"time" | ||
) | ||
|
||
// 永久 | ||
// Permanent 永久 | ||
type Permanent struct { | ||
Key uint64 `gorm:"primary_key"` // 主键:索引 | ||
Lang string `json:"lang" gorm:"type:varchar(16)"` // 语言类型 | ||
Content string `json:"content" gorm:"type:mediumtext"` // 内容,最大长度为 16777215(2^24-1) 个字符 | ||
Password string `json:"password" gorm:"type:varchar(32)"` // 密码 | ||
ClientIP string `gorm:"type:varchar(64)"` // 用户 IP | ||
CreatedAt time.Time // 存储记录的创建时间 | ||
*AbstractPaste | ||
// 存储记录的删除时间 | ||
// 删除具有 DeletedAt 字段的记录,它不会从数据库中删除,但只将字段 DeletedAt 设置为当前时间,并在查询时无法找到记录 | ||
DeletedAt *time.Time | ||
} | ||
|
||
//成员函数,创建 | ||
// Save 成员函数,创建 | ||
func (paste *Permanent) Save() error { | ||
if paste.Content == "" { | ||
return errors.New("empty content") // 内容为空,返回错误信息 "empty content" | ||
} | ||
if paste.Lang == "" { | ||
return errors.New("empty lang") // 语言类型为空,返回错误信息 "empty lang" | ||
} | ||
if paste.Password != "" { | ||
paste.Password = convert.String2md5(paste.Password) // 加密存储,设置密码 | ||
if err := paste.beforeSave(); err != nil { | ||
return err | ||
} | ||
return db.Create(&paste).Error | ||
} | ||
|
||
// 成员函数,删除 | ||
// Delete 成员函数,删除 | ||
func (paste *Permanent) Delete() error { | ||
return db.Delete(&paste, "`key` = ?", paste.Key).Error | ||
} | ||
|
||
// 成员函数,访问 | ||
// Get 成员函数,访问 | ||
func (paste *Permanent) Get() error { | ||
return db.Find(&paste, "`key` = ?", paste.Key).Error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.