@@ -3,6 +3,7 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"testing"
|
||||
@@ -80,5 +81,4 @@ func TestRoundTripper(t *testing.T) {
|
||||
if string(b) != "hello world" {
|
||||
t.Fatal("response is", string(b))
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -8,9 +8,9 @@ import (
|
||||
|
||||
// Tree is a trie tree.
|
||||
type Trie struct {
|
||||
rmu sync.RWMutex
|
||||
node *node
|
||||
rcache map[string]*regexp.Regexp
|
||||
rmu sync.RWMutex
|
||||
}
|
||||
|
||||
// node is a node of tree
|
||||
|
@@ -5,6 +5,26 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTrieContentType(t *testing.T) {
|
||||
type handler struct {
|
||||
name string
|
||||
}
|
||||
tr := NewTrie()
|
||||
tr.Insert([]string{"application/json"}, "/v1/create/{id}", &handler{name: "test"})
|
||||
|
||||
h, _, ok := tr.Search("application/json", "/v1/create/12")
|
||||
if !ok {
|
||||
t.Fatalf("must be found error")
|
||||
}
|
||||
if h.(*handler).name != "test" {
|
||||
t.Fatalf("invalid handler %v", h)
|
||||
}
|
||||
_, _, ok = tr.Search("text/xml", "/v1/create/12")
|
||||
if ok {
|
||||
t.Fatalf("must be not found error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrieNoMatchMethod(t *testing.T) {
|
||||
tr := NewTrie()
|
||||
tr.Insert([]string{http.MethodPut}, "/v1/create/{id}", nil)
|
||||
|
@@ -12,10 +12,9 @@ import (
|
||||
// ErrInvalidParam specifies invalid url query params
|
||||
var ErrInvalidParam = errors.New("invalid url query param provided")
|
||||
|
||||
// var timeKind = reflect.ValueOf(time.Time{}).Kind()
|
||||
var bracketSplitter = regexp.MustCompile(`\[|\]`)
|
||||
|
||||
//var timeKind = reflect.ValueOf(time.Time{}).Kind()
|
||||
|
||||
type StructField struct {
|
||||
Field reflect.StructField
|
||||
Value reflect.Value
|
||||
@@ -149,9 +148,9 @@ func StructFields(src interface{}) ([]StructField, error) {
|
||||
}
|
||||
|
||||
switch val.Kind() {
|
||||
//case timeKind:
|
||||
//fmt.Printf("GGG\n")
|
||||
//fields = append(fields, StructField{Field: fld, Value: val, Path: fld.Name})
|
||||
// case timeKind:
|
||||
// fmt.Printf("GGG\n")
|
||||
// fields = append(fields, StructField{Field: fld, Value: val, Path: fld.Name})
|
||||
case reflect.Struct:
|
||||
infields, err := StructFields(val.Interface())
|
||||
if err != nil {
|
||||
|
@@ -2,7 +2,7 @@ package reflect
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"reflect"
|
||||
rfl "reflect"
|
||||
rfl "reflect"
|
||||
"testing"
|
||||
)
|
||||
|
@@ -45,10 +45,10 @@ func (b *Basic) Generate(acc *auth.Account, opts ...token.GenerateOption) (*toke
|
||||
|
||||
// write to the store
|
||||
key, err := id.New()
|
||||
if err !=nil {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
err = b.store.Write(context.Background(), fmt.Sprintf("%v%v", StorePrefix, key), bytes, store.WriteTTL(options.Expiry))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -13,7 +13,7 @@ import (
|
||||
// authClaims to be encoded in the JWT
|
||||
type authClaims struct {
|
||||
Metadata metadata.Metadata `json:"metadata"`
|
||||
jwt.StandardClaims
|
||||
jwt.RegisteredClaims
|
||||
Type string `json:"type"`
|
||||
Scopes []string `json:"scopes"`
|
||||
}
|
||||
@@ -50,10 +50,10 @@ func (j *JWT) Generate(acc *auth.Account, opts ...token.GenerateOption) (*token.
|
||||
// generate the JWT
|
||||
expiry := time.Now().Add(options.Expiry)
|
||||
t := jwt.NewWithClaims(jwt.SigningMethodRS256, authClaims{
|
||||
Type: acc.Type, Scopes: acc.Scopes, Metadata: acc.Metadata, StandardClaims: jwt.StandardClaims{
|
||||
Type: acc.Type, Scopes: acc.Scopes, Metadata: acc.Metadata, RegisteredClaims: jwt.RegisteredClaims{
|
||||
Subject: acc.ID,
|
||||
Issuer: acc.Issuer,
|
||||
ExpiresAt: expiry.Unix(),
|
||||
ExpiresAt: jwt.NewNumericDate(expiry),
|
||||
},
|
||||
})
|
||||
tok, err := t.SignedString(key)
|
||||
|
Reference in New Issue
Block a user