app

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2014 License: GPL-3.0 Imports: 26 Imported by: 1

Documentation

Index

Constants

View Source
const (
	APICALL_EXIST      = "" /* 127-byte string literal not displayed */
	APICALL_ADD        = "" /* 152-byte string literal not displayed */
	INSERT_APICALL     = "" /* 131-byte string literal not displayed */
	GET_APICALL_COUNT  = "select sum(count) as count from api_call WHERE  customer_id = ? and  tenant_id = ?  and api_name = ?  "
	GET_CUSTOMER_COUNT = "select sum(count) as count from api_call WHERE  customer_id = ? and api_name = ?  "
	SELECT_EXIST       = "select id from quota  where customer_id = ? and tenant_id=? and  api_name=? and type = ?"
	SELECT_QUOTA       = "" /* 135-byte string literal not displayed */
	UPDATE_QUOTA       = "update quota set  value=? , updated =? where customer_id = ? and tenant_id=? and  api_name=? and type = ?"
	INSERT_QUOTA       = "insert into quota(id , customer_id,tenant_id,api_name,type,value,created,updated) values(?,?,?,?,?,?,?,?)"
	SELECT_QUOTA_ALL   = "select id , customer_id,tenant_id,api_name,type,value,created,updated from quota"
	/*配额类型*/
	EXPIRE  = "expire"
	API_CNT = "api_cnt"
)
View Source
const (

	// 租户资源插入 SQL.
	InsertApnsMsgSQL = "" /* 135-byte string literal not displayed */
	// 根据资源id 获取资源
	SelectApnsMsgByIdSQL = "SELECT * FROM `apns_msg` where `id` = ?"
	// 根据租户 id 查询租户的资源.
	SelectApnsMsgByTenantIdSQL = "SELECT * FROM `apns_msg` where `tenant_id`  = ?"
	// 根据apns_token 查询租户的资源.
	SelectApnsMsgByApnsTokenSQL = "SELECT * FROM `apns_msg` where `apns_token`  = ?"
	//根据id修改资源
	UpdateApnsMsgByIdSQL = "" /* 145-byte string literal not displayed */
	//根据id删除资源
	DelApnsMsgByIdSQL = "DELETE FROM `apns_msg` WHERE `id` =? "
	//根据tenant_id删除资源
	DelApnsMsgByTenantIdSQL = "DELETE FROM `apns_msg` where `tenant_id`  = ?"
)
View Source
const (
	// 根据 id 查询应用记录.
	SelectApplicationById = "SELECT  * FROM `application` WHERE `id` = ?"
	// 查询应用记录.
	SelectAllApplication = "SELECT `id`, `name`, `name`,`status`, `sort`,`avatar`, `tenant_id`, `name_py`, `name_quanpin` FROM `application`"
	// 根据 token 获取应用记录.
	SelectApplicationByToken = "SELECT * FROM `application` WHERE `token` = ?"
	//根据应用ID查询应用操作项列表
	SelectAppOpertionByAppId = "" /* 148-byte string literal not displayed */
	//根据操作项父ID查询应用操作项列表
	SelectAppOpertionByParentId = "SELECT `id`, `app_id`, `content`,`action`, `operation_type`,`sort`  FROM `operation` WHERE `parent_id` = ?  order by  sort "
)
View Source
const (

	// 获取最新的客户端版本
	SelectLatestClientVerByType = "SELECT * FROM `client_version` WHERE `type` = ? ORDER BY `ver_code` DESC LIMIT 1"
	//持久话apns_token
	InsertApnsToken               = "INSERT INTO `apns_token`(`id`,`user_id`,`device_id`,`apns_token`,`created`,`updated`) VALUES(?,?,?,?,?,?)"
	SelectApnsTokenByUserId       = "SELECT `id`,`user_id`,`device_id`,`apns_token`,`created`,`updated` FROM `apns_token` WHERE `user_id`=? "
	SelectApnsTokenByUserIdTokens = "SELECT `id`,`user_id`,`device_id`,`apns_token`,`created`,`updated` FROM `apns_token` WHERE `user_id`=? AND `apns_token`=?"
	DeleteApnsToken               = "DELETE FROM apns_token where apns_token = ?"
	DeleteApnsTokenByUid          = "DELETE FROM apns_token where apns_token = ?  and user_id = ? "
	DeleteApnsTokenByDeviceId     = "DELETE FROM apns_token where device_id = ?"
)
View Source
const (
	/*后缀信息*/
	TENANT_SUFFIX = "@tenant"
	ORG_SUFFIX    = "@org"
	QUN_SUFFIX    = "@qun"
	USER_SUFFIX   = "@user"
	APP_SUFFIX    = "@app"
)
View Source
const (
	// 添加联系人.
	InsertUserUserSQL = "INSERT INTO `user_user` (`id`, `from_user_id`, `to_user_id`, `remark_name`, `sort`,`created`, `updated`) VALUES " +
		"(?, ?, ?, ?, ?, ?, ?)"
	// 删除联系人.
	DeleteUserUserSQL = "DELETE FROM `user_user` WHERE `from_user_id` = ? AND `to_user_id` = ?"
)
View Source
const (
	DEVICE_TYPE_IOS     = "ios"
	DEVICE_TYPE_ANDROID = "android"
)
View Source
const (
	INSERT_FILELINK        = "insert into file_link (id , sender_id,file_id ,file_name,file_url,size,created,updated)  values(?,?,?,?,?,?,?,?)"
	UPDATE_FILELINK_TIME   = "update file_link set updated =? where sender_id =? and file_id =?"
	EXIST_FILELINK         = "select id from file_link where sender_id =? and file_id =?"
	SELECT_EXPIRE_FILELINK = "select  id, file_id from file_link where  updated  < ?"
)
View Source
const (
	SELECT_PUSHCNT          = "" /* 198-byte string literal not displayed */
	INSERT_PUSHCNT          = "" /* 131-byte string literal not displayed */
	ADD_PUSH_COUNT          = "" /* 134-byte string literal not displayed */
	GET_PUSH_COUNT          = "select sum(count) as count from push_cnt WHERE  customer_id  = ?  tenantId = ?"
	GET_CUSTOMER_PUSH_COUNT = "select sum(count) as count from push_cnt  WHERE  customer_id  = ?  "
	PUSH_CNT                = "push_cnt"
)
View Source
const (
	// 群插入 SQL.
	InsertQunSQL = "INSERT INTO `qun` (`id`, `creator_id`, `name`, `description`, `max_member`, `avatar`, `tenant_id`, `created`, `updated`) VALUES " +
		"(?, ?, ?, ?, ?, ?, ?, ?, ?)"
	// 群-用户关联插入 SQL.
	InsertQunUserSQL = "" /* 204-byte string literal not displayed */

	// 根据群 id 查询群内用户.
	SelectQunUserSQL = "" /* 189-byte string literal not displayed */
	// 根据群 id 查询群内用户 id.
	SelectQunUserIdSQL = "SELECT `user_id` FROM `qun_user` where `qun_id` = ?"
	// 根据群 id 获取群
	SelectQunById = "SELECT * FROM `qun` where `id` = ?"
	//根据群id修改群topic
	UpdateQunTopicByIdSQL = "UPDATE `qun` SET `name` = ? WHERE `id` = ?"
	//根据群id和用户id删除群成员
	DelQunMemberByQunidAndUserid = "DELETE FROM `qun_user` WHERE `qun_id` =? AND `user_id` =?"
)
View Source
const (

	// 租户资源插入 SQL.
	InsertResourceSQL = "INSERT INTO `resource` (`id`, `customer_id`, `name`, `description`, `type`, `content`, `created`, `updated`) VALUES " +
		"(?, ?, ?, ?, ?, ?, ?, ?)"

	// 根据资源id 获取资源
	SelectResourceByIdSQL = "SELECT * FROM `resource` where `id` = ?"

	// 根据租户 id 查询租户的资源.
	SelectResourceByTenantIdSQL = "SELECT * FROM `resource` where `customer_id`  = (select  customer_id from tenant where  id = ?)"

	//根据id修改资源
	UpdateResourceByIdSQL = "" /* 150-byte string literal not displayed */

	//根据id删除资源
	DelResourceByIdSQL = "DELETE FROM `resource` WHERE `id` =? "
)
View Source
const (
	OK               = 0
	NotFoundServer   = 1001
	NotFound         = 65531
	TooLong          = 65532
	AuthErr          = 65533
	ParamErr         = 65534
	InternalErr      = 65535
	OverQuotaApicall = 65536
	OverQuotaPush    = 65537
	DeleteUser       = 65538
	LoginErr         = 65539
)
View Source
const (
	APPWEB_TYPE = "appWeb"
)

Variables

View Source
var App = app{}

声明应用端操作接口.

View Source
var AppWeb = appWeb{}

声明网页端操作接口.

View Source
var Device = device{}

声明移动端操作接口.

View Source
var LoadQuotaTime = time.NewTicker(5 * time.Minute)
View Source
var QuotaAll = make(map[string]Quota)
View Source
var RedisNoConnErr = errors.New("can't get a redis conn")

Functions

func ApiCallStatistics added in v1.1.0

func ApiCallStatistics(w http.ResponseWriter, r *http.Request) bool

记录api调用次数

func DelQunMember

func DelQunMember(qunUsers []QunUser) bool

删除群成员

func DeleteApnsMsgById

func DeleteApnsMsgById(id string) bool

func DeleteApnsMsgByTenantId

func DeleteApnsMsgByTenantId(tenantId string) bool

func DeleteFile added in v1.2.0

func DeleteFile(fileId string) bool

删除weedfs服务器文件

func DeleteResourceById

func DeleteResourceById(resourceId string) bool

删除资源

func ExistFileLink(fileLink *FileLink) bool

判断是否存在文件链接记录

func InitConfig

func InitConfig() error

InitConfig init configuration file.

func InitQuotaAll added in v1.1.0

func InitQuotaAll()

初始化配额配置

func InitRedisStorage

func InitRedisStorage()

initRedisStorage initialize the redis pool and consistency hash ring.

func LoadQuotaAll added in v1.1.0

func LoadQuotaAll()

定时加载配额信息5分钟加载一次

func RetPWrite

func RetPWrite(w http.ResponseWriter, r *http.Request, res map[string]interface{}, body *string, start time.Time)

retPWrite marshal the result and write to client(post).

func RetPWriteJSON

func RetPWriteJSON(w http.ResponseWriter, r *http.Request, res map[string]interface{}, body *string, start time.Time)

带 Content-Type=application/json 头 写 JSON 数据,为了保持原有 gopush-cluster 的兼容性,所以新加了这个函数.

func RetWrite

func RetWrite(w http.ResponseWriter, r *http.Request, res map[string]interface{}, callback string, start time.Time)

retWrite marshal the result and write to client(get).

func SaveFileLinK(fileLink *FileLink) bool

保存文件链接信息

func ScanExpireFileLink()

定时扫描过期的文件链接,如果过期侧删除该文件记录和文件服务器中的文件

func SessionStat

func SessionStat(w http.ResponseWriter, r *http.Request)

请求参数

baseRequest: {
    "uid": "",
    "deviceID": "",
    "deviceType": "", // iOS / Android
    "token": ""
}

state:"active" sessionId:"1111" 设置会话状态(active/inactive)

func StatisticsPush added in v1.1.0

func StatisticsPush(pushCnt *PushCnt)

统计消息推送

func UserErWeiMa

func UserErWeiMa(w http.ResponseWriter, r *http.Request)

用户二维码处理,返回用户信息 HTML.

func ValidApiCall added in v1.1.0

func ValidApiCall(apiCall *ApiCall) bool

检验本次调用是否合法

func ValidPush added in v1.1.0

func ValidPush(pushCnt *PushCnt) bool

Types

type ApiCall added in v1.1.0

type ApiCall struct {
	Id         string
	CustomerId string
	TenantId   string
	CallerId   string
	Type       string
	ApiName    string
	Count      int
	Sharding   int
	Created    time.Time
	Updated    time.Time
}

type ApnsMsg

type ApnsMsg struct {
	Id        string    `json:"id"`
	Type      string    `json:"type"`
	ApnsToken string    `json:"apns_token"`
	Cnt       int       `json:"cnt"`
	TenantId  string    `json:"tenant_id"`
	Pushed    string    `json:"pushed"`
	Created   time.Time `json:"created"`
	Updated   time.Time `json:"updated"`
}

* APNS消息 *

func AddApnsMsg

func AddApnsMsg(apnsMsg *ApnsMsg) (*ApnsMsg, bool)

数据库中插入资源

func GetApnsMsgByApnsToken

func GetApnsMsgByApnsToken(apnsToken string) ([]*ApnsMsg, error)

在数据库中查询资源.

func GetApnsMsgById

func GetApnsMsgById(id string) (*ApnsMsg, error)

在数据库中查询资源.

func GetApnsMsgByTenantId

func GetApnsMsgByTenantId(tenantId string) ([]*ApnsMsg, error)

在数据库中查询资源.

func UpdateApnsMsgById

func UpdateApnsMsgById(apnsMsg *ApnsMsg) (*ApnsMsg, bool)

数据库中插入资源

type ApnsToken

type ApnsToken struct {
	Id        string    `json:"id"`
	UserId    string    `json:"userId"`
	DeviceId  string    `json:"deviceId"`
	ApnsToken string    `json:"apnsToken"`
	Created   time.Time `json:"created"`
	Updated   time.Time `json:"updated"`
}

apns_token证书

type BySort

type BySort struct {
	// contains filtered or unexported fields
}

func (BySort) Len

func (s BySort) Len() int

获取成员总数

func (BySort) Less

func (s BySort) Less(i, j int) bool

判断两个成员的顺序

func (BySort) Swap

func (s BySort) Swap(i, j int)

交换成员顺序

type Client

type Client struct {
	Id              string
	UserId          string
	Type            string
	DeviceId        string
	LatestLoginTime time.Time
	Created         time.Time
	Updated         time.Time
}

客户端结构.

设备登录的时候会记录.

type ClientVerUpdateMsg

type ClientVerUpdateMsg struct {
	MsgType       int                           `json:"msgType"`
	Content       string                        `json:"content"`
	ObjectContent *ClientVerUpdateObjectContent `json:"objectContent"`
}

客户端版本更新消息结构.

type ClientVerUpdateObjectContent

type ClientVerUpdateObjectContent struct {
	VersionCode int    `json:"versionCode"`
	VersionName string `json:"versionName"`
	URL         string `json:"url"`
	FileName    string `json:"fileName"`
}

客户端版本更新消息内嵌对象内容结构.

type ClientVersion

type ClientVersion struct {
	Id                 string    `json:"id"`
	Type               string    `json:"type"`
	VersionCode        int       `json:"versionCode"`
	VersionName        string    `json:"versionName"`
	VersionDescription string    `json:"versionDesc"`
	DownloadURL        string    `json:"url"`
	FileName           string    `json:"fileName"`
	Created            time.Time `json:"created"`
	Updated            time.Time `json:"updated"`
}

客户端版本结构.

type Config

type Config struct {
	HttpBind             []string          `goconf:"base:http.bind:,"`
	AdminBind            []string          `goconf:"base:admin.bind:,"`
	AppBind              []string          `goconf:"base:app.bind:,"`
	MaxProc              int               `goconf:"base:maxproc"`
	PprofBind            []string          `goconf:"base:pprof.bind:,"`
	User                 string            `goconf:"base:user"`
	PidFile              string            `goconf:"base:pidfile"`
	Dir                  string            `goconf:"base:dir"`
	Router               string            `goconf:"base:router"`
	QQWryPath            string            `goconf:"res:qqwry.path"`
	ZookeeperAddr        []string          `goconf:"zookeeper:addr:,"`
	ZookeeperTimeout     time.Duration     `goconf:"zookeeper:timeout:time"`
	ZookeeperCometPath   string            `goconf:"zookeeper:comet.path"`
	ZookeeperMessagePath string            `goconf:"zookeeper:message.path"`
	RPCRetry             time.Duration     `goconf:"rpc:retry:time"`
	RPCPing              time.Duration     `goconf:"rpc:ping:time"`
	RedisSource          map[string]string `goconf:"-"`
	RedisIdleTimeout     time.Duration     `goconf:"redis:timeout:time"`
	RedisMaxIdle         int               `goconf:"redis:idle"`
	RedisMaxActive       int               `goconf:"redis:active"`
	RedisMaxStore        int               `goconf:"redis:store"`
	RedisKetamaBase      int               `goconf:"redis:ketama.base"`
	TokenExpire          int               `goconf:"token:expire"`
	ApnsType             string            `goconf:"apns:type"`
}
var (
	Conf *Config
)

type ExternalInterface added in v1.2.0

type ExternalInterface struct {
	Id         string    `json:"id"`
	CustomerId string    `json:"customerId"`
	Type       string    `json:"type"`
	Owner      int       `json:"owner"`
	HttpUrl    string    `json:"httpUrl"`
	Created    time.Time `json:"created"`
	Updated    time.Time `json:"updated"`
}

func GetExtInterface added in v1.2.0

func GetExtInterface(customer_id, Type string) *ExternalInterface

根据customer_id 和type获取客户 提供的结构地址

type FileLink struct {
	Id       string
	SenderId string
	FileId   string
	FileName string
	FileUrl  string
	Size     int
	Created  time.Time
	Updated  time.Time
}

type Name

type Name struct {
	Id               string
	SessionId        string
	ActiveSessionIds []string
	Suffix           string
}

推送 Name.

type PushCnt added in v1.1.0

type PushCnt struct {
	Id         string
	CustomerId string
	TenantId   string
	CallerId   string
	Type       string
	PushType   string
	Count      int
	Sharding   int
	Created    time.Time
	Updated    time.Time
}

type Qun

type Qun struct {
	Id              string    `json:"id"`
	CreatorId       string    `json:"creatorId"`
	CreatorUserName string    `json:"creatorUserName"`
	Name            string    `json:"name"`
	Description     string    `json:"description"`
	MaxMember       int       `json:"maxMember"`
	Avatar          string    `json:"avatar"`
	TenantId        string    `json:"tenantId"`
	Created         time.Time `json:"created"`
	Updated         time.Time `json:"updated"`
}

群结构.

type QunUser

type QunUser struct {
	Id      string
	QunId   string
	UserId  string
	Sort    int
	Role    int
	Created time.Time
	Updated time.Time
}

群-用户关联结构.

type Quota added in v1.1.0

type Quota struct {
	Id         string
	CustomerId string
	TenantId   string
	ApiName    string
	Type       string
	Value      string
	Created    time.Time
	Updated    time.Time
	// contains filtered or unexported fields
}

func GetQuotas added in v1.1.0

func GetQuotas(customerId, tenantId, apiName string) ([]Quota, error)

获取配额信息.

type Resource

type Resource struct {
	Id          string    `json:"id"`
	CustomerId  string    `json:"customerId"`
	Name        string    `json:"name"`
	Description string    `json:"description"`
	Type        string    `json:"type"`
	Content     string    `json:"content"`
	Created     time.Time `json:"created"`
	Updated     time.Time `json:"updated"`
}

租户证书资源结构

func AddResource

func AddResource(resource *Resource) (*Resource, bool)

数据库中插入资源

func GetResourceById

func GetResourceById(resourceId string) (*Resource, error)

在数据库中查询资源.

func GetResourceByTenantId

func GetResourceByTenantId(tenantId string) ([]*Resource, error)

在数据库中查询资源.

func UpdateResource

func UpdateResource(resource *Resource) (*Resource, bool)

数据库中插入资源

type Tenant

type Tenant struct {
	Id         string    `json:"id"`
	Code       string    `json:"code"`
	Name       string    `json:"name"`
	Status     int       `json:"status"`
	CustomerId string    `json:"customerId"`
	Created    time.Time `json:"created"`
	Updated    time.Time `json:"updated"`
}

type UserUser

type UserUser struct {
	Id         string    `json:"id"`
	FromUserId string    `json:"fromUserId"`
	ToUserId   string    `json:"toUserId"`
	RemarkName string    `json:"remarkName"`
	Sort       int       `json:"sort"`
	Created    time.Time `json:"created"`
	Updated    time.Time `json:"updated"`
}

联系人结构.

Jump to

Keyboard shortcuts

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