Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support For Resume Gateway URL #19

Merged
merged 4 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion gateway/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Shard struct {
limiter Limiter
packets *sync.Pool
lastHeartbeat time.Time
resumeURL string

connMu sync.Mutex
acks chan struct{}
Expand All @@ -47,6 +48,7 @@ func NewShard(opts *ShardOptions) *Shard {
},
id: strconv.Itoa(opts.Identify.Shard[0]),
acks: make(chan struct{}),
resumeURL: "",
}
}

Expand Down Expand Up @@ -265,6 +267,8 @@ func (s *Shard) handleDispatch(ctx context.Context, p *types.ReceivePacket) (err
return
}

s.resumeURL = r.ResumeGatewayURL

if err = s.opts.Store.SetSession(ctx, s.idUint(), r.SessionID); err != nil {
return
}
Expand Down Expand Up @@ -422,7 +426,11 @@ func (s *Shard) gatewayURL() string {
"compress": {"zstd-stream"},
}

return s.Gateway.URL + "/?" + query.Encode()
if s.resumeURL != "" {
return s.resumeURL + "/?" + query.Encode()
} else {
return s.Gateway.URL + "/?" + query.Encode()
}
}

func (s *Shard) idUint() uint {
Expand Down
38 changes: 20 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
module github.com/spec-tacles/gateway

go 1.17
go 1.21

toolchain go1.22.0

require (
github.com/BurntSushi/toml v1.2.0
github.com/gorilla/websocket v1.5.0
github.com/mediocregopher/radix/v4 v4.1.0
github.com/prometheus/client_golang v1.12.2
github.com/spec-tacles/go v0.0.0-20221010184919-5593c81f20a1
github.com/valyala/gozstd v1.17.0
github.com/BurntSushi/toml v1.3.2
github.com/gorilla/websocket v1.5.1
github.com/mediocregopher/radix/v4 v4.1.4
github.com/prometheus/client_golang v1.19.1
github.com/spec-tacles/go v0.0.0-20240519052238-4bb677db055a
github.com/valyala/gozstd v1.21.1
)

require golang.org/x/net v0.25.0 // indirect

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bwmarrin/snowflake v0.3.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/rabbitmq/amqp091-go v1.4.0
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/procfs v0.15.0 // indirect
github.com/rabbitmq/amqp091-go v1.10.0
github.com/tilinna/clock v1.1.0 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
google.golang.org/protobuf v1.28.0 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/sys v0.20.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
)
Loading
Loading