feat: temp upload
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package config
|
||||
package global
|
||||
|
||||
type ServerConfig struct {
|
||||
Listen string `yaml:"listen"`
|
||||
@@ -11,6 +11,7 @@ type ServerConfig struct {
|
||||
Redis RedisConfig `yaml:"redis"`
|
||||
Jwt JwtConfig `yaml:"jwt"`
|
||||
Email EmailConfig `yaml:"email"`
|
||||
Bos BosConfig `yaml:"bos"`
|
||||
}
|
||||
|
||||
type MySQLConfig struct {
|
||||
@@ -39,3 +40,9 @@ type EmailConfig struct {
|
||||
Account string `yaml:"account"`
|
||||
Password string `yaml:"password"`
|
||||
}
|
||||
|
||||
type BosConfig struct {
|
||||
AccessKey string `yaml:"accessKey"`
|
||||
SecretKey string `yaml:"secretKey"`
|
||||
Domain string `yaml:"domain"`
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package global
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"nCovTrack-Backend/config"
|
||||
"github.com/baidubce/bce-sdk-go/services/bos"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -13,12 +13,13 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ServerSettings config.ServerConfig
|
||||
ServerSettings ServerConfig
|
||||
Db *gorm.DB
|
||||
RootRouter *gin.RouterGroup
|
||||
Logger *zap.SugaredLogger
|
||||
HttpClient map[string]*http.Client
|
||||
Redis *redis.Client
|
||||
BosClient *bos.Client
|
||||
)
|
||||
|
||||
func GetListenOn() string {
|
||||
@@ -37,7 +38,14 @@ const (
|
||||
CHINA_NCOV_STATISTIC_URL = "https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5"
|
||||
ENV_NOLOG = "nolog"
|
||||
TOKEN_EXPIRE_DAYS = 15
|
||||
FACKER_HOST = "http://myhost.fallen-angle.com:5000/"
|
||||
|
||||
REGISTER_REDIS_KEY = "register_key"
|
||||
CHANGEPWD_REDIS_KEY = "changepwd_key"
|
||||
)
|
||||
|
||||
var (
|
||||
ROLE_ID_MAP = map[int]string{
|
||||
0: "SYSTEM",
|
||||
}
|
||||
)
|
||||
|
||||
1
go.mod
1
go.mod
@@ -18,6 +18,7 @@ require (
|
||||
github.com/KyleBanks/depth v1.2.1 // indirect
|
||||
github.com/PuerkitoBio/purell v1.1.1 // indirect
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
|
||||
github.com/baidubce/bce-sdk-go v0.9.112 // indirect
|
||||
github.com/fsnotify/fsnotify v1.5.1 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.19.5 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@@ -46,6 +46,8 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/agiledragon/gomonkey/v2 v2.3.1 h1:k+UnUY0EMNYUFUAQVETGY9uUTxjMdnUkP0ARyJS1zzs=
|
||||
github.com/agiledragon/gomonkey/v2 v2.3.1/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=
|
||||
github.com/baidubce/bce-sdk-go v0.9.112 h1:qHzFxG7fwGbXCv+1smcbWFhWl6iwoXDVzPn9TUtrlss=
|
||||
github.com/baidubce/bce-sdk-go v0.9.112/go.mod h1:zbYJMQwE4IZuyrJiFO8tO8NbtYiKTFTbwh4eIsqjVdg=
|
||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
|
||||
20
initialize/bos.go
Normal file
20
initialize/bos.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"github.com/baidubce/bce-sdk-go/services/bos"
|
||||
"nCovTrack-Backend/global"
|
||||
)
|
||||
|
||||
func initBos() {
|
||||
clientConfig := bos.BosClientConfiguration{
|
||||
global.ServerSettings.Bos.AccessKey,
|
||||
global.ServerSettings.Bos.SecretKey,
|
||||
global.ServerSettings.Bos.Domain,
|
||||
false,
|
||||
}
|
||||
bosClient, err := bos.NewClientWithConfig(&clientConfig)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
global.BosClient = bosClient
|
||||
}
|
||||
@@ -2,11 +2,9 @@ package initialize
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"nCovTrack-Backend/config"
|
||||
"nCovTrack-Backend/global"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/spf13/viper"
|
||||
"nCovTrack-Backend/global"
|
||||
)
|
||||
|
||||
func initConfig() {
|
||||
@@ -16,7 +14,7 @@ func initConfig() {
|
||||
if err := v.ReadInConfig(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
serverConfig := config.ServerConfig{}
|
||||
serverConfig := global.ServerConfig{}
|
||||
if err := v.Unmarshal(&serverConfig); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ func Initialize() *gin.Engine {
|
||||
initHttpClient()
|
||||
initMySQL()
|
||||
initRedis()
|
||||
initBos()
|
||||
initCron()
|
||||
g := initRouter()
|
||||
initSwagger()
|
||||
|
||||
@@ -27,6 +27,7 @@ func Auth() gin.HandlerFunc {
|
||||
c.Request.Header.Set("role", fmt.Sprint(claims["role"]))
|
||||
c.Request.Header.Set("email", claims["email"].(string))
|
||||
c.Request.Header.Set("id", fmt.Sprint(claims["id"]))
|
||||
c.Request.Header.Set("role", claims["role"].(string))
|
||||
|
||||
// renew token, and judge the token's iat is expired or not
|
||||
renewToken := utils.RenewToken(oldToken[0])
|
||||
|
||||
43
models/investigate.go
Normal file
43
models/investigate.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type FakerDate time.Time
|
||||
|
||||
const (
|
||||
timeFormat = "2006-01-02"
|
||||
)
|
||||
|
||||
func (t *FakerDate) UnmarshalJSON(data []byte) (err error) {
|
||||
fmt.Println(string(data))
|
||||
newTime, err := time.ParseInLocation(`"`+timeFormat+`"`, string(data), time.Local)
|
||||
*t = FakerDate(newTime)
|
||||
return
|
||||
}
|
||||
|
||||
func (t FakerDate) MarshalJSON() ([]byte, error) {
|
||||
fmt.Println(time.Time(t).Format(timeFormat))
|
||||
timeStr := fmt.Sprintf("\"%s\"", time.Time(t).Format(timeFormat))
|
||||
return []byte(timeStr), nil
|
||||
}
|
||||
|
||||
func (t FakerDate) String() string {
|
||||
return time.Time(t).Format(timeFormat)
|
||||
}
|
||||
|
||||
type HotelContactRequest struct {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age,string"`
|
||||
Sex int `json:"sex,string"`
|
||||
Phone string `json:"phone"`
|
||||
Address string `json:"address"`
|
||||
HotelCode string `json:"hotel_code"`
|
||||
HotelName string `json:"hotel_name"`
|
||||
LocateCityId string `json:"locate_city_id"`
|
||||
Identification string `json:"identification"`
|
||||
InData FakerDate `json:"in_data"`
|
||||
OutData FakerDate `json:"out_data"`
|
||||
}
|
||||
17
router/investigate.go
Normal file
17
router/investigate.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"nCovTrack-Backend/service/investigate"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func investigatePublicRouter(router *gin.RouterGroup) {
|
||||
investigateRouter := router.Group("investigate")
|
||||
{
|
||||
investigateRouter.GET("/test", func(c *gin.Context) {
|
||||
investigate.QueryHotelContacts()
|
||||
c.JSON(http.StatusOK, nil)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ func BusiRouter() {
|
||||
statisticRouter(publicRouter)
|
||||
articlePublicRouter(publicRouter)
|
||||
userPublicRouter(publicRouter)
|
||||
investigatePublicRouter(publicRouter)
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
27
service/investigate/faker.go
Normal file
27
service/investigate/faker.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package investigate
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"nCovTrack-Backend/global"
|
||||
"nCovTrack-Backend/models"
|
||||
"nCovTrack-Backend/utils"
|
||||
)
|
||||
|
||||
func fakerGetRequest(uri string) string {
|
||||
resStr := utils.GetWhioutHeader(global.FACKER_HOST + uri)
|
||||
var res utils.GinResponse
|
||||
_ = json.Unmarshal([]byte(resStr), &res)
|
||||
dataStr, _ := json.Marshal(res.Data)
|
||||
return string(dataStr)
|
||||
}
|
||||
|
||||
func QueryHotelContacts() {
|
||||
dataStr := fakerGetRequest("query/contacts/hotel/320581199103182689")
|
||||
var data []models.HotelContactRequest
|
||||
err := json.Unmarshal([]byte(dataStr), &data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(data)
|
||||
}
|
||||
1
service/investigate/investigate.go
Normal file
1
service/investigate/investigate.go
Normal file
@@ -0,0 +1 @@
|
||||
package investigate
|
||||
@@ -27,3 +27,8 @@ email:
|
||||
port: 587
|
||||
account: fallen-angle@foxmail.com
|
||||
password: hxrisxltxsjvieec
|
||||
|
||||
bos:
|
||||
accessKey: 90dbff87c5aa4bdbb0d7a29e130b2808
|
||||
secretKey: e53a672a10294abc8ecabe1ef92625b1
|
||||
domain: bj.bcebos.com
|
||||
|
||||
15
utils/bos.go
Normal file
15
utils/bos.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package utils
|
||||
|
||||
import "nCovTrack-Backend/global"
|
||||
|
||||
func UploadFile() string {
|
||||
etag, err := global.BosClient.PutObjectFromFile("ncovtrack", "test.jpg", "/home/fallen-angle/Pictures/Anime/pic-w-000003.jpg", nil)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return etag
|
||||
}
|
||||
|
||||
func DownloadLink() string {
|
||||
return global.BosClient.BasicGeneratePresignedUrl("ncovtrack", "test.jpg", 1800)
|
||||
}
|
||||
Reference in New Issue
Block a user