Minor fixes, package synopsis

This commit is contained in:
diamondburned (Forefront) 2020-01-14 20:56:50 -08:00
parent a951eb2b89
commit 9f643fee7a
7 changed files with 32 additions and 10 deletions

View File

@ -1,3 +1,5 @@
// Package api provides an interface to interact with the Discord REST API. It
// handles rate limiting, as well as authorizing and more.
package api
import (

4
discord/discord.go Normal file
View File

@ -0,0 +1,4 @@
// Package discord provides common structures that the whole repository uses. It
// does not (and should not) contain API-specific structures, or WS-specific
// structures.
package discord

View File

@ -1,3 +1,10 @@
// Package gateway handles the Discord gateway (or Websocket) connection, its
// events, and everything related to it. This includes logging into the
// Websocket.
//
// This package does not abstract events and function handlers; instead, it
// leaves that to the session package. This package exposes only a single Events
// channel.
package gateway
import (
@ -62,10 +69,11 @@ type Gateway struct {
// Retries on connect and reconnect.
WSRetries uint // 3
Events chan Event
SessionID string
// All events sent over are pointers to Event structs (structs suffixed with
// "Event")
Events chan Event
URL string // URL
SessionID string
Identity *IdentifyData
Pacemaker *Pacemaker
@ -76,7 +84,7 @@ type Gateway struct {
// Only use for debugging
// If this channel is non-nil, all incoming OP packets will also be sent
// here.
// here. This should be buffered, so to not block the main loop.
OP chan Event
// Filled by methods, internal use
@ -98,10 +106,9 @@ func NewGatewayWithDriver(token string, driver json.Driver) (*Gateway, error) {
}
g := &Gateway{
URL: URL,
Driver: driver,
WSTimeout: WSTimeout,
Events: make(chan Event),
Events: make(chan Event, WSBuffer),
Identity: &IdentifyData{
Token: token,
Properties: Identity,
@ -191,6 +198,8 @@ func (g *Gateway) Start() error {
if err := AssertEvent(g, <-ch, DispatchOP, &ready); err != nil {
return errors.Wrap(err, "Error at Ready")
}
g.Events <- &ready
} else {
if err := g.Resume(); err != nil {
return errors.Wrap(err, "Failed to resume")
@ -201,6 +210,7 @@ func (g *Gateway) Start() error {
if err := AssertEvent(g, <-ch, DispatchOP, &resumed); err != nil {
return errors.Wrap(err, "Error at Resumed")
}
g.Events <- &resumed
}
// Start the event handler

View File

@ -3,12 +3,12 @@ package gateway
import "sync/atomic"
type Sequence struct {
seq *int64
seq int64
}
func NewSequence() Sequence {
return Sequence{new(int64)}
return Sequence{0}
}
func (s *Sequence) Set(seq int64) { atomic.StoreInt64(s.seq, seq) }
func (s *Sequence) Get() int64 { return atomic.LoadInt64(s.seq) }
func (s *Sequence) Set(seq int64) { atomic.StoreInt64(&s.seq, seq) }
func (s *Sequence) Get() int64 { return atomic.LoadInt64(&s.seq) }

View File

@ -1,3 +1,5 @@
// Package httputil provides abstractions around the common needs of HTTP. It
// also allows swapping in and out the HTTP client.
package httputil
import (

View File

@ -1,3 +1,5 @@
// Package json allows for different implementations of JSON serializing, as
// well as extra optional types needed.
package json
import (

View File

@ -1,3 +1,5 @@
// Package wsutil provides abstractions around the Websocket, including rate
// limits.
package wsutil
import (