aboutsummaryrefslogtreecommitdiff
path: root/lib/websocket/frames.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-06-09 21:57:02 +0700
committerShulhan <ms@kilabit.info>2022-06-09 21:57:02 +0700
commit25a9b45517225b09039cfb7ef887e5db3bb8ebbc (patch)
treed6cc6d69f4ef9280521810a88fdbfdfc4194c1ce /lib/websocket/frames.go
parentca845ca347a171c93e71621ca5249914c6a322b4 (diff)
downloadpakakeh.go-25a9b45517225b09039cfb7ef887e5db3bb8ebbc.tar.xz
lib/websocket: refactoring code
Replace assignment from using ":=" to use variable declaration with type. Rationale: clarity and minimize duplicate temporary variables with the same type.
Diffstat (limited to 'lib/websocket/frames.go')
-rw-r--r--lib/websocket/frames.go24
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/websocket/frames.go b/lib/websocket/frames.go
index 1e91397a..b6143f45 100644
--- a/lib/websocket/frames.go
+++ b/lib/websocket/frames.go
@@ -24,20 +24,24 @@ type Frames struct {
//
// On success it will return one or more frames.
// On fail it will return zero frame.
-func Unpack(in []byte) (frames *Frames) {
- if len(in) == 0 {
+func Unpack(packet []byte) (frames *Frames) {
+ if len(packet) == 0 {
return
}
frames = &Frames{}
- packet := in
+
+ var (
+ f *Frame
+ )
+
for len(packet) > 0 {
- f := &Frame{}
+ f = &Frame{}
packet = f.unpack(packet)
frames.Append(f)
}
- return
+ return frames
}
// Append a frame as part of continuous frame.
@@ -54,7 +58,8 @@ func (frames *Frames) Append(f *Frame) {
func (frames *Frames) fin(last *Frame) (frame *Frame) {
frame = frames.v[0]
- for x := 1; x < len(frames.v); x++ {
+ var x int
+ for x = 1; x < len(frames.v); x++ {
if frames.v[x].opcode == OpcodeClose {
break
}
@@ -79,7 +84,9 @@ func (frames *Frames) isClosed() bool {
if len(frames.v) == 0 {
return false
}
- for x := 0; x < len(frames.v); x++ {
+
+ var x int
+ for ; x < len(frames.v); x++ {
if frames.v[x].opcode == OpcodeClose {
return true
}
@@ -110,7 +117,8 @@ func (frames *Frames) payload() (payload []byte) {
return
}
- for x := 0; x < len(frames.v); x++ {
+ var x int
+ for ; x < len(frames.v); x++ {
if frames.v[x].opcode == OpcodeClose {
break
}