[FIX]登录bug,删除cron,dockerfile
This commit is contained in:
parent
d9be1cab40
commit
f27327f7c7
|
@ -17,4 +17,7 @@
|
||||||
# vendor/
|
# vendor/
|
||||||
go.sum
|
go.sum
|
||||||
.idea/*
|
.idea/*
|
||||||
runtime/*
|
runtime/*
|
||||||
|
shop
|
||||||
|
__debug_bin
|
||||||
|
.vscode/*
|
|
@ -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"]
|
|
@ -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
|
||||||
|
```
|
|
@ -3,7 +3,7 @@ PageSize = 10
|
||||||
JwtSecret = 233
|
JwtSecret = 233
|
||||||
|
|
||||||
RuntimeRootPath = runtime/
|
RuntimeRootPath = runtime/
|
||||||
ImagePrefixUrl = http://127.0.0.8002
|
ImagePrefixUrl = http://127.0.0.1:8002
|
||||||
ImageSavePath = upload/images/
|
ImageSavePath = upload/images/
|
||||||
ImageMaxSize = 1024
|
ImageMaxSize = 1024
|
||||||
ImageAllowExts = .jpg,.jpeg,.png
|
ImageAllowExts = .jpg,.jpeg,.png
|
||||||
|
|
28
cron.go
28
cron.go
|
@ -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
1
go.mod
|
@ -15,7 +15,6 @@ require (
|
||||||
github.com/jinzhu/gorm v1.9.16
|
github.com/jinzhu/gorm v1.9.16
|
||||||
github.com/lib/pq v1.2.0 // indirect
|
github.com/lib/pq v1.2.0 // indirect
|
||||||
github.com/mailru/easyjson v0.7.6 // 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/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 // indirect
|
||||||
github.com/swaggo/gin-swagger v1.2.0
|
github.com/swaggo/gin-swagger v1.2.0
|
||||||
github.com/swaggo/swag v1.6.7
|
github.com/swaggo/swag v1.6.7
|
||||||
|
|
7
main.go
7
main.go
|
@ -2,17 +2,18 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/go-pripro/shop/models"
|
"github.com/go-pripro/shop/models"
|
||||||
"github.com/go-pripro/shop/pkg/gredis"
|
"github.com/go-pripro/shop/pkg/gredis"
|
||||||
"github.com/go-pripro/shop/pkg/logging"
|
"github.com/go-pripro/shop/pkg/logging"
|
||||||
"github.com/go-pripro/shop/pkg/setting"
|
"github.com/go-pripro/shop/pkg/setting"
|
||||||
"github.com/go-pripro/shop/routers"
|
"github.com/go-pripro/shop/routers"
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
setting.Setup()
|
setting.Setup()
|
||||||
models.Setup()
|
models.Setup()
|
||||||
logging.Setup()
|
logging.Setup()
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package admin
|
package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/astaxie/beego/validation"
|
"github.com/astaxie/beego/validation"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/go-pripro/shop/models"
|
"github.com/go-pripro/shop/models"
|
||||||
"github.com/go-pripro/shop/pkg/app"
|
"github.com/go-pripro/shop/pkg/app"
|
||||||
"github.com/go-pripro/shop/pkg/e"
|
"github.com/go-pripro/shop/pkg/e"
|
||||||
"github.com/go-pripro/shop/pkg/util"
|
"github.com/go-pripro/shop/pkg/util"
|
||||||
"golang.org/x/crypto/bcrypt"
|
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Employee struct {
|
type Employee struct {
|
||||||
|
@ -22,7 +22,7 @@ type Employee struct {
|
||||||
// @Param password query string true "密码"
|
// @Param password query string true "密码"
|
||||||
// @Success 200 {string} json "{"code":200,"data":{},"msg":"ok"}"
|
// @Success 200 {string} json "{"code":200,"data":{},"msg":"ok"}"
|
||||||
// @Router /admin/login [get]
|
// @Router /admin/login [get]
|
||||||
func GetLogin(c *gin.Context) {
|
func GetLogin(c *gin.Context) {
|
||||||
appG := app.Gin{C: c}
|
appG := app.Gin{C: c}
|
||||||
username := c.Query("username")
|
username := c.Query("username")
|
||||||
password := c.Query("password")
|
password := c.Query("password")
|
||||||
|
@ -36,19 +36,15 @@ func GetLogin(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
data := make(map[string]interface{})
|
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)
|
appG.Response(http.StatusInternalServerError, e.ErrorAuth, nil)
|
||||||
} else {
|
} else {
|
||||||
if err := bcrypt.CompareHashAndPassword([]byte(fEmployee.Password), []byte(password)); err != nil{
|
token, err := util.GenerateToken(username, password)
|
||||||
appG.Response(http.StatusInternalServerError, e.ErrorAuth, nil)
|
if err != nil {
|
||||||
|
appG.Response(http.StatusInternalServerError, e.ErrorAuthToken, nil)
|
||||||
} else {
|
} else {
|
||||||
token, err := util.GenerateToken(username, password)
|
data["token"] = token
|
||||||
if err != nil {
|
appG.Response(http.StatusOK, e.SUCCESS, data)
|
||||||
appG.Response(http.StatusInternalServerError, e.ErrorAuthToken, nil)
|
|
||||||
} else {
|
|
||||||
data["token"] = token
|
|
||||||
appG.Response(http.StatusOK, e.SUCCESS, data)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package admin
|
package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/go-pripro/shop/pkg/e"
|
"github.com/go-pripro/shop/pkg/e"
|
||||||
"github.com/go-pripro/shop/pkg/logging"
|
"github.com/go-pripro/shop/pkg/logging"
|
||||||
"github.com/go-pripro/shop/pkg/upload"
|
"github.com/go-pripro/shop/pkg/upload"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// @Summary 上传图片
|
// @Summary 上传图片
|
||||||
|
@ -57,8 +58,8 @@ func UploadImage(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"code" : code,
|
"code": code,
|
||||||
"msg" : e.GetMsg(code),
|
"msg": e.GetMsg(code),
|
||||||
"data" : data,
|
"data": data,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue