master
李光春 3 years ago
parent a0a164b063
commit e5922dbfac

@ -1,37 +0,0 @@
# This file is a template, and might need editing before it works on your project.
image: golang:latest
variables:
# Please edit to your GitLab project
REPO_NAME: gitlab.com/namespace/project
# The problem is that to be able to use go get, one needs to put
# the repository in the $GOPATH. So for example if your gitlab domain
# is gitlab.com, and that your repository is namespace/project, and
# the default GOPATH being /go, then you'd need to have your
# repository in /go/src/gitlab.com/namespace/project
# Thus, making a symbolic link corrects this.
before_script:
- mkdir -p $GOPATH/src/$(dirname $REPO_NAME)
- ln -svf $CI_PROJECT_DIR $GOPATH/src/$REPO_NAME
- cd $GOPATH/src/$REPO_NAME
stages:
- test
- build
- deploy
format:
stage: test
script:
- go fmt $(go list ./... | grep -v /vendor/)
- go vet $(go list ./... | grep -v /vendor/)
- go test -race $(go list ./... | grep -v /vendor/)
compile:
stage: build
script:
- go build -race -ldflags "-extldflags '-static'" -o $CI_PROJECT_DIR/mybinary
artifacts:
paths:
- mybinary

@ -1,13 +0,0 @@
# 使用vendor文件夹构建
export GO15VENDOREXPERIMENT=1
export GOPROXY=https://goproxy.cn,direct
# 在工作目录创建源文件夹
mkdir -p $GOPATH/src/dtapps/
# 拷贝代码到创建好的目录
cp -rf . $GOPATH/src/dtapps/
# 进入项目
cd $GOPATH/src/dtapps/
# 构建在GOPATH下生成构建包
go mod tidy
# 列出文件
ls -lh

@ -1,10 +0,0 @@
kind: pipeline
type: docker # 使用docker
name: default
steps:
- name: go-library
image: golang
commands:
- go mod tidy
- ls -lh

5
.gitignore vendored

@ -4,6 +4,5 @@
.idea
.vscode
*.log
git.sh
gittag.sh
*_test.go
*_test.go
gittag.sh

@ -1,29 +0,0 @@
---
stages:
- ".pre"
- build
- test
- deploy
- ".post"
build-job:
stage: build
script:
- echo "Compiling the code..."
- echo "Compile complete."
unit-test-job:
stage: test
script:
- echo "Running unit tests... This will take about 60 seconds."
- sleep 60
- echo "Code coverage is 90%"
lint-test-job:
stage: test
script:
- echo "Linting code... This will take about 10 seconds."
- sleep 10
- echo "No lint issues found."
deploy-job:
stage: deploy
script:
- echo "Deploying application..."
- echo "Application successfully deployed."

@ -1,8 +0,0 @@
language: go
go:
- master
script:
- go mod tidy
- ls -lh

@ -1,43 +0,0 @@
## v1.0.16 / 2021-06-07
- 增加文件/文件夹函数
## v1.0.14 / 2021-06-04
- 优化
- 增加go.mod
- 修复代码
## v1.0.11 / 2021-05-31
- 【优化】
## v1.0.10 / 2021-05-31
- 【优化】http
## v1.0.9 / 2021-05-31
- 【助手】增加http函数
## v1.0.8 / 2021-05-31
- 【助手】增加url函数
- 【助手】增加规则验证函数
- 【助手】优化md5函数
## v0.0.7 / 2021-05-31
- 【助手】增加请求函数
## v0.0.6 / 2021-05-29
- 【服务】修复拼多多参数
## v0.0.5 / 2021-05-29
- 增加拼多多联盟服务
## v0.0.4 / 2021-05-29
- 优化

@ -1,12 +0,0 @@
# These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

@ -1,62 +1,15 @@
<img width="100" src="https://kodo-cdn.dtapp.net/04/999e9f2f06d396968eacc10ce9bc8a.png" alt="www.dtapp.net"/>
<h1><a href="https://www.dtapp.net/">Golang扩展包</a></h1>
📦 Golang扩展包
[comment]: <> (dtapps)
[![GitHub Org's stars](https://img.shields.io/github/stars/dtapps)](https://github.com/dtapps)
[comment]: <> (go)
[![golang version](https://img.shields.io/badge/golang-%3E%3D1.6-8892BF.svg)](https://pkg.go.dev/github.com/dtapps/go-library)
[![godoc](https://pkg.go.dev/badge/github.com/dtapps/go-library?status.svg)](https://pkg.go.dev/github.com/dtapps/go-library)
[comment]: <> (goproxy.cn)
[![goproxy](https://goproxy.cn/stats/github.com/dtapps/go-library/badges/download-count.svg)](https://goproxy.cn/stats/github.com/dtapps/go-library)
[comment]: <> (goreportcard.com)
[![go report card](https://goreportcard.com/badge/github.com/dtapps/go-library)](https://goreportcard.com/report/github.com/dtapps/go-library)
[comment]: <> (github.com)
[![watchers](https://badgen.net/github/watchers/dtapps/go-library)](https://github.com/dtapps/go-library/watchers)
[![stars](https://badgen.net/github/stars/dtapps/go-library)](https://github.com/dtapps/go-library/stargazers)
[![forks](https://badgen.net/github/forks/dtapps/go-library)](https://github.com/dtapps/go-library/network/members)
[![issues](https://badgen.net/github/issues/dtapps/go-library)](https://github.com/dtapps/go-library/issues)
[![branches](https://badgen.net/github/branches/dtapps/go-library)](https://github.com/dtapps/go-library/branches)
[![releases](https://badgen.net/github/releases/dtapps/go-library)](https://github.com/dtapps/go-library/releases)
[![tags](https://badgen.net/github/tags/dtapps/go-library)](https://github.com/dtapps/go-library/tags)
[![license](https://badgen.net/github/license/dtapps/go-library)](https://github.com/dtapps/go-library/blob/master/LICENSE)
[![contributors](https://badgen.net/github/contributors/dtapps/go-library)](https://github.com/dtapps/go-library/CONTRIBUTING.md)
[![GitHub go.mod Go version (subdirectory of monorepo)](https://img.shields.io/github/go-mod/go-version/dtapps/go-library)](https://github.com/dtapps/go-library)
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/dtapps/go-library)](https://github.com/dtapps/go-library/releases)
[![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/dtapps/go-library)](https://github.com/dtapps/go-library/tags)
[![GitHub pull requests](https://img.shields.io/github/issues-pr/dtapps/go-library)](https://github.com/dtapps/go-library/pulls)
[![GitHub issues](https://img.shields.io/github/issues/dtapps/go-library)](https://github.com/dtapps/go-library/issues)
[![GitHub Sponsors](https://img.shields.io/github/sponsors/dtapps)](https://github.com/dtapps/go-library/FUNDING.yml)
[![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/dtapps/go-library)](https://github.com/dtapps/go-library)
[![GitHub language count](https://img.shields.io/github/languages/count/dtapps/go-library)](https://github.com/dtapps/go-library)
[![GitHub search hit counter](https://img.shields.io/github/search/dtapps/go-library/go)](https://github.com/dtapps/go-library)
[![GitHub top language](https://img.shields.io/github/languages/top/dtapps/go-library)](https://github.com/dtapps/go-library)
[comment]: <> (scrutinizer-ci.com)
[![Scrutinizer build (GitHub/Bitbucket)](https://img.shields.io/scrutinizer/build/g/dtapps/go-library/master)](https://scrutinizer-ci.com/g/dtapps/go-library)
[![Scrutinizer coverage (GitHub/BitBucket)](https://img.shields.io/scrutinizer/coverage/g/dtapps/go-library/master)](https://scrutinizer-ci.com/g/dtapps/go-library)
[![Scrutinizer code quality (GitHub/Bitbucket)](https://img.shields.io/scrutinizer/quality/g/dtapps/go-library/master)](https://scrutinizer-ci.com/g/dtapps/go-library)
[comment]: <> (www.travis-ci.com)
[![Travis (.com) branch](https://img.shields.io/travis/com/dtapps/go-library/master)](https://www.travis-ci.com/github/dtapps/go-library)
[comment]: <> (app.codecov.io)
[![Codecov branch](https://img.shields.io/codecov/c/github/dtapps/go-library/master)](https://app.codecov.io/gh/dtapps/go-library)
[comment]: <> (gitlab.com)
[![gitlab (.com)](https://gitlab.com/dtapps/go-library/badges/master/pipeline.svg)](https://gitlab.com/dtapps/go-library)
[comment]: <> (codechina.csdn.net)
[![codechina.csdn (.net)](https://codechina.csdn.net/dtapps/go-library/badges/master/pipeline.svg)](https://codechina.csdn.net/dtapps/go-library)
[![godoc](https://pkg.go.dev/badge/gitee.com/dtapps/go-library?status.svg)](https://pkg.go.dev/gitee.com/dtapps/go-library)
[![goproxy.cn](https://goproxy.cn/stats/gitee.com/dtapps/go-library/badges/download-count.svg)](https://goproxy.cn/stats/gitee.com/dtapps/go-library)
[![goreportcard.com](https://goreportcard.com/badge/gitee.com/dtapps/go-library)](https://goreportcard.com/report/gitee.com/dtapps/go-library)
[![deps.dev](https://img.shields.io/badge/deps-go-red.svg)](https://deps.dev/go/gitee.com%2Fdtapps%2Fgo-library)
## Install
```Importing
go get github.com/dtapps/go-library
go get gitee.com/dtapps/go-library
```

@ -1,19 +0,0 @@
- name: GoLang Test
# You may pin to the exact commit or the version.
# uses: n8maninger/action-golang-test@a8263fc1a85b63937b1b365946518675ceab5740
uses: n8maninger/action-golang-test@v1
with:
# the package to run the tests for
package: # optional, default is ./...
# additional go test command line arguments, individual arguments should be separated by ';'
args: # optional, default is
# outputs a warning for long running tests, -1 to disable
show-long-running-tests: # optional, default is 30
# includes package output in the parsed output
show-package-output: # optional
# shows tests that were run and passed
show-passed-tests: # optional
# shows the unparsed std-out from go test instead of the parsed output
show-stdout: # optional
# skips installing and setting up Go, useful for defining additional parameters for actions/setup-go
skip-go-install: # optional

@ -1,4 +1,4 @@
module github.com/dtapps/go-library
module gitee.com/dtapps/go-library
go 1.16

@ -2,8 +2,8 @@ package http
import (
"encoding/json"
"gitee.com/dtapps/go-library/helper/request"
"github.com/bitly/go-simplejson"
"github.com/dtapps/go-library/helper/request"
"gopkg.in/h2non/gentleman.v2"
"gopkg.in/h2non/gentleman.v2/plugins/body"
)

@ -2,7 +2,7 @@ package uuid_test
import (
"fmt"
"github.com/dtapps/go-library/helper/uuid"
"gitee.com/dtapps/go-library/helper/uuid"
"testing"
)

@ -0,0 +1,5 @@
package library
func Version() string {
return "1.0.18"
}

@ -1 +1,196 @@
package baidubce
import (
"bytes"
"crypto/md5"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
time2 "gitee.com/dtapps/go-library/helper/time"
"gitee.com/dtapps/go-library/helper/uuid"
"gitee.com/dtapps/go-library/service"
"github.com/bitly/go-simplejson"
"github.com/nilorg/sdk/convert"
"io"
"io/ioutil"
"net/http"
"net/url"
"sort"
"strconv"
"strings"
"time"
)
var (
// AccessKeyId 应用Key
AccessKeyId string
// SecretAccessKey 秘密
SecretAccessKey string
// Router 环境请求地址
Router = "http://cdn.baidubce.com"
// Timeout ...
Timeout time.Duration
)
// Parameter 参数
type Parameter map[string]interface{}
// ParameterJsonEncode 参数
type ParameterJsonEncode []string
// copyParameter 复制参数
func copyParameter(srcParams Parameter) Parameter {
newParams := make(Parameter)
for key, value := range srcParams {
newParams[key] = value
}
return newParams
}
// execute 执行API接口
func execute(method string, url string, param Parameter) (bytes []byte, err error) {
err = checkConfig()
if err != nil {
return
}
//Authorization := auth.GetAuthorizationV2(AccessKeyId, SecretAccessKey, "guangdong", "drcdn", method, url, param.getRequestData(), "")
//fmt.Printf("Authorization%#v\n", Authorization)
var req *http.Request
req, err = http.NewRequest(method, Router, strings.NewReader(param.getRequestData()))
if err != nil {
return
}
//req.Header.Add("Authorization", Authorization)
req.Header.Add("x-bce-date", time2.GetCurrentDate())
req.Header.Add("x-bce-request-id", uuid.GenUUID())
req.Header.Add("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")
httpClient := &http.Client{}
httpClient.Timeout = Timeout
var response *http.Response
response, err = httpClient.Do(req)
if err != nil {
return
}
fmt.Printf("Body%#v\n", response.Body)
if response.StatusCode != 200 {
err = fmt.Errorf("请求错误:%d", response.StatusCode)
return
}
defer response.Body.Close()
bytes, err = ioutil.ReadAll(response.Body)
return
}
// Execute 执行API接口
func Execute(method string, url string, param Parameter) (res *simplejson.Json, err error) {
// 更新参数
param.setRequestData()
var bodyBytes []byte
bodyBytes, err = execute(method, url, param)
if err != nil {
return
}
return bytesToResult(bodyBytes)
}
func bytesToResult(bytes []byte) (res *simplejson.Json, err error) {
res, err = simplejson.NewJson(bytes)
if err != nil {
return
}
if responseError, ok := res.CheckGet("error_response"); ok {
if subMsg, subOk := responseError.CheckGet("sub_msg"); subOk {
err = errors.New(subMsg.MustString())
} else {
err = errors.New(responseError.Get("msg").MustString())
}
res = nil
}
return
}
// 检查配置
func checkConfig() error {
if AccessKeyId == "" {
return errors.New("AccessKeyId 不能为空")
}
if SecretAccessKey == "" {
return errors.New("SecretAccessKey 不能为空")
}
if Router == "" {
return errors.New("Router 不能为空")
}
return nil
}
func (p Parameter) setRequestData() {
hh, _ := time.ParseDuration("8h")
loc := time.Now().UTC().Add(hh)
p["timestamp"] = strconv.FormatInt(loc.Unix(), 10)
p["client_id"] = AccessKeyId
p["data_type"] = "JSON"
p["version"] = "v1"
// 设置签名
p["sign"] = getSign(p)
}
// 获取请求数据
func (p Parameter) getRequestData() string {
// 公共参数
args := url.Values{}
// 请求参数
for key, val := range p {
args.Set(key, interfaceToString(val))
}
return args.Encode()
}
// 获取签名
func getSign(params Parameter) string {
// 获取Key
keys := []string{}
for k := range params {
keys = append(keys, k)
}
// 排序asc
sort.Strings(keys)
// 把所有参数名和参数值串在一起
query := bytes.NewBufferString(SecretAccessKey)
for _, k := range keys {
query.WriteString(k)
query.WriteString(interfaceToString(params[k]))
}
query.WriteString(SecretAccessKey)
// 使用MD5加密
h := md5.New()
io.Copy(h, query)
// 把二进制转化为大写的十六进制
return strings.ToUpper(hex.EncodeToString(h.Sum(nil)))
}
func interfaceToString(src interface{}) string {
if src == nil {
panic(service.ErrTypeIsNil)
}
switch src.(type) {
case string:
return src.(string)
case int, int8, int32, int64:
case uint8, uint16, uint32, uint64:
case float32, float64:
return convert.ToString(src)
}
data, err := json.Marshal(src)
if err != nil {
panic(err)
}
return string(data)
}

@ -7,8 +7,8 @@ import (
"encoding/json"
"errors"
"fmt"
"gitee.com/dtapps/go-library/service"
"github.com/bitly/go-simplejson"
"github.com/dtapps/go-library/service"
"github.com/nilorg/sdk/convert"
"io"
"io/ioutil"

@ -7,8 +7,8 @@ import (
"encoding/json"
"errors"
"fmt"
"gitee.com/dtapps/go-library/service"
"github.com/bitly/go-simplejson"
"github.com/dtapps/go-library/service"
"github.com/nilorg/sdk/convert"
"io"
"io/ioutil"

@ -7,8 +7,8 @@ import (
"encoding/json"
"errors"
"fmt"
"gitee.com/dtapps/go-library/service"
"github.com/bitly/go-simplejson"
"github.com/dtapps/go-library/service"
"github.com/nilorg/sdk/convert"
"io"
"io/ioutil"

Loading…
Cancel
Save