当前位置: 首页>>代码示例>>Golang>>正文


Golang DB.Changes方法代码示例

本文整理汇总了Golang中github.com/elos/data.DB.Changes方法的典型用法代码示例。如果您正苦于以下问题:Golang DB.Changes方法的具体用法?Golang DB.Changes怎么用?Golang DB.Changes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/elos/data.DB的用法示例。


在下文中一共展示了DB.Changes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: WebSensorsAgent

func WebSensorsAgent(ctx context.Context, db data.DB, u *models.User) {
	// Get the db's changes, then filter by updates, then
	// filter by whether this user can read the record
	changes := data.Filter(data.FilterKind(db.Changes(), models.EventKind), func(c *data.Change) bool {
		ok, _ := access.CanRead(db, u, c.Record)
		return ok
	})

Run:
	for {
		select {
		case c, ok := <-*changes:
			if !ok {
				break Run
			}

			switch c.Record.(*models.Event).Name {
			case WEB_SENSOR_LOCATION:
				webSensorLocation(db, u, c.Record.(*models.Event).Data)
			}
		case <-ctx.Done():
			break Run

		}
	}
}
开发者ID:elos,项目名称:gaia,代码行数:26,代码来源:web_sensors.go

示例2: TaskAgent

func TaskAgent(ctx context.Context, db data.DB, u *models.User) {

	changes := data.Filter(data.FilterKind(db.Changes(), models.EventKind), func(c *data.Change) bool {
		ok, _ := access.CanRead(db, u, c.Record)
		return ok
	})

Run:
	for {
		select {
		case c, ok := <-*changes:
			if !ok {
				break Run
			}

			switch c.Record.(*models.Event).Name {
			case TaskMakeGoal:
				taskMakeGoal(db, u, c.Record.(*models.Event).Data)
			case TaskDropGoal:
				taskDropGoal(db, u, c.Record.(*models.Event).Data)
			}
		case <-ctx.Done():
			break Run
		}
	}

}
开发者ID:elos,项目名称:gaia,代码行数:27,代码来源:task.go

示例3: LocationAgent

func LocationAgent(ctx context.Context, db data.DB, u *models.User) {
	locTag, err := tag.ForName(db, u, tag.Location)
	if err != nil {
		log.Fatal(err)
	}
	updTag, err := tag.ForName(db, u, tag.Update)
	if err != nil {
		log.Fatal(err)
	}

	// Get the db's changes, then filter by updates, then
	// filter by whether this user can read the record
	changes := data.Filter(data.FilterKind(db.Changes(), models.EventKind), func(c *data.Change) bool {
		ok, _ := access.CanRead(db, u, c.Record)
		if !ok {
			return false
		}

		return event.ContainsTags(c.Record.(*models.Event), locTag, updTag)
	})

Run:
	for {
		select {
		case c, ok := <-*changes:
			if !ok {
				break Run
			}

			locationUpdate(db, u, c.Record.(*models.Event))
		case <-ctx.Done():
			break Run

		}
	}
}
开发者ID:elos,项目名称:gaia,代码行数:36,代码来源:location.go

示例4: RecordChangesGET

func RecordChangesGET(ctx context.Context, ws *websocket.Conn, db data.DB, logger services.Logger) {
	l := logger.WithPrefix("RecordChangesGet: ")

	u, ok := user.FromContext(ctx)
	if !ok {
		l.Print("failed to retrieve user from context")
		return
	}

	// Get the db's changes, then filter by updates, then
	// filter by whether this user can read the record
	changes := data.Filter(db.Changes(), func(c *data.Change) bool {
		ok, err := access.CanRead(db, u, c.Record)
		if err != nil {
			l.Printf("error checking access control: %s", err)
		}
		return ok
	})

	var kind data.Kind
	if kindParam := ws.Request().Form.Get(kindParam); kindParam != "" {
		kind = data.Kind(kindParam)

		if _, ok := models.Kinds[kind]; !ok {
			l.Printf("unrecognized kind: %q", kind)
			if err := websocket.Message.Send(ws, fmt.Sprintf("The kind %q is not recognized", kind)); err != nil {
				if err != io.EOF {
					l.Printf("error sending on websocket: %s", err)
				}
			}
			return
		}

		// If a kind was specified, filter by it
		changes = data.FilterKind(changes, kind)
	}

	for {
		select {
		case change, ok := <-*changes:
			if !ok {
				l.Printf("change channel was closed")
				return
			}

			l.Printf("recieved change: %+v", change)

			changeTransport := transfer.Change(change)

			if err := websocket.JSON.Send(ws, changeTransport); err != nil {
				if err != io.EOF {
					l.Printf("error sending to socket: %s", err)
				}

				return
			}
		case <-time.After(5 * time.Second):
			l.Printf("no change in 5 seconds, but still listening")
		case <-ctx.Done():
			l.Printf("context cancelled")
			// context was cancelled
			return
		}
	}
}
开发者ID:elos,项目名称:gaia,代码行数:65,代码来源:record.go


注:本文中的github.com/elos/data.DB.Changes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。