bootstrap

package
v0.0.0-...-42cc2d4 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: Apache-2.0, Apache-2.0 Imports: 52 Imported by: 0

Documentation

Overview

Package config 负责配置信息

Index

Constants

View Source
const (
	OnlineServiceHostPort = ":50051"
	HttpTimeoutHandler    = 10 * time.Second //TimeoutHandler默认的http超时时间,http响应时间超过后直接返回client端503(不同项目可根据接口最大超时时间调整)
	EnvLocal              = "local"
	EnvTest               = "test"
	EnvBVT                = "bvt"
	EnvProduct            = "product"
	EnvBenchmark          = "benchmark"
)

Variables

View Source
var (
	CoreCtx coreCtx

	DevEnv      string
	TestConfig  string
	ProjectName string
)
View Source
var (
	ErrClosed            = errors.New("pool had closed")
	ErrLimit             = errors.New("pool is reached max")
	MaxConcurrentStreams = 100
	MaxGetConnTimes      = 200
)
View Source
var CosClientList = make(map[string]CosClient)
View Source
var EmailConfig = &emailConfig{}
View Source
var StsClientList = make(map[string]StsClient)
View Source
var TencentSmsClient = &TencentSms{}

Functions

func CheckError

func CheckError(err error, errType string) error

func ControlCors

func ControlCors() gin.HandlerFunc

ControlCors 设置CORS

func GetProjectName

func GetProjectName() string

func Init

func Init()

func InitCos

func InitCos()

func InitEmail

func InitEmail()

func InitGrpc

func InitGrpc()

InitGrpc 初始化连接池

func InitLogger

func InitLogger()

func InitMysql

func InitMysql()

func InitRedis

func InitRedis()

func InitSms

func InitSms()

func InitSts

func InitSts()

func InitWeb

func InitWeb(funs []gin.HandlerFunc) *gin.Engine

func LogRecovery

func LogRecovery() gin.HandlerFunc

func NewGrpcServer

func NewGrpcServer() *grpc.Server

func NewPool

func NewPool(endpoints map[string]GrpcEndpoint) map[string]Pool

func ProjectPath

func ProjectPath() (path string)

func PutGrpcConn

func PutGrpcConn(name string, conn *IdleConn)

func RPCConnectMonitor

func RPCConnectMonitor() grpc.UnaryClientInterceptor

RPCConnectMonitor gRPC.Server 重启, gRPC.Pool连接的时健康检测

func RegisterGRPCServiceConsul

func RegisterGRPCServiceConsul(address string, port int, tags []string) error

RegisterGRPCServiceConsul 注册服务到consul

func RunServer

func RunServer(s *grpc.Server, addr string)

func RunWeb

func RunWeb(r *gin.Engine, addr string)

func SetLogger

func SetLogger() gin.HandlerFunc

SetLogger 接收gin框架默认的日志

func SetProjectName

func SetProjectName(name string)

func TimeoutUnaryClientInterceptor

func TimeoutUnaryClientInterceptor(timeout time.Duration) grpc.UnaryClientInterceptor

TimeoutUnaryClientInterceptor returns a new unary client interceptor that sets a timeout on the request context.

func Usage

func Usage()

Types

type ChannelPool

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

func (*ChannelPool) Close

func (c *ChannelPool) Close(conn *grpc.ClientConn) error

Close 关闭链接

func (*ChannelPool) Get

func (c *ChannelPool) Get() (*IdleConn, error)

Get 从连接池获取连接

func (*ChannelPool) Len

func (c *ChannelPool) Len() int

Len 连接池中已有的连接

func (*ChannelPool) Put

func (c *ChannelPool) Put(ic *IdleConn) error

Put 连接放回连接池

func (*ChannelPool) Release

func (c *ChannelPool) Release()

Release 释放所有的链接

func (*ChannelPool) RetrieveConcurrentStream

func (c *ChannelPool) RetrieveConcurrentStream(ic *IdleConn)

RetrieveConcurrentStream 回收steam

func (*ChannelPool) RetrieveStream

func (c *ChannelPool) RetrieveStream(ic *IdleConn)

RetrieveStream 回收steam

type Config

type Config struct {
}

type CosClient

type CosClient struct {
	AppId           string
	Client          *http.Client
	Region          string
	BucketName      string
	DurationSeconds int
	Bucket          string
	Domain          string
}

type GrpcEndpoint

type GrpcEndpoint struct {
	Endpoint    string
	InitialCap  int
	MaxCap      int
	IdleTimeout int
}

type IdleConn

type IdleConn struct {
	Conn *grpc.ClientConn
	// contains filtered or unexported fields
}

func GetGrpcConn

func GetGrpcConn(ctx context.Context, name string) (*IdleConn, context.Context)

type MysqlInstance

type MysqlInstance struct {
	DSN string
	DB  *gorm.DB
}

func GetMysqlInstance

func GetMysqlInstance(dbName string) (MysqlInstance, error)

type Pool

type Pool interface {
	Get() (*IdleConn, error)

	Put(*IdleConn) error

	RetrieveConcurrentStream(*IdleConn)

	RetrieveStream(*IdleConn)

	Close(*grpc.ClientConn) error

	Release()

	Len() int
}

Pool 定义pool接口

func NewChannelPool

func NewChannelPool(poolConfig *PoolConfig) (Pool, error)

NewChannelPool 初始化连接池

type PoolConfig

type PoolConfig struct {
	InitialCap  int
	MaxCap      int
	Factory     func(string, time.Duration) (*grpc.ClientConn, error)
	Close       func(*grpc.ClientConn) error
	IdleTimeout time.Duration
	Endpoint    string
	Timeout     time.Duration
}

type RedisClient

type RedisClient struct {
	Client *redis.Client
}

type StsClient

type StsClient struct {
	AppId           string
	Client          *sts.Client
	Region          string
	BucketName      string
	DurationSeconds int
	Bucket          string
	Domain          string
}

type TencentSms

type TencentSms struct {
	Client     *sms.Client
	Request    *sms.SendSmsRequest
	MobileCode string
}

Jump to

Keyboard shortcuts

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