logic

package
v0.0.0-...-261bb52 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	// RedisRoomUserPrefix 用户房间
	RedisRoomUserPrefix = "im_room_user_"
	// RedisAuthPrefix 授权 用来寻找serverID
	RedisAuthPrefix = "gim_auth_"
	// RedisSubChannel 消息订阅地址
	RedisSubChannel = "gim_sub_channel"
	// RedisBaseValidTime 过期时间
	RedisBaseValidTime = 86400
)

Variables

View Source
var (
	// RedisCli is default redis client
	RedisCli *redis.Client
)

Functions

func InitRedis

func InitRedis() (err error)

InitRedis is func to initial redis client

func RedisPublishCh

func RedisPublishCh(ctx context.Context, serverID int8, uid string, msg []byte) (err error)

RedisPublishCh is func to push msg

Example

ExampleRedisPublishCh example used to push single msg

c := conf.NewConfig()
conf.Conf = c
if err := logic.InitRedis(); err != nil {
	log.Panic(fmt.Errorf("InitRedis() fatal error : %s \n", err))
}

_ = os.Setenv("JAEGER_REPORTER_LOG_SPANS", "true")
_ = os.Setenv("JAEGER_AGENT_HOST", "118.25.5.127")
_ = os.Setenv("JAEGER_AGENT_PORT", "6831")
tracer, _ := tracing.Init("logic", nil)
span := tracer.StartSpan("logic")
ctx := context.Background()
ctx = opentracing.ContextWithSpan(ctx, span)
_ = logic.RedisPublishCh(ctx, 1, "2850516", []byte(`这是一条发送到 "个人" 的消息`))

span.Finish()

time.Sleep(1 * time.Second)
Output:

func RedisPublishRoom

func RedisPublishRoom(ctx context.Context, rid string, msg []byte) (err error)

RedisPublishRoom is func to push msg to room

Example

ExampleRedisPublishRoom example used to push room msg

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/Cluas/gim/internal/logic"
	"github.com/Cluas/gim/internal/logic/conf"
)

func main() {
	c := conf.NewConfig()
	conf.Conf = c
	if err := logic.InitRedis(); err != nil {
		log.Panic(fmt.Errorf("InitRedis() fatal error : %s \n", err))
	}
	err := logic.RedisPublishRoom(context.Background(), "123", []byte(`这是一条发送到 "房间" 的消息`))
	log.Print(err)

}
Output:

Types

type Operation

type Operation int

Operation defines the type of operation.

const (

	// OpSingleSend 指定用户发送
	OpSingleSend Operation
	// OpRoomSend 广播到房间操作
	OpRoomSend
)

type RedisMsg

type RedisMsg struct {
	Carrier  []byte    `json:"carrier"` // 携带trace信息
	Op       Operation `json:"op"`
	ServerID int8      `json:"serverID,omitempty"`
	RoomID   string    `json:"roomID,omitempty"`
	UserID   string    `json:"userID,omitempty"`
	Msg      []byte    `json:"msg"`
}

RedisMsg is struct of redis msg

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL