Пример #1
0
func NewServer(setting *ServerSetting) *Server {
	if setting == nil {
		panic("wechat.NewServer: setting == nil")
	}

	const requestPoolSize = 1024 // 不暴露这个选项是为了变更到 sync.Pool 不做大的变动

	var srv Server
	srv.setting.initialize(setting)
	srv.messageRequestPool = pool.New(newMessageRequest, requestPoolSize)
	return &srv
}
Пример #2
0
// It will default to http.DefaultClient if httpClient == nil.
func NewClient(appid, appsecret string, httpClient *http.Client) *Client {
	const bufferPoolSize = 16 // 不暴露这个选项是为了变更到 sync.Pool 不做大的变动

	c := &Client{
		appid:                appid,
		appsecret:            appsecret,
		resetRefreshTickChan: make(chan time.Duration), // 同步 channel
		bufferPool:           pool.New(newBuffer, bufferPoolSize),
	}
	if httpClient == nil {
		c.httpClient = http.DefaultClient
	} else {
		c.httpClient = httpClient
	}
	go c.tokenService() // 定时更新 c.token
	c.TokenRefresh()    // *同步*获取 access token
	return c
}