func NewApnsHttpServer(option Option) *ApnsHttpServer { feedbackChan := make(chan *entry.Feedback, 1000) var apnsClient *apns.ApnsClient if option.startMode == STARTMODE_MOCK { //初始化mock apns apnsClient = apns.NewMockApnsClient(option.cert, option.pushAddr, chan<- *entry.Feedback(feedbackChan), option.feedbackAddr, entry.NewCycleLink(3, option.storageCapacity)) log.Info("MOCK APNS HTTPSERVER IS STARTING ....") } else { //初始化apns apnsClient = apns.NewDefaultApnsClient(option.cert, option.pushAddr, chan<- *entry.Feedback(feedbackChan), option.feedbackAddr, entry.NewCycleLink(3, option.storageCapacity)) log.InfoLog("push_handler", "ONLINE APNS HTTPSERVER IS STARTING ....") } server := &ApnsHttpServer{feedbackChan: feedbackChan, apnsClient: apnsClient, expiredTime: option.expiredTime} //创建http server.httpserver = NewMomoHttpServer(option.bindAddr, nil) go server.dial(option.bindAddr) return server }
func main() { feedbackChan := make(chan *entry.Feedback, 1000) cert, _ := tls.LoadX509KeyPair(CERT_PATH, KEY_PATH) client := apns.NewMockApnsClient(cert, PUSH_APPLE, feedbackChan, FEED_BACK_APPLE, entry.NewCycleLink(3, 100000)) payload := entry.NewSimplePayLoad("ms.caf", int(1), "hello") for i := 0; i < 100; i++ { go func(a int) { for j := 0; j < 1000000; j++ { client.SendEnhancedNotification(1, 1, apnsToken, *payload) } fmt.Printf("finish:%d\n", a) }(i) } select {} }