// If the result array is empty, don't return http.NotFound, just return empty array
352227
func restGetDeviceByServiceName(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	sn, err := url.QueryUnescape(vars[SERVICENAME])
	if err != nil {
		LoggingClient.Error(err.Error())
		http.Error(w, err.Error(), http.StatusServiceUnavailable)
		return
	}

	// Check if the device service exists
	ds, err := dbClient.GetDeviceServiceByName(sn)
	if err != nil {
		if err == db.ErrNotFound {
			http.Error(w, err.Error(), http.StatusNotFound)
		} else {
			http.Error(w, err.Error(), http.StatusServiceUnavailable)
		}
		LoggingClient.Error(err.Error())
		return
	}

	// Find devices by service ID now that you have the Service object (and therefor the ID)
	res, err := dbClient.GetDevicesByServiceId(ds.Id)
	if err != nil {
		http.Error(w, err.Error(), http.StatusServiceUnavailable)
		LoggingClient.Error(err.Error())
		return
	}

	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(res)
}
555889
func ExpectJSONArray(t T, r *http.Response, callback func(array []interface{})) bool {
	if r == nil {
		logerror(t, serrorf("ExpectJSONArray: no response available"))
		return false
	}
	if r.Body == nil {
		logerror(t, serrorf("ExpectJSONArray: no body to read"))
		return false
	}
	data, err := ioutil.ReadAll(r.Body)
	defer r.Body.Close()
	if err != nil {
		if verboseOnFailure {
			Dump(t, r)
		}
		logerror(t, serrorf("ExpectJSONArray: unable to read response body:%v", err))
		return false
	}
	// put the body back for re-reads
	r.Body = ioutil.NopCloser(bytes.NewReader(data))

	slice := []interface{}{}
	err = json.Unmarshal(data, &slice)
	if err != nil {
		if verboseOnFailure {
			Dump(t, r)
		}
		logerror(t, serrorf("ExpectJSONArray: unable to unmarshal Json:%v", err))
		return false
	}
	callback(slice)
	return true
}
730460
func Find(rType, action, identifier string, wrappedRequest *http.Request) (*http.Response, string, []error) {
	params := "select_by="
	params += fmt.Sprintf("type=%s,", rType)
	params += fmt.Sprintf("action=%s", action)
	if identifier != "" {
		params += fmt.Sprintf(",uuid=%s,", identifier)
	}

	fmt.Println("Params: ", params)

	k := kumoru.New()
	k.Get(fmt.Sprintf("%s/v1/resources/", k.EndPoint.Authorization))
	k.Query(params)
	if wrappedRequest != nil {
		k.ProxyRequest(wrappedRequest)
		if wrappedRequest.Header.Get("X-Kumoru-Context") != "" {
			k.SetHeader("X-Kumoru-Context", wrappedRequest.Header.Get("X-Kumoru-Context"))
		}
	}
	k.SignRequest(true)

	return k.End()
}
556224
func getArray(schema proto.Schema) (*proto.Array, error) {
	if schema == nil {
		return nil, nil
	}
	visitor := &arraySchemaVisitor{}
	schema.Accept(visitor)
	return visitor.Result, visitor.Err
}
1069679
func IsEmpty(v interface{}) bool {
	switch val := v.(type) {
	case reflect.Value:
		return isEmptyValue(val)
	case *reflect.Value:
		if val == nil {
			return true
		}
		return isEmptyValue(*val)
	default:
		return isEmptyValue(reflect.ValueOf(v))
	}
}
1121498
func Empty(t testing.TB, expr interface{}, args ...interface{}) {
	assert(t, IsEmpty(expr), args, []interface{}{"Empty 失败，实际值为[%T:%[1]v]", expr})
}
586021
func IsNotFound(err error) bool {
	if err == nil {
		return false
	}
	if err, ok := err.(*ErrorResponse); ok && err.Response.StatusCode == http.StatusNotFound {
		return true
	}
	return false
}
294676
func (f *future) result() (loader.PluginInstance, error) {
	return f.instance, f.err
}
6328
func (i *inflight) result() ([]jose.JSONWebKey, error) {
	return i.keys, i.err
}
272149
func (s *Selection) Empty() *Selection {
	var nodes []*html.Node

	for _, n := range s.Nodes {
		for c := n.FirstChild; c != nil; c = n.FirstChild {
			n.RemoveChild(c)
			nodes = append(nodes, c)
		}
	}

	return pushStack(s, nodes)
}
79898
func (u *UsersSearchResult) GetIncompleteResults() bool {
	if u == nil || u.IncompleteResults == nil {
		return false
	}
	return *u.IncompleteResults
}
739474
func IsNotFound(e error) bool {
	if e == NotFound {
		return true
	}
	if e, ok := e.(*URLError); ok && e.Err == NotFound {
		return true
	}
	return false
}
832684
func (r *httpVPackResponse) ParseArrayBody() ([]driver.Response, error) {
	if r.bodyArray == nil {
		slice, err := r.getSlice()
		if err != nil {
			return nil, driver.WithStack(err)
		}
		l, err := slice.Length()
		if err != nil {
			return nil, driver.WithStack(err)
		}

		bodyArray := make([]driver.Response, 0, l)
		it, err := velocypack.NewArrayIterator(slice)
		if err != nil {
			return nil, driver.WithStack(err)
		}
		for it.IsValid() {
			v, err := it.Value()
			if err != nil {
				return nil, driver.WithStack(err)
			}
			bodyArray = append(bodyArray, &httpVPackResponseElement{slice: v})
			it.Next()
		}
		r.bodyArray = bodyArray
	}

	return r.bodyArray, nil
}
753242
func IsNotFound(data string) bool {
	notExistsKeys := []string{
		"no found",
		"no match",
		"not found",
		"not match",
		"no entries found",
		"no data found",
		"not registered",
		"not been registered",
		"is free",
		"not available for registration",
		"object does not exist",
	}

	data = strings.ToLower(data)
	for _, v := range notExistsKeys {
		if strings.Contains(data, v) {
			return true
		}
	}

	return false
}
1133174
func Arr() *Array {
	a := arrayPool.Get().(*Array)
	a.buf = a.buf[:0]
	return a
}
897064
func Found(w http.ResponseWriter, response interface{}) {
	Respond(w, http.StatusFound, response)
}
654319
func (q *Query) resultsAsJSON() string {
	res := &search.SearchResult{
		Blobs: q.Blobs,
		Describe: &search.DescribeResponse{
			Meta: q.Meta,
		},
	}
	var buf bytes.Buffer
	enc := json.NewEncoder(&buf)
	if err := enc.Encode(res); err != nil {
		fmt.Println(fmt.Sprintf("Error marshaling search results: %v", err))
		return ""
	}
	return buf.String()
}