app

package
v0.0.0-...-419ab0e Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2015 License: GPL-3.0 Imports: 25 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 (
	// 根据 id 查询应用记录.
	SelectApplicationById = "SELECT  * FROM `application` WHERE `id` = ?"
	// 查询应用记录.
	//SelectAllApplication = "select t.id, t.name, t.name, t.status, t.sort,t.avatar, t.tenant_id,t.name_py,t.name_quanpin ,t.description, IF( isnull(a.follow) ,t.follow,a.follow)  as follow from (SELECT * from application  where tenant_id = ? ) t left join  app_user a on t.id = a.appId and a.uid = ? "
	SelectAllApplication = "" /* 536-byte string literal not displayed */
	// 根据 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 "
	//插入用户关注的应用
	InsertAppUser = "INSERT INTO `app_user`(`id`,`appid`,`uid`,`follow`) VALUES(?,?,?,?)"
	//删除用户关注应用信息
	UpdateAppUser = "UPDATE  app_user  set follow = ?  where id = ? "
	//查询用户是否关注该企业号
	SelectAppUser = "SELECT `id`,`appid`,`uid`,`follow` FROM `app_user` where appid = ?  and uid = ? "
)
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_PC      = "pc"
	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  < ?"
	UPDATE_USER_AVATAR     = "update user set avatar = ? where id = ?"
	UPDATE_APP_AVATAR      = "update application set avatar = ? where id = ?"
)
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.
	InsertResourceSQL = "INSERT INTO `resource` (`id`, `customer_id`, `name`, `description`, `type`, `content`, `created`, `updated`) VALUES " +
		"(?, ?, ?, ?, ?, ?, ?, ?)"

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

	//根据nam查资源
	SelectResourceByNameSQL = "SELECT * FROM `resource` where `name` = ?"

	// 根据租户 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

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

记录api调用次数

func DeleteFile

func DeleteFile(fileId string) bool

删除weedfs服务器文件

func DeleteResourceById

func DeleteResourceById(resourceId string) bool

删除资源

func ExistFileLink(fileLink *FileLink) bool

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

func GetUserByME

func GetUserByME(key string) *member

通过手机和邮箱查询

func InitConfig

func InitConfig() error

InitConfig init configuration file.

func InitQuotaAll

func InitQuotaAll()

初始化配额配置

func InitRedisStorage

func InitRedisStorage()

initRedisStorage initialize the redis pool and consistency hash ring.

func LoadQuotaAll

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

func StatisticsPush(pushCnt *PushCnt)

统计消息推送

func UserErWeiMa

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

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

func ValidApiCall

func ValidApiCall(apiCall *ApiCall) bool

检验本次调用是否合法

func ValidPush

func ValidPush(pushCnt *PushCnt) bool

Types

type ApiCall

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 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:,"`
	AppPush              []string          `goconf:"base:app.push:,"`
	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"`
	WeedfsAddr           string            `goconf:"weedfs:address:"`
	WeedfsLocalAddr      string            `goconf:"weedfs:localAddress:"`
}
var (
	Conf *Config
)

type ExternalInterface

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

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 PushCnt

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 Quota

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

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 GetResourceByName

func GetResourceByName(name 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