-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gocloudcoder
committed
Apr 20, 2021
1 parent
2477b44
commit bc26b37
Showing
31 changed files
with
608 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,3 +132,7 @@ qn put -w test1.png test2.png | |
- [x] 支持通配符(批量传入) | ||
|
||
- [ ] 改进路径问题(去除路径中的空格) | ||
|
||
## 更新 | ||
|
||
* 4.20 可将网络上的文件上传到七牛中 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
Copyright © 2021 NAME HERE <EMAIL ADDRESS> | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/qiniu/api.v7/v7/auth/qbox" | ||
"github.com/qiniu/api.v7/v7/storage" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"os" | ||
) | ||
|
||
// fetchCmd represents the fetch command | ||
var fetchCmd = &cobra.Command{ | ||
Use: "fetch", | ||
Short: "A brief description of your command", | ||
Long: `A longer description that spans multiple lines and likely contains examples | ||
and usage of using your command. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
Run: fetch, | ||
} | ||
|
||
func fetch(cmd *cobra.Command, params []string) { | ||
remoteUrl := params[0] | ||
accessKey := viper.GetString("ak") | ||
secretKey := viper.GetString("sk") | ||
bucket := viper.GetString("bucket") | ||
if accessKey == "" || secretKey == "" || bucket == "" { | ||
fmt.Println("请设置ak, sk, bucket") | ||
os.Exit(0) | ||
} | ||
|
||
mac := qbox.NewMac(accessKey, secretKey) | ||
cfg := storage.Config{ | ||
ApiHost:"http://api.qiniu.com", | ||
} | ||
bm := storage.NewBucketManager(mac, &cfg) | ||
res, err := bm.Fetch(remoteUrl, bucket, "test123456.png") | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
fmt.Println(res.Key) | ||
|
||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(fetchCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// fetchCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// fetchCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
mysql: | ||
ip: "localhost" | ||
ip: "gocloudcoder.com" | ||
port: "3306" | ||
username: "qn-server" | ||
database: "qn-server" | ||
password: "000000" | ||
|
||
qiniu: | ||
ak: "" | ||
sk: "" | ||
bucket: "" | ||
ak: "zM_pCg7E1kBvwD0DlGQUadtxVGkumuKNQIDVI4Nl" | ||
sk: "P2mdTgHaJ7PPX7cggzpBHti-VKppSh-Mqkj-hWeO" | ||
bucket: "pic-gocloudcoder" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package controllers | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
"qn/server/models" | ||
"qn/server/service" | ||
) | ||
|
||
func QueryAllLogin(c *gin.Context) { | ||
allLogin := service.QueryLogin() | ||
c.IndentedJSON(200, allLogin) | ||
} | ||
|
||
// @Summary 登录接口 | ||
// @Produce json | ||
// @Param username query string true "登录名" | ||
// @Param password query string true "密码" | ||
// @Header | ||
// @Router /api/v2/trueLogin [post] | ||
func TrueLogin(c *gin.Context) { | ||
username := c.PostForm("username") | ||
password := c.PostForm("password") | ||
fmt.Println(username) | ||
fmt.Println(password) | ||
tokenString, err := service.TrueLogin(username, password) | ||
if err != nil { | ||
c.IndentedJSON(200, models.NewLoginErr()) | ||
} else { | ||
c.IndentedJSON(http.StatusOK, gin.H{ | ||
"code": 20000, | ||
"token": tokenString, | ||
}) | ||
} | ||
} | ||
|
||
|
||
// @Summary 注册接口 | ||
// @Produce json | ||
// @Param username query string true "用户名" | ||
// @Param password query string true "密码" | ||
// @Success 200 {} json "{"code":200, "msg":"success add user"}" | ||
// @Failure 401 {} json "{"code":401, "msg":"add user error"}" | ||
// @Router /api/v2/login/add [post] | ||
func PostLogin(c *gin.Context) { | ||
username := c.PostForm("username") | ||
password := c.PostForm("password") | ||
status := service.PostLogin(username, password) | ||
if status == 200 { | ||
c.IndentedJSON(http.StatusOK, gin.H{ | ||
"code" : 200, | ||
"message" : "success add user", | ||
}) | ||
} else { | ||
c.IndentedJSON(http.StatusOK, models.NewUserHasExistedErr(username)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.