vanilla

package
v1.20.76 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const ERROR_TYPE_BUSINESS = 0
View Source
const ERROR_TYPE_SYSTEM = 1
View Source
const InvalidJwtError = "jwt:invalid_jwt_token"
View Source
const MAX_DISTANCE = -1
View Source
const SALT string = "030e2cf548cf9da683e340371d1a74ee"
View Source
const SERVICE_MODE_CRON = "cron"
View Source
const SERVICE_MODE_EVENT = "event"
View Source
const SERVICE_MODE_REST = "rest"

Variables

View Source
var (
	REQUEST_MODE_PROD     = "PROD"
	REQUEST_MODE_TEST     = "TEST"
	REQUEST_HEADER_FORMAT = "Request-Mode"
	REQUEST_MODE_CTX_KEY  = "REQUEST_MODE"
)
View Source
var AREA = make(map[string][]map[string]interface{})
View Source
var Closer io.Closer
View Source
var PROVINCEID2ZONE = map[int]string{
	1:  "直辖市",
	2:  "直辖市",
	3:  "华北-东北",
	4:  "华北-东北",
	5:  "华北-东北",
	6:  "华北-东北",
	7:  "华北-东北",
	8:  "华北-东北",
	9:  "直辖市",
	10: "华东地区",
	11: "华东地区",
	12: "华东地区",
	13: "华东地区",
	14: "华东地区",
	15: "华东地区",
	16: "华南-华中",
	17: "华南-华中",
	18: "华南-华中",
	19: "华南-华中",
	20: "华南-华中",
	21: "华南-华中",
	22: "直辖市",
	23: "西北-西南",
	24: "西北-西南",
	25: "西北-西南",
	26: "西北-西南",
	27: "西北-西南",
	28: "西北-西南",
	29: "西北-西南",
	30: "西北-西南",
	31: "西北-西南",
	32: "其它",
	33: "其它",
	34: "其它",
}
View Source
var RESOURCES = make([]string, 0, 100)

RESOURCES 所有资源名的集合

View Source
var Redis *redisStruct = &redisStruct{}
View Source
var Tracer opentracing.Tracer
View Source
var ZONE_NAMES = []string{"直辖市", "华北-东北", "华东地区", "华南-华中", "西北-西南", "其它"}

Functions

func Decimal

func Decimal(value float64) float64

func DecodeJWT

func DecodeJWT(jwtToken string) (*simplejson.Json, error)

func EncodeJWT

func EncodeJWT(data Map) string

func ExtractUniqueIds

func ExtractUniqueIds(datas []IIDable, idType string) []int

func GetOrmFromContext

func GetOrmFromContext(ctx context.Context) orm.Ormer

func GetRequestModeFromCtx

func GetRequestModeFromCtx(ctx context.Context) *requestMode

GetRequestModeFromCtx 获取请求模式 首先从ctx中获取,如果没有则进行以下判断

生产环境:默认prod
测试环境:如果请求gaia出错,则默认为test

func GetServiceMode

func GetServiceMode() string

func HostDomain

func HostDomain(host string) string

func ParseTime

func ParseTime(strTime string) time.Time

func ParseUserIdFromJwtData

func ParseUserIdFromJwtData(js *simplejson.Json) (int, int, error)

func ParseUserIdFromJwtToken

func ParseUserIdFromJwtToken(jwtToken string) (int, int, error)

func RecoverFromCronTaskPanic

func RecoverFromCronTaskPanic(ctx go_context.Context)

RecoverFromCronTaskPanic crontask的recover

func RecoverPanic

func RecoverPanic(ctx *context.Context)

func Router

func Router(r RestResourceInterface)

Router 添加路由

func RunInGoroutine

func RunInGoroutine(task func())

func Strftime

func Strftime(t *time.Time, f string) string

Strftime formats time.Date according to the directives in the given format string. The directives begins with a percent (%) character.

func ToJsonString

func ToJsonString(obj interface{}) string

func WrapLog

func WrapLog()

Router 添加路由

Types

type APIServiceNextPageInfo

type APIServiceNextPageInfo struct {
	HasNext    bool
	NextFromId int64
}

Mobile模式的分页结果

func (APIServiceNextPageInfo) ToMap

func (this APIServiceNextPageInfo) ToMap() map[string]interface{}

type Area

type Area struct {
	Province *Province
	City     *City
	District *District
}

type AreaService

type AreaService struct {
	ServiceBase
}

func NewAreaService

func NewAreaService() *AreaService

func (*AreaService) GetAreaByCode

func (this *AreaService) GetAreaByCode(code string) *Area

GetAreaByCode 根据area code(1_1_1)获取area

func (*AreaService) GetAreaByName

func (this *AreaService) GetAreaByName(name string) *Area

GetAreaByName 根据area name(北京市 北京市 东城区)获得area

func (*AreaService) GetCitiesByIds

func (this *AreaService) GetCitiesByIds(ids []int) []*City

func (*AreaService) GetCitiesByNames

func (this *AreaService) GetCitiesByNames(names []string) []*City

func (*AreaService) GetCitiesForProvince

func (this *AreaService) GetCitiesForProvince(provinceId int) []*City

func (*AreaService) GetCityById

func (this *AreaService) GetCityById(id int) *City

func (*AreaService) GetCityByName

func (this *AreaService) GetCityByName(name string) *City

func (*AreaService) GetCityByNameInProvince

func (this *AreaService) GetCityByNameInProvince(provinceId int, name string) *City

func (*AreaService) GetDistrictById

func (this *AreaService) GetDistrictById(id int) *District

func (*AreaService) GetDistrictByName

func (this *AreaService) GetDistrictByName(cityId int, name string) *District

District相关api

func (*AreaService) GetDistrictsByIds

func (this *AreaService) GetDistrictsByIds(ids []int) []*District

func (*AreaService) GetDistrictsByNames

func (this *AreaService) GetDistrictsByNames(cityId int, names []string) []*District

func (*AreaService) GetDistrictsForCity

func (this *AreaService) GetDistrictsForCity(cityId int) []*District

func (*AreaService) GetProvinceById

func (this *AreaService) GetProvinceById(id int) *Province

func (*AreaService) GetProvinceByName

func (this *AreaService) GetProvinceByName(name string) *Province

func (*AreaService) GetProvinces

func (this *AreaService) GetProvinces() []*Province

func (*AreaService) GetProvincesByIds

func (this *AreaService) GetProvincesByIds(ids []int) []*Province

func (*AreaService) GetProvincesByNames

func (this *AreaService) GetProvincesByNames(names []string) []*Province

type BusinessError

type BusinessError struct {
	Type    int
	ErrCode string
	ErrMsg  string
}

func NewBusinessError

func NewBusinessError(code string, msg string) *BusinessError

func NewSystemError

func NewSystemError(code string, msg string) *BusinessError

func (*BusinessError) Error

func (this *BusinessError) Error() string

func (*BusinessError) IsPanicError

func (this *BusinessError) IsPanicError() bool

type City

type City struct {
	Id         int
	ProvinceId int
	Name       string
	ZipCode    string
	Districts  []*District
}

func NewCity

func NewCity(data map[string]interface{}) *City

type ConsoleController

type ConsoleController struct {
	beego.Controller
}

func (*ConsoleController) Get

func (c *ConsoleController) Get()

type DingBot

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

func NewDingBot

func NewDingBot() *DingBot

func (*DingBot) Critical

func (this *DingBot) Critical(msg string)

Critical 严重错误

func (*DingBot) Error

func (this *DingBot) Error(msg string)

Error 错误

func (*DingBot) Info

func (this *DingBot) Info(msg string)

Info 通知

func (*DingBot) SetToken

func (this *DingBot) SetToken(token string) *DingBot

func (*DingBot) Use

func (this *DingBot) Use(name string) *DingBot

func (*DingBot) Warn

func (this *DingBot) Warn(msg string)

Warn 警告

type District

type District struct {
	Id     int
	CityId int
	Name   string
}

func NewDistrict

func NewDistrict(data map[string]interface{}) *District

type DummyLock

type DummyLock struct {
}

DummyLock 空的锁引擎

func (*DummyLock) Lock

func (this *DummyLock) Lock(key string, args ...*LockOption) (*redsync.Mutex, error)

type EntityBase

type EntityBase struct {
	Ctx   context.Context
	Model interface{}
}

type FillOption

type FillOption = map[string]bool

type GeoService

type GeoService struct {
	ServiceBase
}

func NewGeoService

func NewGeoService(ctx context.Context) *GeoService

func (*GeoService) CalculateDistance

func (this *GeoService) CalculateDistance(lat1, lng1, lat2, lng2 float64) float64

func (*GeoService) CalculateDistanceUseStr

func (this *GeoService) CalculateDistanceUseStr(strLat1, strLng1, strLat2, strLng2 string) float64

type IBusinessContextFactory

type IBusinessContextFactory interface {
	NewContext(ctx context.Context, request *http.Request, userId int, jwtToken string, rawData *simplejson.Json) context.Context
}

type IIDable

type IIDable interface {
	GetId(idType string) int
}

type ILock

type ILock interface {
	Lock(key string, args ...*LockOption) (*redsync.Mutex, error)
}
var Lock ILock //暴露的锁

type IModel

type IModel interface {
	GetId() int
}

type INextPageInfo

type INextPageInfo interface {
	ToMap() map[string]interface{}
}

INextPageInfo

func MockPaginate

func MockPaginate(itemCount int64, page *PageInfo) INextPageInfo

MockPaginate 模拟进行分页

func MockPaginateV2

func MockPaginateV2(itemCount int, page *PageInfo) (INextPageInfo, int, int)

MockPaginate 模拟进行分页

func NewPaginateResultFromData

func NewPaginateResultFromData(js *simplejson.Json) INextPageInfo

func Paginate

func Paginate(objects orm.QuerySeter, page *PageInfo, container interface{}) (INextPageInfo, error)

PaginateAndFill 进行分页,并获取填充数据

type IndexController

type IndexController struct {
	beego.Controller
}

func (*IndexController) Get

func (c *IndexController) Get()

type LockOption

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

func NewLockOption

func NewLockOption(key string) *LockOption

func (*LockOption) SetTimeout

func (this *LockOption) SetTimeout(n int) *LockOption

func (*LockOption) SetTryTimes

func (this *LockOption) SetTryTimes(n int) *LockOption

type Map

type Map = map[string]interface{}

func ConvertToBeegoOrmFilter

func ConvertToBeegoOrmFilter(filters Map) Map

func GetMachineInfo

func GetMachineInfo() Map

GetMachineInfo 获取机器相关信息,目前包括hostname, ip address

type OpHealthController

type OpHealthController struct {
	beego.Controller
}

func (*OpHealthController) Get

func (c *OpHealthController) Get()

type PageInfo

type PageInfo struct {
	Page         int
	FromId       int
	CountPerPage int
	Mode         string
	Direction    string
}

PageInfo 指示当前查询的数据的page信息

func ExtractPageInfoFromRequest

func ExtractPageInfoFromRequest(ctx *context.Context) *PageInfo

ExtractPageInfoFromRequest 从Request中抽取page信息

func (*PageInfo) Asc

func (self *PageInfo) Asc() *PageInfo

func (*PageInfo) Desc

func (self *PageInfo) Desc() *PageInfo

func (*PageInfo) IsApiServerMode

func (self *PageInfo) IsApiServerMode() bool

type PaginateResult

type PaginateResult struct {
	HasPrev      bool
	HasNext      bool
	HasHead      bool
	HasTail      bool
	Prev         int
	Next         int
	CurPage      int
	MaxPage      int
	TotalCount   int64
	DisplayPages []int

	Offset      int
	CountInPage int
}

PaginateResult 分页的结果

func (PaginateResult) ToMap

func (this PaginateResult) ToMap() map[string]interface{}

type Province

type Province struct {
	Id     int
	Name   string
	Zone   string
	Cities []*City
}

func NewProvince

func NewProvince(data map[string]interface{}) *Province

func (*Province) IsDGC

func (this *Province) IsDGC() bool

IsDGC 是否是直辖市

type RedisLock

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

RedisLock 基于redis的锁引擎

func (*RedisLock) Lock

func (this *RedisLock) Lock(key string, args ...*LockOption) (*redsync.Mutex, error)

type RepositoryBase

type RepositoryBase struct {
	Ctx context.Context
}

type Resource

type Resource struct {
	Ctx            context.Context
	CustomJWTToken string
	// contains filtered or unexported fields
}

RestResource 扩展beego.Controller, 作为rest中各个资源的基类

func CronLogin

func CronLogin(o orm.Ormer) (*Resource, error)

func NewResource

func NewResource(ctx context.Context) *Resource

func (*Resource) Delete

func (this *Resource) Delete(service string, resource string, data Map) (resp *ResourceResponse, err error)

func (*Resource) DisableRetry

func (this *Resource) DisableRetry() *Resource

func (*Resource) Get

func (this *Resource) Get(service string, resource string, data Map) (resp *ResourceResponse, err error)

func (*Resource) LoginAs

func (this *Resource) LoginAs(username string) *Resource

func (*Resource) LoginAsManager

func (this *Resource) LoginAsManager() *Resource

func (*Resource) LoginAsUser

func (this *Resource) LoginAsUser(unionid string) *Resource

func (*Resource) Post

func (this *Resource) Post(service string, resource string, data Map) (resp *ResourceResponse, err error)

func (*Resource) Put

func (this *Resource) Put(service string, resource string, data Map) (resp *ResourceResponse, err error)

type ResourceResponse

type ResourceResponse struct {
	RespData *simplejson.Json
}

func (*ResourceResponse) Bind

func (this *ResourceResponse) Bind(container interface{}) error

Bind 将respData映射到struct,container一定要是指针类型

func (*ResourceResponse) Data

func (this *ResourceResponse) Data() *simplejson.Json

func (*ResourceResponse) IsSuccess

func (this *ResourceResponse) IsSuccess() bool

type Response

type Response struct {
	Code        int32                  `json:"code"`
	Data        interface{}            `json:"data"`
	ErrCode     string                 `json:"errCode"`
	ErrMsg      string                 `json:"errMsg"`
	InnerErrMsg string                 `json:"innerErrMsg"`
	MachineInfo map[string]interface{} `json:"_pod"`
}

func MakeErrorResponse

func MakeErrorResponse(code int32, errCode string, errMsg string, innerErrMsgs ...string) *Response

func MakeResponse

func MakeResponse(data interface{}) *Response

func MakeResponse2

func MakeResponse2(data map[string]interface{}) *Response

type Response2

type Response2 struct {
	Code        int32                  `json:"code"`
	Data        map[string]interface{} `json:"data"`
	ErrCode     string                 `json:"errCode"`
	ErrMsg      string                 `json:"errMsg"`
	InnerErrMsg string                 `json:"innerErrMsg"`
}

type RestProxy

type RestProxy struct {
	RestResource
}

func (*RestProxy) Get

func (this *RestProxy) Get()

func (*RestProxy) Resource

func (this *RestProxy) Resource() string

type RestRequest

type RestRequest struct {
	Path   string `json:"path"`
	Method string `json:"method"`
	Params string `json:"params"`
	Rid    string `json:"rid"`
}

type RestResource

type RestResource struct {
	beego.Controller

	Name2JSON      map[string]map[string]interface{}
	Name2RAWJSON   map[string]*simplejson.Json
	Name2JSONArray map[string][]interface{}
	Filters        map[string]interface{}
}

RestResource 扩展beego.Controller, 作为rest中各个资源的基类

func (*RestResource) Delete

func (c *RestResource) Delete()

Delete adds a request function to handle DELETE request.

func (*RestResource) DisableTx

func (r *RestResource) DisableTx() bool

DisableTx 是否关闭事务支持

func (*RestResource) EnableHTMLResource

func (r *RestResource) EnableHTMLResource() bool

EnableHTMLResource 是否开启html资源

func (*RestResource) Finish

func (r *RestResource) Finish()

func (*RestResource) Get

func (c *RestResource) Get()

Get adds a request function to handle GET request.

func (*RestResource) GetAlias

func (r *RestResource) GetAlias() []string

GetAlias 返回别名集合

func (*RestResource) GetBusinessContext

func (r *RestResource) GetBusinessContext() context.Context

func (*RestResource) GetCorpToken

func (r *RestResource) GetCorpToken() string

func (*RestResource) GetFillOptions

func (r *RestResource) GetFillOptions(key string) FillOption

func (*RestResource) GetFilters

func (r *RestResource) GetFilters() map[string]interface{}

返回filters参数与__f标准查询的map数据

func (*RestResource) GetIntArray

func (r *RestResource) GetIntArray(key string) []int

func (*RestResource) GetJSON

func (r *RestResource) GetJSON(key string) map[string]interface{}

GetJSONArray 与key对应的返回json map数据

func (*RestResource) GetJSONArray

func (r *RestResource) GetJSONArray(key string) []interface{}

GetJSONArray 与key对应的返回json array数据

func (*RestResource) GetLockKey

func (r *RestResource) GetLockKey() string

GetLockKey 获取锁的key

func (*RestResource) GetLockOption

func (r *RestResource) GetLockOption() *LockOption

func (*RestResource) GetParameters

func (r *RestResource) GetParameters() map[string][]string

Parameters 获取需要检查的参数

func (*RestResource) GetRawJSON

func (r *RestResource) GetRawJSON(key string) *simplejson.Json

GetRawJSON 与key对应的返回json数据

func (*RestResource) GetStringArray

func (r *RestResource) GetStringArray(key string) []string

func (*RestResource) HandlerFunc

func (c *RestResource) HandlerFunc(fnname string) bool

HandlerFunc call function with the name

func (*RestResource) Head

func (c *RestResource) Head()

Head adds a request function to handle HEAD request.

func (*RestResource) Init

func (c *RestResource) Init(ctx *beego_context.Context, controllerName, actionName string, app interface{})

Init generates default values of controller operations.

func (*RestResource) IsForDevTest

func (r *RestResource) IsForDevTest() bool

IsForDevTest 是否是开发时支持的资源

func (*RestResource) Mapping

func (c *RestResource) Mapping(method string, fn func())

Mapping the method to function

func (*RestResource) Options

func (c *RestResource) Options()

Options adds a request function to handle OPTIONS request.

func (*RestResource) Patch

func (c *RestResource) Patch()

Patch adds a request function to handle PATCH request.

func (*RestResource) Post

func (c *RestResource) Post()

Post adds a request function to handle POST request.

func (*RestResource) Prepare

func (r *RestResource) Prepare()

Prepare 实现beego.Controller的Prepare函数

func (*RestResource) Put

func (c *RestResource) Put()

Put adds a request function to handle PUT request.

func (*RestResource) Resource

func (r *RestResource) Resource() string

Resource 返回resource名

func (*RestResource) ReturnJSON

func (r *RestResource) ReturnJSON(response *Response)

ReturnJSON 返回json response

func (*RestResource) SetBeegoController

func (r *RestResource) SetBeegoController(ctx *beego_context.Context, data map[interface{}]interface{})

func (*RestResource) URLMapping

func (c *RestResource) URLMapping()

URLMapping register the internal RestResource router.

type RestResourceInterface

type RestResourceInterface interface {
	beego.ControllerInterface
	Resource() string
	GetAlias() []string
	EnableHTMLResource() bool
	IsForDevTest() bool
	DisableTx() bool
	GetParameters() map[string][]string
	GetBusinessContext() context.Context
	SetBeegoController(ctx *beego_context.Context, data map[interface{}]interface{})
	GetLockKey() string
	GetLockOption() *LockOption
}

type ServiceBase

type ServiceBase struct {
	Ctx context.Context
}

type Timedelta

type Timedelta struct {
	Days, Seconds, Microseconds, Milliseconds, Minutes, Hours, Weeks time.Duration
}

Timedelta represents a duration between two dates. All fields are optional and default to 0. You can initialize any type of timedelta by specifying field values which you want to use.

func (*Timedelta) Abs

func (t *Timedelta) Abs() Timedelta

Abs returns the absolute value of t

func (*Timedelta) Add

func (t *Timedelta) Add(t2 *Timedelta) Timedelta

Add returns the Timedelta t+t2.

func (*Timedelta) Duration

func (t *Timedelta) Duration() time.Duration

Duration() returns time.Duration. time.Duration can be added to time.Date.

func (*Timedelta) String

func (t *Timedelta) String() string

String returns a string representing the Timedelta's duration in the form "72h3m0.5s".

func (*Timedelta) Subtract

func (t *Timedelta) Subtract(t2 *Timedelta) Timedelta

Subtract returns the Timedelta t-t2.

type WsResponse

type WsResponse struct {
	*Response
	Rid string `json:"rid"`
}

func WsRestRecoverPanic

func WsRestRecoverPanic(err interface{}, ctx *context.Context, restReq RestRequest) (resp WsResponse)

Directories

Path Synopsis
mns
Package backoff implements backoff algorithms for retrying operations.
Package backoff implements backoff algorithms for retrying operations.
gogap
stack
Package stack provides utilities to capture and pass around stack traces.
Package stack provides utilities to capture and pass around stack traces.
BatchConsumer 实现了批量同步的向接收端传送数据的功能
BatchConsumer 实现了批量同步的向接收端传送数据的功能

Jump to

Keyboard shortcuts

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