Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bwallet
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Go
bwallet
Commits
02f90c5a
Commit
02f90c5a
authored
Dec 25, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
648438c7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
37 deletions
+68
-37
excel.go
pkg/export/excel.go
+0
-20
setting.go
pkg/setting/setting.go
+5
-4
upload.go
routers/api/upload.go
+9
-0
upload.go
routers/api/v1/upload.go
+50
-11
router.go
routers/router.go
+4
-2
No files found.
pkg/export/excel.go
deleted
100644 → 0
View file @
648438c7
package
export
import
"bwallet/pkg/setting"
const
EXT
=
".xlsx"
// GetExcelFullUrl get the full access path of the Excel file
func
GetExcelFullUrl
(
name
string
)
string
{
return
setting
.
AppSetting
.
PrefixUrl
+
"/"
+
GetExcelPath
()
+
name
}
// GetExcelPath get the relative save path of the Excel file
func
GetExcelPath
()
string
{
return
setting
.
AppSetting
.
ExportSavePath
}
// GetExcelFullPath Get the full save path of the Excel file
func
GetExcelFullPath
()
string
{
return
setting
.
AppSetting
.
RuntimeRootPath
+
GetExcelPath
()
}
pkg/setting/setting.go
View file @
02f90c5a
...
@@ -10,7 +10,7 @@ import (
...
@@ -10,7 +10,7 @@ import (
type
App
struct
{
type
App
struct
{
JwtSecret
string
JwtSecret
string
PageSize
int
PageSize
int
Timeout
int
Timeout
int
PrefixUrl
string
PrefixUrl
string
RuntimeRootPath
string
RuntimeRootPath
string
...
@@ -62,10 +62,10 @@ type Redis struct {
...
@@ -62,10 +62,10 @@ type Redis struct {
var
RedisSetting
=
&
Redis
{}
var
RedisSetting
=
&
Redis
{}
type
Oss
struct
{
type
Oss
struct
{
AccessKeyId
string
AccessKeyId
string
AccessKeySecret
string
AccessKeySecret
string
Endpoint
string
Endpoint
string
Bucket
string
Bucket
string
}
}
var
OssSetting
=
&
Oss
{}
var
OssSetting
=
&
Oss
{}
...
@@ -84,6 +84,7 @@ func Setup() {
...
@@ -84,6 +84,7 @@ func Setup() {
mapTo
(
"server"
,
ServerSetting
)
mapTo
(
"server"
,
ServerSetting
)
mapTo
(
"database"
,
DatabaseSetting
)
mapTo
(
"database"
,
DatabaseSetting
)
mapTo
(
"redis"
,
RedisSetting
)
mapTo
(
"redis"
,
RedisSetting
)
mapTo
(
"oss"
,
OssSetting
)
AppSetting
.
ImageMaxSize
=
AppSetting
.
ImageMaxSize
*
1024
*
1024
AppSetting
.
ImageMaxSize
=
AppSetting
.
ImageMaxSize
*
1024
*
1024
ServerSetting
.
ReadTimeout
=
ServerSetting
.
ReadTimeout
*
time
.
Second
ServerSetting
.
ReadTimeout
=
ServerSetting
.
ReadTimeout
*
time
.
Second
...
...
routers/api/upload.go
View file @
02f90c5a
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"bwallet/pkg/e"
"bwallet/pkg/e"
"bwallet/pkg/logging"
"bwallet/pkg/logging"
"bwallet/pkg/upload"
"bwallet/pkg/upload"
"fmt"
)
)
// @Summary Import Image
// @Summary Import Image
...
@@ -36,6 +37,12 @@ func UploadImage(c *gin.Context) {
...
@@ -36,6 +37,12 @@ func UploadImage(c *gin.Context) {
savePath
:=
upload
.
GetImagePath
()
savePath
:=
upload
.
GetImagePath
()
src
:=
fullPath
+
imageName
src
:=
fullPath
+
imageName
//fmt.Println(imageName)
//fmt.Println(fullPath)
//fmt.Println(savePath)
//fmt.Println(src)
//os.Exit(0)
if
!
upload
.
CheckImageExt
(
imageName
)
||
!
upload
.
CheckImageSize
(
file
)
{
if
!
upload
.
CheckImageExt
(
imageName
)
||
!
upload
.
CheckImageSize
(
file
)
{
appG
.
Response
(
http
.
StatusBadRequest
,
e
.
ERROR_UPLOAD_CHECK_IMAGE_FORMAT
,
nil
)
appG
.
Response
(
http
.
StatusBadRequest
,
e
.
ERROR_UPLOAD_CHECK_IMAGE_FORMAT
,
nil
)
return
return
...
@@ -54,6 +61,8 @@ func UploadImage(c *gin.Context) {
...
@@ -54,6 +61,8 @@ func UploadImage(c *gin.Context) {
return
return
}
}
fmt
.
Println
(
upload
.
GetImageFullUrl
(
imageName
))
fmt
.
Println
(
savePath
+
imageName
)
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
map
[
string
]
string
{
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
map
[
string
]
string
{
"image_url"
:
upload
.
GetImageFullUrl
(
imageName
),
"image_url"
:
upload
.
GetImageFullUrl
(
imageName
),
"image_save_url"
:
savePath
+
imageName
,
"image_save_url"
:
savePath
+
imageName
,
...
...
routers/api/v1/upload.go
View file @
02f90c5a
...
@@ -6,13 +6,19 @@ import (
...
@@ -6,13 +6,19 @@ import (
"bwallet/pkg/app"
"bwallet/pkg/app"
"bwallet/pkg/e"
"bwallet/pkg/e"
"bwallet/pkg/setting"
"bwallet/pkg/setting"
"bwallet/pkg/upload"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
"fmt"
"fmt"
"os"
)
)
func
Upload
Image
(
c
*
gin
.
Context
)
{
func
Upload
(
c
*
gin
.
Context
)
{
appG
:=
app
.
Gin
{
C
:
c
}
appG
:=
app
.
Gin
{
C
:
c
}
accessKeyId
:=
setting
.
OssSetting
.
AccessKeyId
accessKeySecret
:=
setting
.
OssSetting
.
AccessKeySecret
endpoint
:=
setting
.
OssSetting
.
Endpoint
bucketName
:=
setting
.
OssSetting
.
Bucket
file
,
image
,
err
:=
c
.
Request
.
FormFile
(
"image"
)
file
,
image
,
err
:=
c
.
Request
.
FormFile
(
"image"
)
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR
,
nil
)
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR
,
nil
)
...
@@ -24,19 +30,52 @@ func UploadImage(c *gin.Context) {
...
@@ -24,19 +30,52 @@ func UploadImage(c *gin.Context) {
return
return
}
}
accessKeyId
:=
setting
.
OssSetting
.
AccessKeyId
imageName
:=
upload
.
GetImageName
(
image
.
Filename
)
accessKeySecret
:=
setting
.
OssSetting
.
AccessKeySecret
fullPath
:=
upload
.
GetImageFullPath
()
endpoint
:=
setting
.
OssSetting
.
Endpoint
//savePath := upload.GetImagePath()
//bucket := setting.OssSetting.Bucket
src
:=
fullPath
+
imageName
if
!
upload
.
CheckImageExt
(
imageName
)
||
!
upload
.
CheckImageSize
(
file
)
{
appG
.
Response
(
http
.
StatusBadRequest
,
e
.
ERROR_UPLOAD_CHECK_IMAGE_FORMAT
,
nil
)
return
}
err
=
upload
.
CheckImage
(
fullPath
)
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_UPLOAD_CHECK_IMAGE_FAIL
,
nil
)
return
}
if
err
:=
c
.
SaveUploadedFile
(
image
,
src
);
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_UPLOAD_SAVE_IMAGE_FAIL
,
nil
)
return
}
client
,
err
:=
oss
.
New
(
endpoint
,
accessKeyId
,
accessKeySecret
)
client
,
err
:=
oss
.
New
(
endpoint
,
accessKeyId
,
accessKeySecret
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
Exit
(
0
)
appG
.
Response
(
http
.
StatusBadRequest
,
e
.
INVALID_PARAMS
,
nil
)
appG
.
Response
(
http
.
StatusBadRequest
,
e
.
INVALID_PARAMS
,
nil
)
return
return
}
}
fmt
.
Println
(
client
)
os
.
Exit
(
0
)
bucket
,
err
:=
client
.
Bucket
(
bucketName
)
return
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusBadRequest
,
e
.
INVALID_PARAMS
,
nil
)
return
}
uploaddir
:=
"upload/test"
objectName
:=
fmt
.
Sprintf
(
"%s/%s"
,
uploaddir
,
imageName
)
//完整的oss路径
err
=
bucket
.
PutObjectFromFile
(
objectName
,
upload
.
GetImageFullUrl
(
imageName
))
if
err
!=
nil
{
fmt
.
Println
(
"aaaaaa"
)
fmt
.
Println
(
err
)
return
}
var
resultfile
=
objectName
fmt
.
Println
(
imageName
)
fmt
.
Println
(
resultfile
)
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
map
[
string
]
string
{
"image_url"
:
resultfile
,
"image_name"
:
imageName
,
})
}
}
routers/router.go
View file @
02f90c5a
...
@@ -6,6 +6,8 @@ import (
...
@@ -6,6 +6,8 @@ import (
"bwallet/routers/api"
"bwallet/routers/api"
"bwallet/routers/api/v1"
"bwallet/routers/api/v1"
"bwallet/middleware/auth"
"bwallet/middleware/auth"
"net/http"
"bwallet/pkg/upload"
)
)
func
InitRouter
()
*
gin
.
Engine
{
func
InitRouter
()
*
gin
.
Engine
{
...
@@ -15,7 +17,7 @@ func InitRouter() *gin.Engine {
...
@@ -15,7 +17,7 @@ func InitRouter() *gin.Engine {
r
.
Use
(
gin
.
Recovery
())
r
.
Use
(
gin
.
Recovery
())
//
r.StaticFS("/upload/images", http.Dir(upload.GetImageFullPath()))
r
.
StaticFS
(
"/upload/images"
,
http
.
Dir
(
upload
.
GetImageFullPath
()))
//r.StaticFS("/qrcode", http.Dir(qrcode.GetQrCodeFullPath()))
//r.StaticFS("/qrcode", http.Dir(qrcode.GetQrCodeFullPath()))
r
.
POST
(
"/auth"
,
api
.
GetAuth
)
r
.
POST
(
"/auth"
,
api
.
GetAuth
)
...
@@ -25,7 +27,7 @@ func InitRouter() *gin.Engine {
...
@@ -25,7 +27,7 @@ func InitRouter() *gin.Engine {
api
.
Use
(
auth
.
AUTH
())
api
.
Use
(
auth
.
AUTH
())
{
{
api
.
POST
(
"/upload"
,
v1
.
UploadImage
)
//api.POST("/upload",v1.Upload
)
api
.
GET
(
"/coins"
,
v1
.
GetCoins
)
api
.
GET
(
"/coins"
,
v1
.
GetCoins
)
api
.
POST
(
"/coin"
,
v1
.
AddCoin
)
api
.
POST
(
"/coin"
,
v1
.
AddCoin
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment