Ejemplo n.º 1
0
func (e *Event) Create(ctx context.Context, req *event.CreateRequest, rsp *event.CreateResponse) error {
	if req.Record == nil {
		return errors.BadRequest("go.micro.srv.event.Create", "invalid record")
	}

	if req.Record.Timestamp == 0 {
		req.Record.Timestamp = time.Now().Unix()
	}

	if len(req.Record.Id) == 0 {
		req.Record.Id = uuid.NewUUID().String()
	}

	if err := db.Create(req.Record); err != nil {
		return errors.InternalServerError("go.micro.srv.event.Create", err.Error())
	}

	return nil
}
Ejemplo n.º 2
0
func Process(ctx context.Context, rec *event.Record) error {
	if rec == nil {
		return errors.BadRequest("go.micro.srv.event.Process", "invalid record")
	}

	if len(rec.Id) == 0 {
		return errors.BadRequest("go.micro.srv.event.Process", "invalid id")
	}

	if len(rec.Type) == 0 {
		return errors.BadRequest("go.micro.srv.event.Process", "invalid type")
	}

	if rec.Timestamp == 0 {
		return errors.BadRequest("go.micro.srv.event.Process", "invalid timestamp")
	}

	if err := db.Create(rec); err != nil {
		return errors.InternalServerError("go.micro.srv.event.Process", err.Error())
	}

	return nil
}