Hello everyone
I am currently learning go and am creating a server app, in which create a discord oauth2 client and a http mux server. When a new oauth2 flow is completed by a user, a event should be sent into a channel by the http server goroutine and received, by my main goroutine. I now have the problem, that i am not receiving an event after a completion of a oauth2 grant flow.
Event related functions
func NewEventEmitter() *EventEmitter {
return &EventEmitter{
events: make(chan Event),
shutdown: make(chan struct{}),
}
}
func (emitter *EventEmitter) Emit(event Event) {
go func(ch chan Event) {
ch <- event
}(emitter.events)
}
func (emitter *EventEmitter) Subscribe() <-chan Event {
go func() {
<-emitter.shutdown
close(emitter.events)
}()
return emitter.events
}
func (handler *OAuth2Handler) SubscribeNewUserEvents() <-chan Event {
return handler.emitter.Subscribe()
}
Emitting
event := Event{
UserData: user,
VerificationCode: verificationCode,
}
handler.emitter.Emit(event)
Recieving
newUserChannel := oauthHandler.SubscribeNewUserEvents()
go func() {
for event := range newUserChannel {
fmt.Printf("New user event received: %+v\n", event)
}
}()
Types
type Event struct {
UserData DiscordUser
VerificationCode string
}
type EventEmitter struct {
events chan Event
shutdown chan struct{}
}
type EventListener interface {
OnNewUser(event Event)
}
type OAuth2Handler struct {
config *oauth2.Config
emitter *EventEmitter
listener EventListener
httpServer *http.Server
}
This is obviously not everything regarding code, so if there is any function or method I missed please tell me.



