// findHandlerByID returns the Handler for the searchID. If not found // or slices have an indifferent length or something is nil it will // return the DefaultErrorHandler. func findHandlerByID(so scope.Scope, id int64, idsIdx util.Int64Slice, handlers []ctxhttp.HandlerFunc) ctxhttp.HandlerFunc { if len(idsIdx) != len(handlers) { return DefaultAlternativeHandler } index := idsIdx.Index(id) if index < 0 { return DefaultAlternativeHandler } prospect := handlers[index] if nil == prospect { return DefaultAlternativeHandler } if PkgLog.IsInfo() { PkgLog.Info("geoip.findHandlerByID.found", "scope", so.String(), "id", id, "idsIdx", idsIdx) } return prospect }
func TestInt64SliceIndex(t *testing.T) { is := util.Int64Slice{-29, 30, -1} assert.EqualValues(t, 2, is.Index(-1)) assert.EqualValues(t, -1, is.Index(123)) }