Skip to content

Commit

Permalink
🎨 Improve project directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jweboy committed Dec 19, 2018
1 parent 9040e34 commit 3499773
Show file tree
Hide file tree
Showing 848 changed files with 387,066 additions and 1,694 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
files/
log/
.vendor/
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
- docker
language: go
go:
- 1.10.3
- 1.11.2
install: true

before_install:
Expand All @@ -19,8 +19,8 @@ script:

branches:
only:
# - deploy
- master
- deploy
# - master
addons:
ssh_known_hosts:
- 118.24.155.105
Expand Down
2 changes: 1 addition & 1 deletion handler/handler.go → api/api.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package handler
package api

import (
"net/http"
Expand Down
3 changes: 2 additions & 1 deletion handler/qiniu/create-file.go → api/qiniu/create-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"os"

"github.com/gin-gonic/gin"
. "github.com/jweboy/api-server/handler"
. "github.com/jweboy/api-server/api"
"github.com/jweboy/api-server/model"
"github.com/jweboy/api-server/pkg/errno"
"github.com/qiniu/api.v7/storage"
Expand All @@ -25,6 +25,7 @@ import (
func UploadFile(c *gin.Context) {
// TODO: 文件大小需要作限制
// TODO: 请求参数校验整理
// TODO: 文件上传改为字节或者数据 https://gist.github.com/ZenGround0/49e4a1aa126736f966a1dfdcb84abdae

bucket := c.Param("bucket")
if bucket == "" {
Expand Down
12 changes: 9 additions & 3 deletions handler/qiniu/delete-file.go → api/qiniu/delete-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import (
"fmt"
"strconv"

"github.com/jweboy/api-server/pkg/setting"

"github.com/gin-gonic/gin"
. "github.com/jweboy/api-server/handler"
. "github.com/jweboy/api-server/api"
"github.com/jweboy/api-server/model"
"github.com/jweboy/api-server/pkg/errno"
"github.com/qiniu/api.v7/auth/qbox"
"github.com/qiniu/api.v7/storage"
log "qiniupkg.com/x/log.v7"
)

// TODO: 请求字段比较繁琐需要优化

// Query 删除文件Query请求参数
type Query struct {
Bucket string `form:"bucket"`
Expand Down Expand Up @@ -41,8 +45,10 @@ func DeleteFile(c *gin.Context) {
}

// 删除七牛云指定文件
accessKey, secretKey := getKeys()
mac := qbox.NewMac(accessKey, secretKey)
mac := qbox.NewMac(
setting.QiniuSetting.AccessKey,
setting.QiniuSetting.SecretKey,
)
cfg := storage.Config{}
bucketManager := storage.NewBucketManager(mac, &cfg)
if err := bucketManager.Delete(query.Bucket, query.Name); err != nil {
Expand Down
15 changes: 10 additions & 5 deletions handler/qiniu/list-bucket.go → api/qiniu/list-bucket.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package qiniu

import (
"fmt"

"github.com/jweboy/api-server/pkg/setting"

"github.com/gin-gonic/gin"
. "github.com/jweboy/api-server/handler"
. "github.com/jweboy/api-server/api"
"github.com/jweboy/api-server/pkg/errno"
"github.com/qiniu/api.v7/auth/qbox"
"github.com/qiniu/api.v7/storage"
Expand All @@ -17,11 +21,11 @@ import (
// @Router /qiniu/bucket [get]
// @Success 200 {object} handler.Response "{"code":0,"message":"ok", "data": []}"
func ListBucket(c *gin.Context) {
// get keys
accessKey, secretKey := getKeys()

// new qbox mac
mac := qbox.NewMac(accessKey, secretKey)
mac := qbox.NewMac(
setting.QiniuSetting.AccessKey,
setting.QiniuSetting.SecretKey,
)

// set default storage config => default http
cfg := storage.Config{}
Expand All @@ -34,6 +38,7 @@ func ListBucket(c *gin.Context) {
buckets, err := bucketManger.Buckets(true)

if err != nil {
fmt.Print(err, accessKey, secretKey)
SendResponse(c, errno.ErrListBucketError, nil)
return
}
Expand Down
2 changes: 1 addition & 1 deletion handler/qiniu/list-file.go → api/qiniu/list-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package qiniu

import (
"github.com/gin-gonic/gin"
. "github.com/jweboy/api-server/handler"
. "github.com/jweboy/api-server/api"
"github.com/jweboy/api-server/model"
"github.com/jweboy/api-server/pkg/errno"
)
Expand Down
17 changes: 12 additions & 5 deletions handler/qiniu/qiniu.go → api/qiniu/qiniu.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package qiniu

import (
"github.com/jweboy/api-server/pkg/setting"
"github.com/qiniu/api.v7/auth/qbox"
"github.com/qiniu/api.v7/storage"
"github.com/spf13/viper"
)

var (
accessKey = setting.QiniuSetting.AccessKey
secretKey = setting.QiniuSetting.SecretKey
AccessKey = setting.QiniuSetting.AccessKey
// secretKey = setting.QiniuSetting.SecretKey
)

func getKeys() (string, string) {
accessKey := viper.GetString("qiniu.accessKey")
secretKey := viper.GetString("qiniu.secretKey")
return accessKey, secretKey
}

func getToken(bucket string) string {
accessKey, secretKey := getKeys()
// get mac
mac := qbox.NewMac(accessKey, secretKey)
mac := qbox.NewMac(
setting.QiniuSetting.AccessKey,
setting.QiniuSetting.SecretKey,
)
// get policy
putPolicy := storage.PutPolicy{
Scope: bucket,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions conf/app.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[app]
PageSize = 10


[server]
# debug or release
RunMode = debug
HTTPPort = 4000
ReadTimeout = 60
WriteTimeout = 60

[database]
Type = mysql
User = jl
Password = Jl940630.
Host = 118.24.155.105:3306
Name = dev_db
TablePrefix = blog_
Gormlog = true
SetMaxOpenConns = 2000
SetMaxIdleConns = 0

[qiniu]
AccessKey = KgNS98Sj66CuXFi64xNHs11vfrO8iXmX8Zcht-Id
SecretKey = gohLJusvDqZcwwYaL_DcF-KeTDX65zDdEzaEyayP
Expires = 7200
75 changes: 0 additions & 75 deletions config/config.go

This file was deleted.

7 changes: 0 additions & 7 deletions cover.out

This file was deleted.

Binary file removed cpu.profile
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file removed files/2018-08-06 22-23-19 的屏幕截图.png
Binary file not shown.
Binary file removed files/2018-08-19 11-50-17 的屏幕截图.png
Binary file not shown.
Binary file added files/Autumn_in_Kanas_by_Wang_Jinyu.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed files/【个人周报】蒋磊-20181020.xls
Binary file not shown.
Binary file removed id_rsa.enc
Binary file not shown.
Loading

0 comments on commit 3499773

Please sign in to comment.