-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathendpoint.go
More file actions
35 lines (28 loc) · 717 Bytes
/
endpoint.go
File metadata and controls
35 lines (28 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package socketio
import (
"strings"
)
// Endpoint is a socket.io endpoint.
type Endpoint struct {
Path string
Query string
}
// NewEndpoint returns a new Endpoint with the given path and query.
func NewEndpoint(path, query string) *Endpoint {
return &Endpoint{path, query}
}
// ParseEndpoint parses the given rawn endpoint into an Endpoint.
func ParseEndpoint(rawEndpoint string) *Endpoint {
parts := strings.SplitN(rawEndpoint, "?", 2)
if len(parts) == 1 {
return &Endpoint{parts[0], ""}
}
return &Endpoint{parts[0], parts[1]}
}
// String returns the string representation of the endpoint.
func (e Endpoint) String() string {
if e.Query != "" {
return e.Path + "?" + e.Query
}
return e.Path
}