Skip to content

Commit

Permalink
Merge pull request PasteUs#92 from LucienShui/chore/go1.16_supported
Browse files Browse the repository at this point in the history
go1.16 supported
Interface Paste supported
  • Loading branch information
LucienShui authored Jul 11, 2021
2 parents fa95278 + 8d583d8 commit 3d3e84c
Show file tree
Hide file tree
Showing 17 changed files with 228 additions and 358 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
release:
strategy:
matrix:
go_version: [1.12]
go_version: [1.16]
os: [ubuntu-latest]

if: github.repository == 'PasteUs/PasteMeGoBackend'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
build:
strategy:
matrix:
go_version: [1.12]
go_version: [1.16]
os: [ubuntu-latest]

name: Build with go ${{ matrix.go_version }} on ${{ matrix.os }}
Expand Down Expand Up @@ -38,8 +38,8 @@ jobs:
matrix:
# go_version: [1.12, 1.13]
# remove 1.13 for /~https://github.com/golang/go/issues/31859
go_version: [1.12]
mysql_version: [5.5, 5.7, 8]
go_version: [1.16]
mysql_version: [5.5, 8]
os: [ubuntu-latest]

name: Test with go ${{ matrix.go_version }} using mysql:${{ matrix.mysql_version }} on ${{ matrix.os }}
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
matrix:
# go_version: [1.12, 1.13]
# remove 1.13 for /~https://github.com/golang/go/issues/31859
go_version: [1.12]
go_version: [1.16]
os: [ubuntu-latest]

name: Test with go ${{ matrix.go_version }} using sqlite3 on ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upload-to-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
go_version: [1.12]
go_version: [1.16]
os: [ubuntu-latest]

steps:
Expand Down
31 changes: 31 additions & 0 deletions api.http
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
11 changes: 2 additions & 9 deletions flag/flag.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
/*
@File: flag.go
@Contact: lucien@lucien.ink
@Licence: (C)Copyright 2019 Lucien
@Modify Time @Author @Version @Description
------------ ------- -------- -----------
2019-07-25 08:36 Lucien 1.0 Init
*/
package flag

import (
Expand All @@ -16,6 +7,7 @@ import (
"github.com/wonderivan/logger"
"os"
"strings"
"testing"
)

var (
Expand All @@ -31,6 +23,7 @@ func init() {
flag.BoolVar(&Debug, "debug", false, "--debug Using debug mode")
flag.StringVar(&DataDir, "d", "./", "-d <data dir>")

testing.Init()
flag.Parse()

validationCheck()
Expand Down
25 changes: 15 additions & 10 deletions go.mod
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
)
177 changes: 47 additions & 130 deletions go.sum

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions http-client.env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dev": {
"host": "http://localhost:8000"
}
}
10 changes: 0 additions & 10 deletions model/model.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
/*
@File: model.go
@Contact: lucien@lucien.ink
@Licence: (C)Copyright 2019 Lucien Shui
@Modify Time @Author @Version @Description
------------ ------- -------- -----------
2019-06-23 14:03 Lucien 1.0.0 None
2019-10-20 19:30 Lucien 1.1.0 Add SQLite support
*/
package model

import (
Expand Down
50 changes: 50 additions & 0 deletions model/paste.go
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
}
35 changes: 7 additions & 28 deletions model/permanent.go
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
}
39 changes: 7 additions & 32 deletions model/temporary.go
Original file line number Diff line number Diff line change
@@ -1,50 +1,25 @@
/*
@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"
)

// 临时
// Temporary 临时
type Temporary struct {
Key string `json:"key" gorm:"type:varchar(16);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
}

// 成员函数,保存
// Save 成员函数,保存
func (paste *Temporary) 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 *Temporary) Delete() error {
return db.Delete(&paste, "`key` = ?", paste.Key).Error
}

// 成员函数,查看
// Get 成员函数,查看
func (paste *Temporary) Get() error {
return db.Find(&paste, "`key` = ?", paste.Key).Error
}
Expand Down
Loading

0 comments on commit 3d3e84c

Please sign in to comment.