mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-09-27 20:58:50 +00:00
Minor fixes, package synopsis
This commit is contained in:
parent
a951eb2b89
commit
9f643fee7a
|
@ -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
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
4
discord/discord.go
Normal file
4
discord/discord.go
Normal 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
|
|
@ -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
|
package gateway
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -62,10 +69,11 @@ type Gateway struct {
|
||||||
// Retries on connect and reconnect.
|
// Retries on connect and reconnect.
|
||||||
WSRetries uint // 3
|
WSRetries uint // 3
|
||||||
|
|
||||||
Events chan Event
|
// All events sent over are pointers to Event structs (structs suffixed with
|
||||||
SessionID string
|
// "Event")
|
||||||
|
Events chan Event
|
||||||
|
|
||||||
URL string // URL
|
SessionID string
|
||||||
|
|
||||||
Identity *IdentifyData
|
Identity *IdentifyData
|
||||||
Pacemaker *Pacemaker
|
Pacemaker *Pacemaker
|
||||||
|
@ -76,7 +84,7 @@ type Gateway struct {
|
||||||
// Only use for debugging
|
// Only use for debugging
|
||||||
|
|
||||||
// If this channel is non-nil, all incoming OP packets will also be sent
|
// 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
|
OP chan Event
|
||||||
|
|
||||||
// Filled by methods, internal use
|
// Filled by methods, internal use
|
||||||
|
@ -98,10 +106,9 @@ func NewGatewayWithDriver(token string, driver json.Driver) (*Gateway, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
g := &Gateway{
|
g := &Gateway{
|
||||||
URL: URL,
|
|
||||||
Driver: driver,
|
Driver: driver,
|
||||||
WSTimeout: WSTimeout,
|
WSTimeout: WSTimeout,
|
||||||
Events: make(chan Event),
|
Events: make(chan Event, WSBuffer),
|
||||||
Identity: &IdentifyData{
|
Identity: &IdentifyData{
|
||||||
Token: token,
|
Token: token,
|
||||||
Properties: Identity,
|
Properties: Identity,
|
||||||
|
@ -191,6 +198,8 @@ func (g *Gateway) Start() error {
|
||||||
if err := AssertEvent(g, <-ch, DispatchOP, &ready); err != nil {
|
if err := AssertEvent(g, <-ch, DispatchOP, &ready); err != nil {
|
||||||
return errors.Wrap(err, "Error at Ready")
|
return errors.Wrap(err, "Error at Ready")
|
||||||
}
|
}
|
||||||
|
g.Events <- &ready
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if err := g.Resume(); err != nil {
|
if err := g.Resume(); err != nil {
|
||||||
return errors.Wrap(err, "Failed to resume")
|
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 {
|
if err := AssertEvent(g, <-ch, DispatchOP, &resumed); err != nil {
|
||||||
return errors.Wrap(err, "Error at Resumed")
|
return errors.Wrap(err, "Error at Resumed")
|
||||||
}
|
}
|
||||||
|
g.Events <- &resumed
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the event handler
|
// Start the event handler
|
||||||
|
|
|
@ -3,12 +3,12 @@ package gateway
|
||||||
import "sync/atomic"
|
import "sync/atomic"
|
||||||
|
|
||||||
type Sequence struct {
|
type Sequence struct {
|
||||||
seq *int64
|
seq int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSequence() Sequence {
|
func NewSequence() Sequence {
|
||||||
return Sequence{new(int64)}
|
return Sequence{0}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sequence) Set(seq int64) { atomic.StoreInt64(s.seq, seq) }
|
func (s *Sequence) Set(seq int64) { atomic.StoreInt64(&s.seq, seq) }
|
||||||
func (s *Sequence) Get() int64 { return atomic.LoadInt64(s.seq) }
|
func (s *Sequence) Get() int64 { return atomic.LoadInt64(&s.seq) }
|
||||||
|
|
|
@ -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
|
package httputil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// Package json allows for different implementations of JSON serializing, as
|
||||||
|
// well as extra optional types needed.
|
||||||
package json
|
package json
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// Package wsutil provides abstractions around the Websocket, including rate
|
||||||
|
// limits.
|
||||||
package wsutil
|
package wsutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
Loading…
Reference in a new issue