Documentation
¶
Overview ¶
MIT License
Copyright (c) 2017 jjeffcaii@outlook.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Package sio is a server-side Socket.IO in Golang.
Basic Example:
flag.Parse()
var server = sio.NewBuilder().Build()
var nsp = server.Of("/")
nsp.OnConnect(func(socket sio.Socket) {
socket.On("news", func(msg sio.Message) {
fmt.Println("[news]:", msg)
})
socket.Emit("hello", "你好,世界!")
})
http.HandleFunc(sio.DefaultPath, server.Router())
log.Fatalln(http.ListenAndServe(":3000", nil))
MIT License ¶
Copyright (c) 2017 jjeffcaii@outlook.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MIT License ¶
Copyright (c) 2017 jjeffcaii@outlook.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MIT License ¶
Copyright (c) 2017 jjeffcaii@outlook.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MIT License ¶
Copyright (c) 2017 jjeffcaii@outlook.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MIT License ¶
Copyright (c) 2017 jjeffcaii@outlook.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Index ¶
- Constants
- type Handshake
- type InRoom
- type Message
- type Namespace
- type Server
- type ServerBuilder
- func (p *ServerBuilder) Build() Server
- func (p *ServerBuilder) ForceCheckProtocol() *ServerBuilder
- func (p *ServerBuilder) SetAllowRequest(validator func(*http.Request) error) *ServerBuilder
- func (p *ServerBuilder) SetAllowUpgrades(enable bool) *ServerBuilder
- func (p *ServerBuilder) SetCookie(enable bool) *ServerBuilder
- func (p *ServerBuilder) SetCookieHTTPOnly(httpOnly bool) *ServerBuilder
- func (p *ServerBuilder) SetCookiePath(path string) *ServerBuilder
- func (p *ServerBuilder) SetGenerateID(gen func(uint32) string) *ServerBuilder
- func (p *ServerBuilder) SetLoggerError(logger *log.Logger) *ServerBuilder
- func (p *ServerBuilder) SetLoggerInfo(logger *log.Logger) *ServerBuilder
- func (p *ServerBuilder) SetLoggerWarn(logger *log.Logger) *ServerBuilder
- func (p *ServerBuilder) SetPath(path string) *ServerBuilder
- func (p *ServerBuilder) SetPingInterval(interval uint32) *ServerBuilder
- func (p *ServerBuilder) SetPingTimeout(timeout uint32) *ServerBuilder
- func (p *ServerBuilder) SetTransports(transports ...eio.TransportType) *ServerBuilder
- type Socket
- type Sockets
- type ToRoom
Constants ¶
const DefaultPath = "/socket.io/"
DefaultPath '/socket.io/' is the default http handler path.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handshake ¶
type Handshake struct {
Headers http.Header
Address string
XDomain bool
URL string
Query url.Values
}
Handshake is the object used when negociating the handshake.
type Namespace ¶
type Namespace interface {
// ID returns the pathname of namespace.
ID() string
// OnConnect register handler for socket created in namespace.
OnConnect(callback func(socket Socket))
// GetSockets returns all of sockets in current namespace.
GetSockets() Sockets
}
Namespace represents a pool of sockets connected under a given scope identified by a pathname (eg: /chat).
type Server ¶
type Server interface {
// Of initializes and retrieves the given Namespace by its pathname identifier nsp.
Of(nsp string) Namespace
// Router returns a http handler.
Router() func(http.ResponseWriter, *http.Request)
// GetSockets returns all sockets of server.
GetSockets() Sockets
}
Server is socket.io server. You can use ServerBuilder to create it simply.
type ServerBuilder ¶
type ServerBuilder struct {
// contains filtered or unexported fields
}
ServerBuilder can be used to build a new server.
func (*ServerBuilder) ForceCheckProtocol ¶
func (p *ServerBuilder) ForceCheckProtocol() *ServerBuilder
ForceCheckProtocol force protocol check for query param EIO.
func (*ServerBuilder) SetAllowRequest ¶
func (p *ServerBuilder) SetAllowRequest(validator func(*http.Request) error) *ServerBuilder
SetAllowRequest set a function that receives a given request, and can decide whether to continue or not.
func (*ServerBuilder) SetAllowUpgrades ¶
func (p *ServerBuilder) SetAllowUpgrades(enable bool) *ServerBuilder
SetAllowUpgrades define whether to allow transport upgrades. (default allow upgrades)
func (*ServerBuilder) SetCookie ¶
func (p *ServerBuilder) SetCookie(enable bool) *ServerBuilder
SetCookie can control enable/disable of cookie.
func (*ServerBuilder) SetCookieHTTPOnly ¶
func (p *ServerBuilder) SetCookieHTTPOnly(httpOnly bool) *ServerBuilder
SetCookieHTTPOnly if set true HttpOnly io cookie cannot be accessed by client-side APIs, such as JavaScript. (true) This option has no effect if cookie or cookiePath is set to false.
func (*ServerBuilder) SetCookiePath ¶
func (p *ServerBuilder) SetCookiePath(path string) *ServerBuilder
SetCookiePath define the path of cookie.
func (*ServerBuilder) SetGenerateID ¶
func (p *ServerBuilder) SetGenerateID(gen func(uint32) string) *ServerBuilder
SetGenerateID define the method of creating SocketID.
func (*ServerBuilder) SetLoggerError ¶
func (p *ServerBuilder) SetLoggerError(logger *log.Logger) *ServerBuilder
SetLoggerError set logger for ERROR
func (*ServerBuilder) SetLoggerInfo ¶
func (p *ServerBuilder) SetLoggerInfo(logger *log.Logger) *ServerBuilder
SetLoggerInfo set logger for INFO
func (*ServerBuilder) SetLoggerWarn ¶
func (p *ServerBuilder) SetLoggerWarn(logger *log.Logger) *ServerBuilder
SetLoggerWarn set logger for WARN
func (*ServerBuilder) SetPath ¶
func (p *ServerBuilder) SetPath(path string) *ServerBuilder
SetPath define the http router path for Engine.
func (*ServerBuilder) SetPingInterval ¶
func (p *ServerBuilder) SetPingInterval(interval uint32) *ServerBuilder
SetPingInterval define ping time interval in millseconds for client.
func (*ServerBuilder) SetPingTimeout ¶
func (p *ServerBuilder) SetPingTimeout(timeout uint32) *ServerBuilder
SetPingTimeout define ping timeout in millseconds for client.
func (*ServerBuilder) SetTransports ¶
func (p *ServerBuilder) SetTransports(transports ...eio.TransportType) *ServerBuilder
SetTransports define transport types allow.
type Socket ¶
type Socket interface {
// ID returns session ID of socket.
ID() string
// Namespace returns Namespace of current socket.
Namespace() Namespace
// Handshake returns Handshake of current socket.
Handshake() *Handshake
// Emit emits an event to the socket identified by the string name.
Emit(event string, first interface{}, others ...interface{}) error
// On register a handler of event identified by the string event.
On(event string, callback func(msg Message)) error
// OnError register a handler of error happend.
OnError(callback func(error)) error
// OnClose register a handler of socket closed.
OnClose(callback func(reason string)) error
// Close close current socket.
Close()
// To return ToRoom identified by the room string.
To(room string) ToRoom
// In return InRoom identified by the room string.
In(room string) InRoom
Join(room string) error
Leave(room string) error
LeaveAll() error
}
Socket is the fundamental class for interacting with browser clients. A Socket belongs to a certain Namespace (by default /) and uses an underlying Client to communicate.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
MIT License Copyright (c) 2017 jjeffcaii@outlook.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
MIT License Copyright (c) 2017 jjeffcaii@outlook.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |