reorg imports

This commit is contained in:
kevin
2020-08-09 14:03:37 +08:00
parent 18a80efd70
commit 8094ebd876
21 changed files with 2 additions and 535 deletions

View File

@@ -10,7 +10,6 @@ import (
"github.com/tal-tech/go-zero/core/lang"
"github.com/tal-tech/go-zero/core/threading"
"gopkg.in/cheggaaa/pb.v1"
)

View File

@@ -1,11 +0,0 @@
seconds,goodOk,goodFail,goodReject,goodErrs,goodUnknowns,goodDropRatio,heavyOk,heavyFail,heavyReject,heavyErrs,heavyUnknowns,heavyDropRatio
1,172,0,0,0,0,0.0,159,0,0,0,0,0.0
2,598,0,0,0,0,0.0,591,0,0,0,0,0.0
3,583,0,0,0,0,0.0,631,0,0,0,0,0.0
4,3,0,0,0,0,0.0,2,0,0,0,0,0.0
5,17,0,0,17,0,0.0,17,0,0,16,0,0.0
6,27,0,0,1,0,0.0,21,0,0,1,0,0.0
7,81,0,0,4,0,0.0,93,0,0,3,0,0.0
8,349,0,0,39,0,0.0,325,0,0,40,0,0.0
9,337,0,0,35,0,0.0,335,0,0,34,0,0.0
10,76,0,0,42,0,0.0,73,0,0,42,0,0.0
1 seconds goodOk goodFail goodReject goodErrs goodUnknowns goodDropRatio heavyOk heavyFail heavyReject heavyErrs heavyUnknowns heavyDropRatio
2 1 172 0 0 0 0 0.0 159 0 0 0 0 0.0
3 2 598 0 0 0 0 0.0 591 0 0 0 0 0.0
4 3 583 0 0 0 0 0.0 631 0 0 0 0 0.0
5 4 3 0 0 0 0 0.0 2 0 0 0 0 0.0
6 5 17 0 0 17 0 0.0 17 0 0 16 0 0.0
7 6 27 0 0 1 0 0.0 21 0 0 1 0 0.0
8 7 81 0 0 4 0 0.0 93 0 0 3 0 0.0
9 8 349 0 0 39 0 0.0 325 0 0 40 0 0.0
10 9 337 0 0 35 0 0.0 335 0 0 34 0 0.0
11 10 76 0 0 42 0 0.0 73 0 0 42 0 0.0

View File

@@ -1,56 +0,0 @@
package main
import (
"fmt"
"log"
"github.com/tal-tech/go-zero/core/codec"
)
const (
pubKey = `-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD7bq4FLG0ctccbEFEsUBuRxkjE
eJ5U+0CAEjJk20V9/u2Fu76i1oKoShCs7GXtAFbDb5A/ImIXkPY62nAaxTGK4KVH
miYbRgh5Fy6336KepLCtCmV/r0PKZeCyJH9uYLs7EuE1z9Hgm5UUjmpHDhJtkAwR
my47YlhspwszKdRP+wIDAQAB
-----END PUBLIC KEY-----`
body = "hello"
)
var key = []byte("q4t7w!z%C*F-JaNdRgUjXn2r5u8x/A?D")
func main() {
encrypter, err := codec.NewRsaEncrypter([]byte(pubKey))
if err != nil {
log.Fatal(err)
}
decrypter, err := codec.NewRsaDecrypter("private.pem")
if err != nil {
log.Fatal(err)
}
output, err := encrypter.Encrypt([]byte(body))
if err != nil {
log.Fatal(err)
}
actual, err := decrypter.Decrypt(output)
if err != nil {
log.Fatal(err)
}
fmt.Println(actual)
out, err := codec.EcbEncrypt(key, []byte(body))
if err != nil {
log.Fatal(err)
}
ret, err := codec.EcbDecrypt(key, out)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(ret))
}

View File

@@ -1,113 +0,0 @@
package main
import (
"crypto/hmac"
"crypto/md5"
"crypto/sha256"
"encoding/base64"
"flag"
"fmt"
"io"
"log"
"net/http"
"os"
"strconv"
"strings"
"time"
"github.com/tal-tech/go-zero/core/codec"
)
const pubKey = `-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD7bq4FLG0ctccbEFEsUBuRxkjE
eJ5U+0CAEjJk20V9/u2Fu76i1oKoShCs7GXtAFbDb5A/ImIXkPY62nAaxTGK4KVH
miYbRgh5Fy6336KepLCtCmV/r0PKZeCyJH9uYLs7EuE1z9Hgm5UUjmpHDhJtkAwR
my47YlhspwszKdRP+wIDAQAB
-----END PUBLIC KEY-----`
var (
crypt = flag.Bool("crypt", false, "encrypt body or not")
key = []byte("q4t7w!z%C*F-JaNdRgUjXn2r5u8x/A?D")
)
func fingerprint(key string) string {
h := md5.New()
io.WriteString(h, key)
return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
func hs256(key []byte, body string) string {
h := hmac.New(sha256.New, key)
io.WriteString(h, body)
return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
func main() {
flag.Parse()
var err error
body := "hello world!"
if *crypt {
bodyBytes, err := codec.EcbEncrypt(key, []byte(body))
if err != nil {
log.Fatal(err)
}
body = base64.StdEncoding.EncodeToString(bodyBytes)
}
r, err := http.NewRequest(http.MethodPost, "http://localhost:3333/a/b?c=first&d=second", strings.NewReader(body))
if err != nil {
log.Fatal(err)
}
timestamp := time.Now().Unix()
sha := sha256.New()
sha.Write([]byte(body))
bodySign := fmt.Sprintf("%x", sha.Sum(nil))
contentOfSign := strings.Join([]string{
strconv.FormatInt(timestamp, 10),
http.MethodPost,
r.URL.Path,
r.URL.RawQuery,
bodySign,
}, "\n")
sign := hs256(key, contentOfSign)
var mode string
if *crypt {
mode = "1"
} else {
mode = "0"
}
content := strings.Join([]string{
"version=v1",
"type=" + mode,
fmt.Sprintf("key=%s", base64.StdEncoding.EncodeToString(key)),
"time=" + strconv.FormatInt(timestamp, 10),
}, "; ")
encrypter, err := codec.NewRsaEncrypter([]byte(pubKey))
if err != nil {
log.Fatal(err)
}
output, err := encrypter.Encrypt([]byte(content))
if err != nil {
log.Fatal(err)
}
encryptedContent := base64.StdEncoding.EncodeToString(output)
r.Header.Set("X-Content-Security", strings.Join([]string{
fmt.Sprintf("key=%s", fingerprint(pubKey)),
"secret=" + encryptedContent,
"signature=" + sign,
}, "; "))
client := &http.Client{}
resp, err := client.Do(r)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
fmt.Println(resp.Status)
io.Copy(os.Stdout, resp.Body)
}

View File

@@ -1,59 +0,0 @@
package main
import (
"flag"
"io"
"net/http"
"github.com/tal-tech/go-zero/core/logx"
"github.com/tal-tech/go-zero/core/service"
"github.com/tal-tech/go-zero/rest"
"github.com/tal-tech/go-zero/rest/httpx"
)
var keyPem = flag.String("prikey", "private.pem", "the private key file")
type Request struct {
User string `form:"user,optional"`
}
func handle(w http.ResponseWriter, r *http.Request) {
var req Request
err := httpx.Parse(r, &req)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
io.Copy(w, r.Body)
}
func main() {
flag.Parse()
engine := rest.MustNewServer(rest.RestConf{
ServiceConf: service.ServiceConf{
Log: logx.LogConf{
Path: "logs",
},
},
Port: 3333,
Signature: rest.SignatureConf{
Strict: true,
PrivateKeys: []rest.PrivateKeyConf{
{
Fingerprint: "bvw8YlnSqb+PoMf3MBbLdQ==",
KeyFile: *keyPem,
},
},
},
})
defer engine.Stop()
engine.AddRoute(rest.Route{
Method: http.MethodPost,
Path: "/a/b",
Handler: handle,
})
engine.Start()
}