design_principles

package
v0.0.0-...-184aab5 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const IdentifierString = "UEUEUE;"

Variables

View Source
var (
	InvalidUsernameErr = errors.New("invalid username")
	InvalidPasswordErr = errors.New("invalid password")
)
View Source
var (
	InvalidEmailErr         = errors.New("invalid email")
	AuthorizationFailureErr = errors.New("authorization failure")
)
View Source
var NoAuthorizationErr = errors.New("no authorization runtime error")

Functions

func Average

func Average(dataSet []int64)

func CheckIfIPValid

func CheckIfIPValid(ip string) bool

func IsValidIP

func IsValidIP(ip string) bool

func IsValidIPAddressV1

func IsValidIPAddressV1(ip string) bool

IsValidIPAddressV1 使用正则表达式

func IsValidIPAddressV2

func IsValidIPAddressV2(ip string) bool

IsValidIPAddressV2 使用 net 库中的 ParseIP 函数

func IsValidIPAddressV3

func IsValidIPAddressV3(ip string) bool

IsValidIPAddressV3 手写,只实现了解析以点分割的 IPv4

func KMP

func KMP(a, b []byte, n, m int) int

KMP - a: 主串 - b:模式串 - n:主串长度 - m:模式串长度

func Max

func Max(dataSet []int64)

func Min

func Min(dataSet []int64)

Types

type Alert

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

func NewAlert

func NewAlert(rule AlertRule, notification Notification) *Alert

func (*Alert) CheckV1

func (a *Alert) CheckV1(api string, requestCount, errorCount, durationOfSeconds int)

CheckV1 第一版

func (*Alert) CheckV2

func (a *Alert) CheckV2(api string, requestCount, errorCount, timeoutCount, durationOfSeconds int)

CheckV2 第二版

type AlertHandler

type AlertHandler interface {
	Check(info *ApiStatInfo)
}

type AlertRule

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

AlertRule 存储告警规则

func (*AlertRule) GetMatchedRule

func (a *AlertRule) GetMatchedRule(api string) *AlertRule

func (*AlertRule) GetMaxErrorCount

func (a *AlertRule) GetMaxErrorCount() int

func (*AlertRule) GetMaxTimeoutTps

func (a *AlertRule) GetMaxTimeoutTps() int

func (*AlertRule) GetMaxTps

func (a *AlertRule) GetMaxTps() int

type AlertRuleV3

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

func NewAlertRuleV3

func NewAlertRuleV3(maxTps int, maxErrorCount int, maxTimeoutTps int) *AlertRuleV3

func (*AlertRuleV3) GetMatchedRule

func (a *AlertRuleV3) GetMatchedRule(api string) *AlertRuleV3

func (*AlertRuleV3) GetMaxErrorCount

func (a *AlertRuleV3) GetMaxErrorCount() int

func (*AlertRuleV3) GetMaxTimeoutTps

func (a *AlertRuleV3) GetMaxTimeoutTps() int

func (*AlertRuleV3) GetMaxTps

func (a *AlertRuleV3) GetMaxTps() int

type AlertV3

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

func NewAlertV3

func NewAlertV3() *AlertV3

func (*AlertV3) AddAlertHandler

func (a *AlertV3) AddAlertHandler(handler ...AlertHandler)

func (*AlertV3) Check

func (a *AlertV3) Check(info *ApiStatInfo)

type ApiStatInfo

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

func NewDefaultApiStatInfo

func NewDefaultApiStatInfo() *ApiStatInfo

func (*ApiStatInfo) GetApi

func (i *ApiStatInfo) GetApi() string

func (*ApiStatInfo) GetDurationOfSeconds

func (i *ApiStatInfo) GetDurationOfSeconds() int

func (*ApiStatInfo) GetErrorCount

func (i *ApiStatInfo) GetErrorCount() int

func (*ApiStatInfo) GetRequestCount

func (i *ApiStatInfo) GetRequestCount() int

func (*ApiStatInfo) GetTimeoutCount

func (i *ApiStatInfo) GetTimeoutCount() int

type ApolloConfigSource

type ApolloConfigSource struct{}

func NewApolloConfigSource

func NewApolloConfigSource() *ApolloConfigSource

type ApplicationContext

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

ApplicationContext 负责 Alert 的创建、组装(alertRule 和 notification 的依赖注入)、初始化(添加 handlers)工作

var (
	ApplicationContextInstance *ApplicationContext // 单例

)

func GetApplicationContextInstance

func GetApplicationContextInstance() *ApplicationContext

func NewApplicationContext

func NewApplicationContext() *ApplicationContext

func (*ApplicationContext) GetAlert

func (a *ApplicationContext) GetAlert() *AlertV3

type BaseHandler

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

func NewBaseHandler

func NewBaseHandler(rule *AlertRuleV3, notification *NotificationV3) *BaseHandler

type ConfigServer

type ConfigServer struct {
	*http.Server
	// contains filtered or unexported fields
}

ConfigServer 对外暴露配置信息的类

func NewConfigServer

func NewConfigServer(host string, port int) *ConfigServer

func (*ConfigServer) AddViewer

func (c *ConfigServer) AddViewer(urlDirectory string, viewer Viewer)

func (*ConfigServer) Run

func (c *ConfigServer) Run()

type ConfigSource

type ConfigSource interface {
	// contains filtered or unexported methods
}

ConfigSource 配置中心,如 Zookeeper/Apollo

type Customer

type Customer struct{}

type CustomerRepo

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

func (*CustomerRepo) CheckIfUserExisted

func (r *CustomerRepo) CheckIfUserExisted(email, password string) (bool, error)

func (*CustomerRepo) GetUserByEmail

func (r *CustomerRepo) GetUserByEmail(email string) (*Customer, error)

type CustomerRepoV2

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

func (*CustomerRepoV2) CheckIfUserExisted

func (r *CustomerRepoV2) CheckIfUserExisted(email, password string) (bool, error)

func (CustomerRepoV2) GetUserByEmail

func (r CustomerRepoV2) GetUserByEmail(email string) (*Customer, error)

type CustomerService

type CustomerService struct {
	CustomerRepo
}

func NewCustomerService

func NewCustomerService(customerRepo CustomerRepo) *CustomerService

func (*CustomerService) Login

func (s *CustomerService) Login(email, password string) (*Customer, error)

type CustomerServiceV2

type CustomerServiceV2 struct {
	CustomerRepoV2
}

func NewCustomerServiceV2

func NewCustomerServiceV2(customerRepoV2 CustomerRepoV2) *CustomerServiceV2

func (*CustomerServiceV2) Login

func (s *CustomerServiceV2) Login(email, password string) (*Customer, error)

type DefaultSerialization

type DefaultSerialization struct{}

func (*DefaultSerialization) Deserialize

func (d *DefaultSerialization) Deserialize(str string) interface{}

func (*DefaultSerialization) Serialize

func (s *DefaultSerialization) Serialize(obj interface{}) string

type Demo

type Demo struct {
	MessageQueue // 基于接口而非实现编程
}

func NewDemo

func NewDemo(messageQueue MessageQueue) *Demo

func (*Demo) SendNotification

func (d *Demo) SendNotification(info Infos, formatter MessageFormatter)

type Deserializer

type Deserializer struct{}

func (*Deserializer) Deserialize

func (d *Deserializer) Deserialize(str string) interface{}

type Deserializers

type Deserializers interface {
	Deserialize(str string) interface{}
}

type Document

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

func NewDocument

func NewDocument(url string) (*Document, error)

func NewDocumentV2

func NewDocumentV2(url string, html *HTML) (*Document, error)

type DocumentFactory

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

DocumentFactory 通过工厂方法来创建Document

func NewDocumentFactory

func NewDocumentFactory(downloader HtmlDownloader) *DocumentFactory

func (*DocumentFactory) CreateDocument

func (f *DocumentFactory) CreateDocument(url string) (*Document, error)

type ErrorAlertHandler

type ErrorAlertHandler struct {
	*BaseHandler
}

func NewErrorAlertHandler

func NewErrorAlertHandler(rule *AlertRuleV3, notification *NotificationV3) *ErrorAlertHandler

func (*ErrorAlertHandler) Check

func (e *ErrorAlertHandler) Check(info *ApiStatInfo)

type HTML

type HTML struct{}

func NewHTML

func NewHTML(raw []byte) *HTML

type HtmlDownloader

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

func NewHtmlDownloader

func NewHtmlDownloader(networkTransporter *NetworkTransporter) *HtmlDownloader

func (*HtmlDownloader) DownloadHTML

func (d *HtmlDownloader) DownloadHTML(url string) (*HTML, error)

type InboxSender

type InboxSender struct{}

InboxSender 站内信发送类

func NewInboxSender

func NewInboxSender() *InboxSender

func (*InboxSender) Send

func (i *InboxSender) Send(cellphone, message string)

type Infos

type Infos struct{}

Infos 带发送的消息

type JsonMessageFormatter

type JsonMessageFormatter struct{}

func (JsonMessageFormatter) Format

func (j JsonMessageFormatter) Format()

type KafkaConfig

type KafkaConfig struct {
	ConfigSource
}

KafkaConfig Kafka配置类

func NewKafkaConfig

func NewKafkaConfig(configSource ConfigSource) *KafkaConfig

type KafkaMessageQueue

type KafkaMessageQueue struct{}

func (KafkaMessageQueue) Receive

func (k KafkaMessageQueue) Receive()

func (KafkaMessageQueue) Send

func (k KafkaMessageQueue) Send(formatter MessageFormatter)

type MessageFormatter

type MessageFormatter interface {
	Format()
}

type MessageQueue

type MessageQueue interface {
	Receive()
	Send(formatter MessageFormatter)
}

type MessageSender

type MessageSender struct{}

func NewMessageSender

func NewMessageSender() *MessageSender

func (MessageSender) Send

func (m MessageSender) Send(cellphone, message string)

type MsgSender

type MsgSender interface {
	Send(cellphone, message string)
}

type MySQLConfig

type MySQLConfig struct {
	ConfigSource
}

MySQLConfig MySQL 配置类

func NewMySQLConfig

func NewMySQLConfig(configSource ConfigSource) *MySQLConfig

func (*MySQLConfig) Output

func (m *MySQLConfig) Output() map[string]string

func (*MySQLConfig) OutputInPlainText

func (m *MySQLConfig) OutputInPlainText() string

type NetworkTransporter

type NetworkTransporter struct{}

func NewNetworkTransporter

func NewNetworkTransporter() *NetworkTransporter

func (*NetworkTransporter) SendV1

func (t *NetworkTransporter) SendV1(r *http.Request) []byte

func (*NetworkTransporter) SendV2

func (t *NetworkTransporter) SendV2(address string, data []byte) []byte

SendV2 address 和 content 交给 NetworkTransporter,而非是直接把 http.Request 交给 NetworkTransporter。

type Notification

type Notification struct{}

Notification 告警通知类,支持多种通知渠道:邮件,短信,微信,手机

func (*Notification) Notify

func (n *Notification) Notify(level NotificationEmergencyLevel, info string)

type NotificationDI

type NotificationDI struct {
	*MessageSender
}

func NewNotificationDI

func NewNotificationDI(messageSender *MessageSender) *NotificationDI

func (*NotificationDI) Notification

func (n *NotificationDI) Notification(cellphone, message string)

type NotificationDIV2

type NotificationDIV2 struct {
	MsgSender
}

func NewNotificationDIV2

func NewNotificationDIV2(msgSender MsgSender) *NotificationDIV2

func (*NotificationDIV2) Notification

func (n *NotificationDIV2) Notification(cellphone, message string)

type NotificationEmergencyLevel

type NotificationEmergencyLevel int
const (
	SEVERE  NotificationEmergencyLevel = iota // 严重
	URGENCY                                   // 紧急
	NORMAL                                    // 普通
	TRIVIAL                                   // 无关紧要
)

API 接口监控告警

type NotificationNoDI

type NotificationNoDI struct {
	*MessageSender
}

func NewNotificationNoDI

func NewNotificationNoDI() *NotificationNoDI

func (*NotificationNoDI) SendMessage

func (n *NotificationNoDI) SendMessage(cellphone, message string)

type NotificationV3

type NotificationV3 struct{}

func NewNotificationV3

func NewNotificationV3() *NotificationV3

func (NotificationV3) Notify

func (n NotificationV3) Notify(level NotificationEmergencyLevel, info string)

type ProtoBufMessageFormatter

type ProtoBufMessageFormatter struct{}

func (ProtoBufMessageFormatter) Format

func (p ProtoBufMessageFormatter) Format()

type RedisConfig

type RedisConfig struct {
	ConfigSource
	// contains filtered or unexported fields
}

RedisConfig 配置类

func NewRedisConfig

func NewRedisConfig(configSource ConfigSource) *RedisConfig

func (RedisConfig) Address

func (r RedisConfig) Address() string

func (*RedisConfig) Output

func (r *RedisConfig) Output() map[string]string

func (*RedisConfig) OutputInPlainText

func (r *RedisConfig) OutputInPlainText() string

type RestrictedUserService

type RestrictedUserService interface {
	DeleteUserByCellphone(cellphone string)
	DeleteUserById(id int64)
}

type RestrictedUserServiceImpl

type RestrictedUserServiceImpl struct{}

func (*RestrictedUserServiceImpl) DeleteUserByCellphone

func (r *RestrictedUserServiceImpl) DeleteUserByCellphone(cellphone string)

func (*RestrictedUserServiceImpl) DeleteUserById

func (r *RestrictedUserServiceImpl) DeleteUserById(id int64)

type RocketMQMessageQueue

type RocketMQMessageQueue struct{}

func (RocketMQMessageQueue) Receive

func (r RocketMQMessageQueue) Receive()

func (RocketMQMessageQueue) Send

func (r RocketMQMessageQueue) Send(formatter MessageFormatter)

type SMSSender

type SMSSender struct{}

SMSSender 短信发送类

func NewSMSSender

func NewSMSSender() *SMSSender

func (*SMSSender) Send

func (s *SMSSender) Send(cellphone, message string)

type ScheduledUpdater

type ScheduledUpdater struct {
	Updater
	// contains filtered or unexported fields
}

ScheduledUpdater 代码热更新类

func NewScheduledUpdater

func NewScheduledUpdater(initialDelayInSeconds time.Duration, periodInSeconds time.Duration, updater Updater) *ScheduledUpdater

type SecurityTransporter

type SecurityTransporter struct {
	*Transporter
	// contains filtered or unexported fields
}

func NewSecurityTransporter

func NewSecurityTransporter(appId string, appToken string, transporter *Transporter) *SecurityTransporter

func (*SecurityTransporter) SendRequest

func (s *SecurityTransporter) SendRequest(r *http.Request) error

SendRequest

- 修改前,如果 appId 或者 appToken 没有设置,不做校验 - 修改后,如果 appId 或者 appToken 没有设置,则直接抛出 NoAuthorizationRuntimeException 未授权异常

type Serialization

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

func NewSerialization

func NewSerialization() *Serialization

func (*Serialization) Deserialize

func (s *Serialization) Deserialize(text string) map[string]string

func (*Serialization) Serialize

func (s *Serialization) Serialize(object map[string]string) (string, error)

type Serializations

type Serializations struct {
}

func (*Serializations) Deserialize

func (s *Serializations) Deserialize(str string) interface{}

func (*Serializations) Serialize

func (s *Serializations) Serialize(obj interface{}) string

type Serializer

type Serializer struct{}

func (*Serializer) Serialize

func (s *Serializer) Serialize(obj interface{}) string

type Serializers

type Serializers interface {
	Serialize(obj interface{}) string
}

type Stage1UserInfo

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

type Stage2UserAddress

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

type Stage2UserInfo

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

type Stage3Account

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

type Stage3UserAddress

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

type Stage3UserInfo

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

type Statistics

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

func Count

func Count(dataSet []int64) *Statistics

type TimeoutAlertHandler

type TimeoutAlertHandler struct {
	*BaseHandler
}

func NewTimeoutAlertHandler

func NewTimeoutAlertHandler(rule *AlertRuleV3, notification *NotificationV3) *TimeoutAlertHandler

func (*TimeoutAlertHandler) Check

func (t *TimeoutAlertHandler) Check(info *ApiStatInfo)

type TpsAlertHandler

type TpsAlertHandler struct {
	*BaseHandler
}

func NewTpsAlertHandler

func NewTpsAlertHandler(rule *AlertRuleV3, notification *NotificationV3) *TpsAlertHandler

func (*TpsAlertHandler) Check

func (t *TpsAlertHandler) Check(info *ApiStatInfo)

type Transport

type Transport interface {
	SendRequest(r *http.Request) error
}

type Transporter

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

func NewTransporter

func NewTransporter(httpClient *http.Client) *Transporter

func (*Transporter) SendRequest

func (t *Transporter) SendRequest(r *http.Request) error

type Updater

type Updater interface {
	// contains filtered or unexported methods
}

type UserAuthenticator

type UserAuthenticator struct{}

func (*UserAuthenticator) Authenticate

func (u *UserAuthenticator) Authenticate(username, password string) error

type UserAuthenticatorV2

type UserAuthenticatorV2 struct{}

func (*UserAuthenticatorV2) Authenticate

func (u *UserAuthenticatorV2) Authenticate(username, password string) error

type UserInfo

type UserInfo struct {
	Id        int64
	Name      string
	Password  string
	Cellphone string
}

type UserService

type UserService interface {
	Register(cellphone, password string)
	Login(cellphone, password string)
	GetUserInfoById(id int64) UserInfo
	GetUserInfoByCellphone(cellphone string) UserInfo
}

type UserServiceImpl

type UserServiceImpl struct{}

func (*UserServiceImpl) GetUserInfoByCellphone

func (u *UserServiceImpl) GetUserInfoByCellphone(cellphone string) UserInfo

func (*UserServiceImpl) GetUserInfoById

func (u *UserServiceImpl) GetUserInfoById(id int64) UserInfo

func (*UserServiceImpl) Login

func (u *UserServiceImpl) Login(cellphone, password string)

func (*UserServiceImpl) Register

func (u *UserServiceImpl) Register(cellphone, password string)

type UserServiceTest

type UserServiceTest struct{}

func (UserServiceTest) DoTest

func (u UserServiceTest) DoTest() bool

type Viewer

type Viewer interface {
	OutputInPlainText() string
	Output() map[string]string
}

type ZookeeperConfigSource

type ZookeeperConfigSource struct{}

func NewZookeeperConfigSource

func NewZookeeperConfigSource() *ZookeeperConfigSource

Jump to

Keyboard shortcuts

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