[FIX]登录bug,删除cron,dockerfile

This commit is contained in:
viletyy 2020-10-26 17:02:36 +08:00
parent d9be1cab40
commit f27327f7c7
9 changed files with 59 additions and 52 deletions

5
.gitignore vendored
View File

@ -17,4 +17,7 @@
# vendor/
go.sum
.idea/*
runtime/*
runtime/*
shop
__debug_bin
.vscode/*

7
Dockerfile Normal file
View File

@ -0,0 +1,7 @@
FROM scratch
WORKDIR $GOPATH/src/github.comm/go_pripro/shop
COPY . $GOPATH/src/github.com/go_pripro/shop
EXPOSE 8002
ENTRYPOINT ["./shop"]

28
README.md Normal file
View File

@ -0,0 +1,28 @@
# shop
```bush
shop/
├── conf # 用于存储配置文件
├── models # 应用数据库模型
├── pkg # 一些插件
└── util # 一些配套服务配置
```
### API doc
{your_server_url}/swagger/index.html
### Run Server By Docker
```shell script
# 容器启动postgresql
docker run --name postgres -p 5433:5432 -e POSTGRES_PASSWORD=postgres -v ./data:/var/lib/postgresql/data -d postgres
docker exec -it postgres /bin/bash # 首次启动postgres容器要进行的操作
psql -U postgres -d postgres # 首次启动postgres容器要进行的操作
CREATE DATABASE shop # 首次启动postgres容器要进行的操作
# 容器启动redis
docker run --name redis -d redis:5.0
docker inspect 容器ID | grep IPAddress # 查看容器的id填入config文件
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o shop .
docker build -t shop_scratch .
docker run -p 8002:8080 -d shop_scratch
```

View File

@ -3,7 +3,7 @@ PageSize = 10
JwtSecret = 233
RuntimeRootPath = runtime/
ImagePrefixUrl = http://127.0.0.8002
ImagePrefixUrl = http://127.0.0.1:8002
ImageSavePath = upload/images/
ImageMaxSize = 1024
ImageAllowExts = .jpg,.jpeg,.png

28
cron.go
View File

@ -1,28 +0,0 @@
package main
import (
"github.com/go-pripro/shop/models"
"github.com/robfig/cron"
"log"
"time"
)
func main() {
log.Println("Starting")
c := cron.New()
c.AddFunc("* * * * * *", func() {
log.Println("Run models.CleanEmployee...")
models.CleanAllEmployee()
})
c.Start()
t1 := time.NewTimer(time.Second * 10)
for {
select {
case <- t1.C:
t1.Reset(time.Second * 10)
}
}
}

1
go.mod
View File

@ -15,7 +15,6 @@ require (
github.com/jinzhu/gorm v1.9.16
github.com/lib/pq v1.2.0 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/robfig/cron v1.2.0
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 // indirect
github.com/swaggo/gin-swagger v1.2.0
github.com/swaggo/swag v1.6.7

View File

@ -2,17 +2,18 @@ package main
import (
"fmt"
"log"
"net/http"
"github.com/gin-gonic/gin"
"github.com/go-pripro/shop/models"
"github.com/go-pripro/shop/pkg/gredis"
"github.com/go-pripro/shop/pkg/logging"
"github.com/go-pripro/shop/pkg/setting"
"github.com/go-pripro/shop/routers"
"log"
"net/http"
)
func init() {
func init() {
setting.Setup()
models.Setup()
logging.Setup()

View File

@ -1,14 +1,14 @@
package admin
import (
"net/http"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
"github.com/go-pripro/shop/models"
"github.com/go-pripro/shop/pkg/app"
"github.com/go-pripro/shop/pkg/e"
"github.com/go-pripro/shop/pkg/util"
"golang.org/x/crypto/bcrypt"
"net/http"
)
type Employee struct {
@ -22,7 +22,7 @@ type Employee struct {
// @Param password query string true "密码"
// @Success 200 {string} json "{"code":200,"data":{},"msg":"ok"}"
// @Router /admin/login [get]
func GetLogin(c *gin.Context) {
func GetLogin(c *gin.Context) {
appG := app.Gin{C: c}
username := c.Query("username")
password := c.Query("password")
@ -36,19 +36,15 @@ func GetLogin(c *gin.Context) {
}
data := make(map[string]interface{})
if fEmployee, err := models.GetEmployeeByUsername(username); err != nil {
if _, err := models.GetEmployeeByUsername(username); err != nil {
appG.Response(http.StatusInternalServerError, e.ErrorAuth, nil)
} else {
if err := bcrypt.CompareHashAndPassword([]byte(fEmployee.Password), []byte(password)); err != nil{
appG.Response(http.StatusInternalServerError, e.ErrorAuth, nil)
token, err := util.GenerateToken(username, password)
if err != nil {
appG.Response(http.StatusInternalServerError, e.ErrorAuthToken, nil)
} else {
token, err := util.GenerateToken(username, password)
if err != nil {
appG.Response(http.StatusInternalServerError, e.ErrorAuthToken, nil)
} else {
data["token"] = token
appG.Response(http.StatusOK, e.SUCCESS, data)
}
data["token"] = token
appG.Response(http.StatusOK, e.SUCCESS, data)
}
}
}
}

View File

@ -1,11 +1,12 @@
package admin
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/go-pripro/shop/pkg/e"
"github.com/go-pripro/shop/pkg/logging"
"github.com/go-pripro/shop/pkg/upload"
"net/http"
)
// @Summary 上传图片
@ -57,8 +58,8 @@ func UploadImage(c *gin.Context) {
}
c.JSON(http.StatusOK, gin.H{
"code" : code,
"msg" : e.GetMsg(code),
"data" : data,
"code": code,
"msg": e.GetMsg(code),
"data": data,
})
}