// GetEventService returns the EventService.
173293
func (c *contextCache) GetEventService(channelID string, opts ...options.Opt) (fab.EventService, error) {
	chnlCfg, err := c.GetChannelConfig(channelID)
	if err != nil {
		return nil, err
	}
	key, err := newEventCacheKey(chnlCfg, opts...)
	if err != nil {
		return nil, err
	}
	eventService, err := c.eventServiceCache.Get(key)
	if err != nil {
		return nil, err
	}

	return eventService.(fab.EventService), nil
}
1248586
func GetRequestEventID(r *http.Request) (*lunk.EventID, error) {
	s := r.Header.Get(HeaderEventID)
	if s == "" {
		return nil, nil
	}
	return lunk.ParseEventID(s)
}
842040
func eventHandler(w http.ResponseWriter, r *http.Request) {
	if r.Body != nil {
		defer r.Body.Close()
	}

	ctx := r.Context()

	switch r.Method {
	// Get all events
	case http.MethodGet:
		events, err := getEvents(Configuration.Service.ReadMaxLimit)
		if err != nil {
			LoggingClient.Error(err.Error())
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}

		encode(events, w)
		break
		// Post a new event
	case http.MethodPost:
		contentType := r.Header.Get(clients.ContentType)
		if contentType == clients.ContentTypeCBOR {
			errMsg := "CBOR payload is not yet supported"
			http.Error(w, errMsg, http.StatusNotImplemented)
			LoggingClient.Error(errMsg)

			return
		}

		var e models.Event
		dec := json.NewDecoder(r.Body)
		err := dec.Decode(&e)

		// Problem Decoding Event
		if err != nil {
			http.Error(w, err.Error(), http.StatusBadRequest)
			LoggingClient.Error("Error decoding event: " + err.Error())
			return
		}

		LoggingClient.Info("Posting Event: " + e.String())

		newId, err := addNewEvent(e, ctx)
		if err != nil {
			switch t := err.(type) {
			case *errors.ErrValueDescriptorNotFound:
				http.Error(w, t.Error(), http.StatusBadRequest)
			case *errors.ErrValueDescriptorInvalid:
				http.Error(w, t.Error(), http.StatusBadRequest)
			default:
				http.Error(w, t.Error(), http.StatusInternalServerError)
			}
			LoggingClient.Error(err.Error())
			return
		}

		w.WriteHeader(http.StatusOK)
		w.Write([]byte(newId))

		break
		// Do not update the readings
	case http.MethodPut:
		contentType := r.Header.Get(clients.ContentType)
		if contentType == clients.ContentTypeCBOR {
			errMsg := "CBOR payload is not yet supported"
			http.Error(w, errMsg, http.StatusNotImplemented)
			LoggingClient.Error(errMsg)

			return
		}

		var from models.Event
		dec := json.NewDecoder(r.Body)
		err := dec.Decode(&from)

		// Problem decoding event
		if err != nil {
			http.Error(w, err.Error(), http.StatusBadRequest)
			LoggingClient.Error("Error decoding the event: " + err.Error())
			return
		}

		LoggingClient.Info("Updating event: " + from.ID)
		err = updateEvent(from, ctx)
		if err != nil {
			switch t := err.(type) {
			case *errors.ErrEventNotFound:
				http.Error(w, t.Error(), http.StatusNotFound)
			default:
				http.Error(w, t.Error(), http.StatusInternalServerError)
			}
			LoggingClient.Error(err.Error())
			return
		}

		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)
		w.Write([]byte("true"))
	}
}
586360
func (c *Contributor) GetEventsURL() string {
	if c == nil || c.EventsURL == nil {
		return ""
	}
	return *c.EventsURL
}
212424
func EventHandler(handler func(zk.Event)) Option {
	return func(c *clientConfig) error {
		c.eventHandler = handler
		return nil
	}
}
1077484
func (cs *MockChannelService) EventService(opts ...options.Opt) (fab.EventService, error) {
	return NewMockEventService(), nil
}
1321928
func GetRuntimeService(ctx context.Context, storageImageServer ImageServer, pauseImage, pauseImageAuthFile string) RuntimeServer {
	return &runtimeService{
		storageImageServer: storageImageServer,
		pauseImage:         pauseImage,
		pauseImageAuthFile: pauseImageAuthFile,
		ctx:                ctx,
	}
}
1192230
func parseService(ctx *context, svcName string, svcNode *jsongo.JSONNode) (*Service, error) {
	if svcNode.Len() == 0 || svcNode.At(replyField).GetType() != jsongo.TypeValue {
		return nil, errors.New("invalid JSON for service specified")
	}

	svc := Service{
		Name:        ctx.moduleName + "." + svcName,
		RequestType: svcName,
	}

	if replyNode := svcNode.At(replyField); replyNode.GetType() == jsongo.TypeValue {
		reply, ok := replyNode.Get().(string)
		if !ok {
			return nil, fmt.Errorf("service reply is %T, not a string", replyNode.Get())
		}
		if reply != serviceNoReply {
			svc.ReplyType = reply
		}
	}

	// stream service (dumps)
	if streamNode := svcNode.At(streamField); streamNode.GetType() == jsongo.TypeValue {
		var ok bool
		svc.Stream, ok = streamNode.Get().(bool)
		if !ok {
			return nil, fmt.Errorf("service stream is %T, not a string", streamNode.Get())
		}
	}

	// events service (event subscription)
	if eventsNode := svcNode.At(eventsField); eventsNode.GetType() == jsongo.TypeArray {
		for j := 0; j < eventsNode.Len(); j++ {
			event := eventsNode.At(j).Get().(string)
			svc.Events = append(svc.Events, event)
		}
	}

	// validate service
	if len(svc.Events) > 0 {
		// EVENT service
		if !strings.HasPrefix(svc.RequestType, serviceEventPrefix) {
			log.Debugf("unusual EVENTS service: %+v\n"+
				"- events service %q does not have %q prefix in request.",
				svc, svc.Name, serviceEventPrefix)
		}
	} else if svc.Stream {
		// STREAM service
		if !strings.HasSuffix(svc.RequestType, serviceDumpSuffix) ||
			!strings.HasSuffix(svc.ReplyType, serviceDetailsSuffix) {
			log.Debugf("unusual STREAM service: %+v\n"+
				"- stream service %q does not have %q suffix in request or reply does not have %q suffix.",
				svc, svc.Name, serviceDumpSuffix, serviceDetailsSuffix)
		}
	} else if svc.ReplyType != "" && svc.ReplyType != serviceNoReply {
		// REQUEST service
		// some messages might have `null` reply (for example: memclnt)
		if !strings.HasSuffix(svc.ReplyType, serviceReplySuffix) {
			log.Debugf("unusual REQUEST service: %+v\n"+
				"- service %q does not have %q suffix in reply.",
				svc, svc.Name, serviceReplySuffix)
		}
	}

	return &svc, nil
}
1334225
func (m *Maestro) GetServiceName() (string, error) {
	address := m.osGetenv("SERVICE_NAME")
	if address == "" {
		return "", ErrNoServiceName
	}
	return address, nil
}
1372615
func getEventByIdHandler(w http.ResponseWriter, r *http.Request) {
	if r.Body != nil {
		defer r.Body.Close()
	}

	// URL parameters
	vars := mux.Vars(r)
	id := vars["id"]

	// Get the event
	e, err := getEventById(id)
	if err != nil {
		switch x := err.(type) {
		case *errors.ErrEventNotFound:
			http.Error(w, x.Error(), http.StatusNotFound)
		default:
			http.Error(w, x.Error(), http.StatusInternalServerError)
		}

		LoggingClient.Error(err.Error())
		return
	}

	encode(e, w)
}
73218
func (a *Client) GetService(params *GetServiceParams) (*GetServiceOK, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewGetServiceParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "GetService",
		Method:             "GET",
		PathPattern:        "/service",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &GetServiceReader{formats: a.formats},
		Context:            params.Context,
		Client:             params.HTTPClient,
	})
	if err != nil {
		return nil, err
	}
	return result.(*GetServiceOK), nil

}
1268477
func NewEventsService(b backend.Backend) *EventsService {
	return &EventsService{
		Entry:   logrus.WithFields(logrus.Fields{trace.Component: "Events"}),
		backend: b,
	}
}
839044
func (s *Sensu) GetEventsForClient(client string) ([]interface{}, error) {
	//return s.get("events", client)
	// TODO  is this the correct way? need validation??
	return s.getList(fmt.Sprintf("events/%s", client), 0, 0)
}
112638
func (c *Client) ListServiceUsageEventsByQuery(query url.Values) ([]ServiceUsageEvent, error) {
	var serviceUsageEvents []ServiceUsageEvent
	requestURL := fmt.Sprintf("/v2/service_usage_events?%s", query.Encode())
	for {
		var serviceUsageEventsResponse ServiceUsageEventsResponse
		r := c.NewRequest("GET", requestURL)
		resp, err := c.DoRequest(r)
		if err != nil {
			return nil, errors.Wrap(err, "error requesting events")
		}
		defer resp.Body.Close()
		if err := json.NewDecoder(resp.Body).Decode(&serviceUsageEventsResponse); err != nil {
			return nil, errors.Wrap(err, "error unmarshaling events")
		}
		for _, e := range serviceUsageEventsResponse.Resources {
			e.Entity.GUID = e.Meta.Guid
			e.Entity.CreatedAt = e.Meta.CreatedAt
			e.Entity.c = c
			serviceUsageEvents = append(serviceUsageEvents, e.Entity)
		}
		requestURL = serviceUsageEventsResponse.NextURL
		if requestURL == "" {
			break
		}
	}
	return serviceUsageEvents, nil
}
988191
func (cs *ChannelService) EventService(opts ...options.Opt) (fab.EventService, error) {
	return cs.ctxtCache.GetEventService(cs.channelID, opts...)
}
619831
func (b *FusisBalancer) GetService(name string) (*types.Service, error) {
	return b.store.GetService(name)
}
542569
func (client *Client) GetEvents(filters ...Filter) ([]Event, Warnings, error) {
	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.GetEventsRequest,
		Query:       ConvertFilterParameters(filters),
	})
	if err != nil {
		return nil, nil, err
	}

	var fullEventsList []Event
	warnings, err := client.paginate(request, Event{}, func(item interface{}) error {
		if event, ok := item.(Event); ok {
			fullEventsList = append(fullEventsList, event)
		} else {
			return ccerror.UnknownObjectInListError{
				Expected:   Event{},
				Unexpected: item,
			}
		}
		return nil
	})

	return fullEventsList, warnings, err
}