newChatServer constructs a chatServer with the defaults.
()
| 42 | |
| 43 | // newChatServer constructs a chatServer with the defaults. |
| 44 | func newChatServer() *chatServer { |
| 45 | cs := &chatServer{ |
| 46 | subscriberMessageBuffer: 16, |
| 47 | logf: log.Printf, |
| 48 | subscribers: make(map[*subscriber]struct{}), |
| 49 | publishLimiter: rate.NewLimiter(rate.Every(time.Millisecond*100), 8), |
| 50 | } |
| 51 | cs.serveMux.Handle("/", http.FileServer(http.Dir("."))) |
| 52 | cs.serveMux.HandleFunc("/subscribe", cs.subscribeHandler) |
| 53 | cs.serveMux.HandleFunc("/publish", cs.publishHandler) |
| 54 | |
| 55 | return cs |
| 56 | } |
| 57 | |
| 58 | // subscriber represents a subscriber. |
| 59 | // Messages are sent on the msgs channel and if the client |