Skip to content

Commit

Permalink
Merge pull request #4 from ArtisanCloud/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Matrix-X authored May 17, 2022
2 parents 19943e5 + d380b00 commit 92bdd58
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions http/drivers/gout/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (client *Client) PrepareRequest(method string, uri string, options *object.

// append query
queries = &object.StringMap{}
if (*options)["query"] != nil {
if !object.IsObjectNil((*options)["query"]) {
queries = (*options)["query"].(*object.StringMap)
}

Expand Down Expand Up @@ -287,8 +287,8 @@ func (client *Client) buildUri(uri *url.URL, config *object.HashMap) *url.URL {
}
} else {
// use app config base uri
mapHttp := (*client.Config)["http"].(object.HashMap)
strBaseUri := mapHttp["base_uri"].(string)
mapHttp := (*client.Config)["http"].(*object.HashMap)
strBaseUri := (*mapHttp)["base_uri"].(string)
baseUri, err = url.Parse(strBaseUri)
if err != nil {
print("cannot parse base url, pls make sure base_uri has scheme")
Expand Down
2 changes: 2 additions & 0 deletions object/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ func (c *Collection) Get(key string, defaultValue interface{}) interface{} {
switch hashedObject[segment].(type) {
case HashMap:
hashedObject = hashedObject[segment].(HashMap)
case *HashMap:
hashedObject = *(hashedObject[segment].(*HashMap))
case map[string]interface{}:
hashedObject = hashedObject[segment].(map[string]interface{})
default:
Expand Down
8 changes: 6 additions & 2 deletions object/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func GetModelTags(t reflect.Type, tagName string) (tags []string) {
for i := 0; i < t.NumField(); i++ {
// Get the field, returns https://golang.org/pkg/reflect/#StructField
field := t.Field(i)
kind:=field.Type.Kind().String()
if kind == "struct" || kind=="ptr" {
kind := field.Type.Kind().String()
if kind == "struct" || kind == "ptr" {
subTags = GetModelTags(field.Type.Elem(), tagName)
tags = append(tags, subTags...)

Expand All @@ -62,3 +62,7 @@ func GetModelTags(t reflect.Type, tagName string) (tags []string) {
}
return tags
}

func IsObjectNil(obj interface{}) bool {
return obj == nil || (reflect.ValueOf(obj).Kind() == reflect.Ptr && reflect.ValueOf(obj).IsNil())
}

0 comments on commit 92bdd58

Please sign in to comment.