common

package module
v1.0.0-20241129-1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: MIT Imports: 30 Imported by: 0

README

dapr-platform common library

Documentation

Overview

internal message 内部服务间各类消息

Index

Constants

View Source
const DbTimeFormat = "2006-01-02T15:04:05"
View Source
const JsonTimeFormat = "2006-01-02 15:04:05"

Variables

View Source
var (
	OK                 = response(0, "服务调用成功")
	BaseErrorNo        = OK.Status
	ErrNotFound        = response(BaseErrorNo+1, "服务调用成功,但没有找到相应数据")
	ErrDeleteError     = response(BaseErrorNo+2, "无法删除:")
	ErrParam           = response(BaseErrorNo+3, "参数有误")
	ErrSignParam       = response(BaseErrorNo+4, "签名参数有误")
	ErrReqBodyRead     = response(BaseErrorNo+5, "读取body有误")
	ErrReqBodyParse    = response(BaseErrorNo+6, "请求参数反序列化错误")
	ErrPubSubPublish   = response(BaseErrorNo+7, "发布消息错误")
	ErrServiceInvokeDB = response(BaseErrorNo+8, "调用数据库异常")
	ErrAddEdgeToGraph  = response(BaseErrorNo+9, "添加边到图异常")
	ErrService         = response(BaseErrorNo+10, "服务异常")
	ErrListUnMashal    = response(BaseErrorNo+11, "列表反序列化错误")
	ErrModelParse      = response(BaseErrorNo+12, "对象反序列化错误")
	ErrExists          = response(BaseErrorNo+13, "已存在")
	ErrAuthz           = response(BaseErrorNo+14, "没有权限")
)
View Source
var (
	PLATFORM_ALARM_TOPIC_NAME = "platform-alarm"
	EVENT_TOPIC_NAME          = "eventTopic"
	EVENT_DATA_TOPIC_NAME     = "eventDataTopic"
	EVENT_POINT_RW_META_TOPIC = "pointRWMetaTopic"
	EventArchivedFlag         = int32(1)

	EventTypePlatform = int32(1)
	EventTypeDevice   = int32(2)
	EventTypeSecurity = int32(3)

	EventSubTypeService      = int32(101)
	EventSubTypeInterface    = int32(102)
	EventSubTypeComunication = int32(103)

	EventStatusActive  = int32(1)
	EventStatusClosed  = int32(0)
	EventLevelCritical = int32(1)
	EventLevelMajor    = int32(2)
	EventLevelMinor    = int32(3)
	EventLevelWarning  = int32(4)
)

event指告警类事件

View Source
var BASE_CONTEXT = ""
View Source
var CENTER_DAPR_STATESTORE_NAME = "center-statestore"
View Source
var CENTER_DB_SERVICE_NAME = "center-db-service"
View Source
var CENTER_DB_UPSERT_TOPIC = "center_db_upsert_event"
View Source
var CENTER_GLOBAL_STATESTOR_NAME = "center-global-redis"
View Source
var CENTER_METHOD_INVOKE_TOPIC = "centerMethodInvoke"
View Source
var CENTER_PUBSUB_NAME = "center_pubsub"
View Source
var COMMON_MESSAGE_KEY_BUSINESS_TYPE = "business_type"
View Source
var COMMON_MESSAGE_KEY_CONNECT_ID = "connect_id"
View Source
var COMMON_MESSAGE_KEY_MARK = "mark"
View Source
var COMMON_MESSAGE_KEY_MESSAGE = "message"
View Source
var COMMON_MESSAGE_KEY_TO_ID = "to_id"
View Source
var COMMON_MESSAGE_KEY_TYPE = "type"
View Source
var COMMON_MESSAGE_TYPE_PONG = "pong"
View Source
var DAPR_STATESTORE_NAME = "statestore"
View Source
var DBNAME = "thingsdb"
View Source
var DB_SCHEMA = "public"
View Source
var DB_SERVICE_NAME = "db-service"
View Source
var DB_UPSERT_TOPIC = "db_upsert_event"
View Source
var DEVICE_DATA_TOPIC = "deviceData"
View Source
var DefaultmetricsPanel = []MetricPanel{
	{Row: 0, Col: 0, Title: "go协程数", Query: "go_goroutines{ident=\"${HOST}\",instance=\"${NAME}:80\"}", Type: "trend"},
	{Row: 0, Col: 1, Title: "go gc秒数", Query: "go_gc_duration_seconds{ident=\"${HOST}\",instance=\"${NAME}:80\"}", Type: "trend"},
	{Row: 0, Col: 2, Title: "go线程数", Query: "go_threads{ident=\"${HOST}\",instance=\"${NAME}:80\"}", Type: "trend"},
	{Row: 0, Col: 3, Title: "go分配对象数", Query: "go_memstats_heap_objects{ident=\"${HOST}\",instance=\"${NAME}:80\"}", Type: "trend"},
}
View Source
var EDGE_ID = ""
View Source
var FILE_SERVICE_NAME = "file-service"
View Source
var GLOBAL_STATESTOR_NAME = "global-redis"
View Source
var INTERNAL_MESSAGE_KEY_BUSINESS_TYPE = "business_type"
View Source
var INTERNAL_MESSAGE_KEY_CONNECT_ID = "connect_id"
View Source
var INTERNAL_MESSAGE_KEY_MARK = "mark"
View Source
var INTERNAL_MESSAGE_KEY_MESSAGE = "message"
View Source
var INTERNAL_MESSAGE_KEY_TYPE = "type"
View Source
var INTERNAL_MESSAGE_KEY_USER_ID = "user_id"
View Source
var INTERNAL_MESSAGE_TOPIC_NAME = "internal_msg"
View Source
var INTERNAL_MESSAGE_TYPE_SYS_LOG = "sys_log"
View Source
var INTERNAL_MESSAGE_TYPE_USER_LOGIN = "user_login"
View Source
var INTERNAL_MESSAGE_TYPE_USER_LOGOUT = "user_logout"
View Source
var INTERNAL_MESSAGE_TYPE_WEB_CONNECT = "web_connect"
View Source
var INTERNAL_MESSAGE_TYPE_WEB_DISCONNECT = "web_disconnect"
View Source
var Logger = logrus.New()
View Source
var METHOD_INVOKE_TOPIC = "methodInvoke"
View Source
var PROPERTY_SET_TOPIC = "property_set_event"
View Source
var PUBSUB_NAME = "pubsub"
View Source
var RESOURCE_CHANGE_TOPIC = "resourceChange"
View Source
var RUNNING_MODE = "center_edge"
View Source
var RUNNING_MODE_CENTER = "center"
View Source
var RUNNING_MODE_CENTER_EDGE = "center_edge"
View Source
var RUNNING_MODE_EDGE = "edge"
View Source
var USER_EXPIRED_SECONDS = 7200
View Source
var USER_STATESTORE_KEY_PREFIX = "user#"
View Source
var WEB_MESSAGE_TOPIC_NAME = "web"

message 指发送到UI的各类消息

Functions

func BulkSaveInStateStore

func BulkSaveInStateStore(ctx context.Context, client dapr.Client, stateStore string, key []string, data []string, expires bool, ttl time.Duration) (err error)

func CheckKeyInStateStore

func CheckKeyInStateStore(ctx context.Context, client dapr.Client, stateStore, key string) (bool, error)

func CommonDelete

func CommonDelete(w http.ResponseWriter, r *http.Request, client dapr.Client, tableName string, idField string, queryField string)

func CommonGroupby

func CommonGroupby(w http.ResponseWriter, r *http.Request, client dapr.Client, tableName string) (err error)

func CommonPageQuery

func CommonPageQuery[T any](w http.ResponseWriter, r *http.Request, client dapr.Client, tableName string, idFieldName string)

func CommonQuery

func CommonQuery[T any](w http.ResponseWriter, r *http.Request, client dapr.Client, tableName string, idFieldName string)

func CommonUpsert

func CommonUpsert(w http.ResponseWriter, r *http.Request, client dapr.Client, tableName string, keys string) (err error)

func CustomSql

func CustomSql[T any](ctx context.Context, client dapr.Client, selectField, fromField, whereField string) (result []T, err error)

func DaprCacheGet

func DaprCacheGet[T any](client dapr.Client, key string) (*T, error)

func DaprCacheGetGeneric

func DaprCacheGetGeneric[T any](ctx context.Context, client dapr.Client, dbFunc func(ctx context.Context, args ...any) (*T, error), key string, forceUpdate bool, expire bool, expireSeconds int, args ...any) (result *T, useStateStoreFlag bool, err error)

func DaprCacheSet

func DaprCacheSet(ctx context.Context, client dapr.Client, key string, value interface{}, expire bool, expireSeconds int) error

func DbBatchInsert

func DbBatchInsert[T any](ctx context.Context, client dapr.Client, val []T, tablename string) (err error)

func DbBatchUpsert

func DbBatchUpsert[T any](ctx context.Context, client dapr.Client, datas []T, tableName string, primaryKeys string) (err error)

func DbBatchUpsertIg

func DbBatchUpsertIg[T any](ctx context.Context, client dapr.Client, datas []T, tableName string, keys string, updateIgKeys string) (err error)

func DbDelete

func DbDelete(ctx context.Context, client dapr.Client, tableName string, idField string, id string) (err error)

func DbDeleteByOps

func DbDeleteByOps(ctx context.Context, client dapr.Client, tableName string, field []string, ops []string, val []any) error

func DbDeleteExpired

func DbDeleteExpired(ctx context.Context, client dapr.Client, tableName string, timeField string, expireTime time.Time) (err error)

func DbGetCount

func DbGetCount(ctx context.Context, client dapr.Client, tableName string, countField string, queryString string) (result int64, err error)

func DbGetOne

func DbGetOne[T any](ctx context.Context, client dapr.Client, tableName string, queryString string) (result *T, err error)

func DbQuery

func DbQuery[T any](ctx context.Context, client dapr.Client, tableName string, queryString string) (result []T, err error)

func DbRefreshContinuousAggregate

func DbRefreshContinuousAggregate(ctx context.Context, client dapr.Client, name, start, end string) (err error)

func DbRefreshContinuousAggregateFull

func DbRefreshContinuousAggregateFull(ctx context.Context, client dapr.Client, name string) (err error)

func DbUpdateByOps

func DbUpdateByOps(ctx context.Context, client dapr.Client, tableName string, data map[string]any, field []string, ops []string, val []any) error

func DbUpsert

func DbUpsert[T any](ctx context.Context, client dapr.Client, data T, tableName string, primaryKeys string) (err error)

func DbUpsertIg

func DbUpsertIg[T any](ctx context.Context, client dapr.Client, data T, tableName string, keys string, updateIgKeys string) (err error)

func DeleteKeyInStateStore

func DeleteKeyInStateStore(ctx context.Context, client dapr.Client, stateStore, key string) (err error)

func ExtractUserSub

func ExtractUserSub(r *http.Request) (sub string, err error)

func GetBatchDeleteBeforeHook

func GetBatchDeleteBeforeHook(key string) (f func(r *http.Request, in any) (out any, err error), exists bool)

func GetDaprClient

func GetDaprClient() client.Client

func GetDeleteBeforeHook

func GetDeleteBeforeHook(key string) (f func(r *http.Request, in any) (out any, err error), exists bool)

func GetIP

func GetIP(r *http.Request) string

GetIP returns request real ip.

func GetInStateStore

func GetInStateStore(ctx context.Context, client dapr.Client, stateStore, key string) ([]byte, error)

func GetMD5Hash

func GetMD5Hash(text string) string

func GetSha1Hash

func GetSha1Hash(text string) string

func GetUpsertBeforeHook

func GetUpsertBeforeHook(key string) (f func(r *http.Request, in any) (out any, err error), exists bool)

func HttpError

func HttpError(w http.ResponseWriter, response *Response, code int)

func HttpResult

func HttpResult(w http.ResponseWriter, response *Response)

func HttpSuccess

func HttpSuccess(w http.ResponseWriter, response *Response)

func MarshalWithRemoveKey

func MarshalWithRemoveKey(v interface{}, key string) ([]byte, error)

func NanoId

func NanoId() string

func PublishDbUpsertMessage

func PublishDbUpsertMessage(ctx context.Context, client dapr.Client, table, keys, ignorekeys string, batch bool, data any) error

func PublishMethodInvokeMessage

func PublishMethodInvokeMessage(ctx context.Context, client dapr.Client, event MethodInvokeInfo) error

func ReadRequestBody

func ReadRequestBody(r *http.Request, v interface{}) error

func ReadResponseBody

func ReadResponseBody(r *http.Response, v interface{}) error

func RegisterBatchDeleteBeforeHook

func RegisterBatchDeleteBeforeHook(key string, f func(r *http.Request, in any) (out any, err error))

func RegisterDeleteBeforeHook

func RegisterDeleteBeforeHook(key string, f func(r *http.Request, in any) (out any, err error))

func RegisterUpsertBeforeHook

func RegisterUpsertBeforeHook(key string, f func(r *http.Request, in any) (out any, err error))

func SaveInStateStore

func SaveInStateStore(ctx context.Context, client dapr.Client, stateStore, key string, data []byte, expires bool, ttl time.Duration) (err error)

Types

type AccessInfo

type AccessInfo struct {
	Aud string `json:"aud"` //client_id
	Exp int    `json:"exp"` //expired time
	Sub string `json:"sub"` //user_name
}

func ExtractJwt

func ExtractJwt(r *http.Request) (*AccessInfo, error)

func ExtractJwtFromMap

func ExtractJwtFromMap(m map[string]string) (*AccessInfo, error)

func ExtractJwtFromString

func ExtractJwtFromString(authVal string) (*AccessInfo, error)

type AutoRefreshCacher

type AutoRefreshCacher[T any] struct {
	Name          string
	Id            string
	ExpiredSecond int
	// contains filtered or unexported fields
}

func NewAutoRefreshCacher

func NewAutoRefreshCacher[T any](name string, expiredSecond int, expired bool, forceUpdate bool) *AutoRefreshCacher[T]

func (*AutoRefreshCacher[T]) DaprCacheGetGeneric

func (c *AutoRefreshCacher[T]) DaprCacheGetGeneric(ctx context.Context, client dapr.Client, dbFunc func(ctx context.Context, args ...any) (*T, error), key string, args ...any) (result *T, err error)

func (*AutoRefreshCacher[T]) Invalid

func (c *AutoRefreshCacher[T]) Invalid(client dapr.Client)

type BytesPage

type BytesPage struct {
	Page     int    `json:"page"`
	PageSize int    `json:"page_size"`
	Total    int    `json:"total"`
	Data     []byte `json:"data"`
}

type CommonMessage

type CommonMessage map[string]interface{}

type Count

type Count struct {
	Count int `json:"count"`
}

type DbUpsertEvent

type DbUpsertEvent struct {
	Db         string `json:"db"`
	Schema     string `json:"schema"`
	Table      string `json:"table"`
	Keys       string `json:"keys"`
	Batch      bool   `json:"batch"`
	Ignorekeys string `json:"ignorekeys"`
	Data       any    `json:"data"`
}

type Event

type Event struct {
	Dn          string    `json:"dn"`
	Title       string    `json:"title"`
	Type        int32     `json:"type"`
	Description string    `json:"description"`
	Status      int32     `json:"status"`
	Level       int32     `json:"level"`
	EventTime   LocalTime `json:"event_time"`
	CreateAt    LocalTime `json:"create_at"`
	UpdatedAt   LocalTime `json:"updated_at"`
	ObjectID    string    `json:"object_id"`
	ObjectName  string    `json:"object_name"`
	Location    string    `json:"location"`
}

type InternalMessage

type InternalMessage map[string]any

func (InternalMessage) FromStruct

func (m InternalMessage) FromStruct(s any) (err error)

func (InternalMessage) GetType

func (m InternalMessage) GetType() string

func (InternalMessage) SetType

func (m InternalMessage) SetType(t string)

type LocalNullableTime

type LocalNullableTime null.Time

func (LocalNullableTime) DbString

func (t LocalNullableTime) DbString() string

func (LocalNullableTime) MarshalJSON

func (t LocalNullableTime) MarshalJSON() ([]byte, error)

func (*LocalNullableTime) Scan

func (t *LocalNullableTime) Scan(v interface{}) error

func (LocalNullableTime) String

func (t LocalNullableTime) String() string

func (*LocalNullableTime) UnmarshalJSON

func (t *LocalNullableTime) UnmarshalJSON(data []byte) (err error)

func (LocalNullableTime) Value

func (t LocalNullableTime) Value() (driver.Value, error)

type LocalTime

type LocalTime time.Time

func (LocalTime) DbString

func (t LocalTime) DbString() string

func (LocalTime) MarshalJSON

func (t LocalTime) MarshalJSON() ([]byte, error)

func (*LocalTime) Scan

func (t *LocalTime) Scan(v interface{}) error

func (LocalTime) String

func (t LocalTime) String() string

func (*LocalTime) UnmarshalJSON

func (t *LocalTime) UnmarshalJSON(data []byte) (err error)

func (LocalTime) Value

func (t LocalTime) Value() (driver.Value, error)

type MethodInvokeInfo

type MethodInvokeInfo struct {
	Service string `json:"service"`
	Method  string `json:"method"` //"GET POST PUT DELETE"
	Url     string `json:"url"`
	Data    any    `json:"data"`
}

type MetricPanel

type MetricPanel struct {
	Row   int    `json:"row"`
	Col   int    `json:"col"`
	Title string `json:"title"`
	Query string `json:"query"`
	Type  string `json:"type"` //trend,bar,current,stack,etc..
}

type MyFormatter

type MyFormatter struct{}

func (*MyFormatter) Format

func (m *MyFormatter) Format(entry *logrus.Entry) ([]byte, error)

type Page

type Page struct {
	Page     int         `json:"page"`
	PageSize int         `json:"page_size"`
	Total    int         `json:"total"`
	Items    interface{} `json:"items"`
}

type PageGeneric

type PageGeneric[T any] struct {
	Page     int `json:"page"`
	PageSize int `json:"page_size"`
	Total    int `json:"total"`
	Items    []T `json:"items"`
}

func DbPageQuery

func DbPageQuery[T any](ctx context.Context, client dapr.Client, page, pageSize int, orderField string, tableName string, idFieldName string, queryString string) (pageResult *PageGeneric[T], err error)

type Response

type Response struct {
	Status int         `json:"status"`
	Msg    string      `json:"msg"`
	Data   interface{} `json:"data"`
}

func DbInsert

func DbInsert[T any](ctx context.Context, client dapr.Client, data T, tableName string) (resp *Response, err error)

func (*Response) AppendMsg

func (res *Response) AppendMsg(msg string) *Response

func (*Response) ToBytes

func (res *Response) ToBytes() []byte

func (*Response) WithData

func (res *Response) WithData(data interface{}) *Response

type ResponseGeneric

type ResponseGeneric[T any] struct {
	Status int    `json:"status"`
	Msg    string `json:"msg"`
	Data   T      `json:"data"`
}

type SyslogMessage

type SyslogMessage struct {
	Type   string `json:"type"`
	UserId string `json:"user_id"`
	Ip     string `json:"ip"`
	Action int    `json:"action"`
	Info   string `json:"info"`
}

func (*SyslogMessage) FromInternalMessage

func (s *SyslogMessage) FromInternalMessage(m InternalMessage)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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