websocket

package
v0.0.0-...-b8a7096 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package websocket MIT License

# Copyright (c) 2024 go-fox Author https://github.com/go-fox/fox

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 websocket MIT License

# Copyright (c) 2024 go-fox Author https://github.com/go-fox/fox

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 websocket MIT License

# Copyright (c) 2024 go-fox Author https://github.com/go-fox/fox

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 websocket MIT License

# Copyright (c) 2024 go-fox Author https://github.com/go-fox/fox

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 websocket MIT License

# Copyright (c) 2024 go-fox Author https://github.com/go-fox/fox

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 websocket MIT License

# Copyright (c) 2024 go-fox Author https://github.com/go-fox/fox

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 websocket MIT License

# Copyright (c) 2024 go-fox Author https://github.com/go-fox/fox

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 websocket MIT License

# Copyright (c) 2024 go-fox Author https://github.com/go-fox/fox

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 websocket MIT License

# Copyright (c) 2024 go-fox Author https://github.com/go-fox/fox

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 websocket MIT License

# Copyright (c) 2024 go-fox Author https://github.com/go-fox/fox

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

View Source
const KindWebsocket transport.Kind = "websocket" // KindWebsocket websocket kind

Variables

View Source
var (

	// Name is name for transport
	Name transport.Kind = "websocket"
)

Functions

func CodecForRequest

func CodecForRequest(r *protocol.Request, name string) codec.Codec

CodecForRequest get encoding.Codec via http.Request

func DefaultErrorEncoder

func DefaultErrorEncoder(ss *Session, r *protocol.Request, err error)

DefaultErrorEncoder default error encoder

func DefaultRequestDecoder

func DefaultRequestDecoder(r *protocol.Request, v any) error

DefaultRequestDecoder default request decoder

func DefaultRequestEncoder

func DefaultRequestEncoder(ctx context.Context, args any) ([]byte, error)

DefaultRequestEncoder default request encoder

func DefaultResponseDecoder

func DefaultResponseDecoder(ctx context.Context, data []byte, out any) error

DefaultResponseDecoder default response decoder

func DefaultResponseEncoder

func DefaultResponseEncoder(ss *Session, r *protocol.Request, reply *protocol.Reply, v any) error

DefaultResponseEncoder default response encoder

Types

type AuthorizationHandler

type AuthorizationHandler func(ss *Session) error

AuthorizationHandler is a session authorization handler

type CallOption

type CallOption interface {
	// contains filtered or unexported methods
}

CallOption call options

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client ws client

func NewClient

func NewClient(ctx context.Context, opts ...ClientOption) (*Client, error)

NewClient create a websocket client

func (*Client) Close

func (c *Client) Close() error

Close is websocket conn close func.

func (*Client) Invoke

func (c *Client) Invoke(ctx context.Context, operation string, args any, reply any, opts ...CallOption) error

Invoke makes a rpc call procedure for remote service.

type ClientOption

type ClientOption func(c *Client)

ClientOption client option

func WithCodec

func WithCodec(codec codec.Codec) ClientOption

WithCodec with client protocol codec

func WithEndpoint

func WithEndpoint(endpoint string) ClientOption

WithEndpoint with client endpoint

func WithRequestEncoder

func WithRequestEncoder(requestFunc EncoderRequestFunc) ClientOption

WithRequestEncoder with client request encoder.

func WithResponseDecoder

func WithResponseDecoder(decode DecodeResponseFunc) ClientOption

WithResponseDecoder with client response decoder.

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

WithTimeout with client timeout

type ConnectedInterceptor

type ConnectedInterceptor func(ss *Session) error

ConnectedInterceptor client connect interceptor

type Context

type Context interface {
	context.Context
	Result(data any) error
	Bind(any) error
}

Context ...context

type DecodeResponseFunc

type DecodeResponseFunc func(ctx context.Context, data []byte, out any) error

DecodeResponseFunc is response decode func.

type DecoderRequestFunc

type DecoderRequestFunc func(r *protocol.Request, v any) error

DecoderRequestFunc is decoder request func.

type DisconnectedInterceptor

type DisconnectedInterceptor func(ss *Session)

DisconnectedInterceptor client disconnect interceptor

type EncoderErrorFunc

type EncoderErrorFunc func(ss *Session, r *protocol.Request, err error)

EncoderErrorFunc is encode error func.

type EncoderRequestFunc

type EncoderRequestFunc func(ctx context.Context, args any) ([]byte, error)

EncoderRequestFunc is request encode func.

type EncoderResponseFunc

type EncoderResponseFunc func(ss *Session, r *protocol.Request, reply *protocol.Reply, v any) error

EncoderResponseFunc is encode response func.

type HandlerFunc

type HandlerFunc func(ctx Context) error

HandlerFunc handler func

type HandlersChain

type HandlersChain []HandlerFunc

HandlersChain handler chain

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is impl transport.Server

func NewServer

func NewServer(opts ...ServerOption) *Server

NewServer new a websocket server by options

func NewServerWithConfig

func NewServerWithConfig(cs ...*ServerConfig) *Server

NewServerWithConfig create websocket with server config

func (*Server) Endpoint

func (s *Server) Endpoint() (*url.URL, error)

Endpoint 获取地址

func (*Server) Handler

func (s *Server) Handler(operator string, handler HandlerFunc)

Handler 设置handler

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start is start this server

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop is stop this server

func (*Server) Use

func (s *Server) Use(selector string, m ...middleware.Middleware)

Use uses service middleware with selector.

type ServerConfig

type ServerConfig struct {
	Network         string        `json:"network"`
	Address         string        `json:"address"`
	SessionPoolSize int           `json:"session_pool_size"`
	HandlerPoolSize int           `json:"handler_pool_size"`
	CertFile        string        `json:"cert_file"`
	KeyFile         string        `json:"key_file"`
	Timeout         time.Duration `json:"timeout"`
	// contains filtered or unexported fields
}

ServerConfig websocket server config

func DefaultServerConfig

func DefaultServerConfig() *ServerConfig

DefaultServerConfig default server option

type ServerOption

type ServerOption func(s *ServerConfig)

ServerOption is websocket server options

func AddMiddleware

func AddMiddleware(selector string, mws ...middleware.Middleware) ServerOption

AddMiddleware add middlewares

func Address

func Address(address string) ServerOption

Address with an address option

func Authorization

func Authorization(handler AuthorizationHandler) ServerOption

Authorization with an authorization option.

func Codec

func Codec(codec codec.Codec) ServerOption

Codec with a codec option

func HandlerPoolSize

func HandlerPoolSize(size int) ServerOption

HandlerPoolSize with handler pool size

func Logger

func Logger(logger *slog.Logger) ServerOption

Logger with logger option

func Middleware

func Middleware(ms ...middleware.Middleware) ServerOption

Middleware with middlewares

func Network

func Network(network string) ServerOption

Network with a network option

func OnConnected

func OnConnected(onConnect ConnectedInterceptor) ServerOption

OnConnected with a connected callback option

func OnDisconnected

func OnDisconnected(disconnect DisconnectedInterceptor) ServerOption

OnDisconnected with a disconnect callback option

func SessionPoolSize

func SessionPoolSize(size int) ServerOption

SessionPoolSize with session pool size

func TLSConfig

func TLSConfig(config *tls.Config) ServerOption

TLSConfig with tls config

func Timeout

func Timeout(timeout time.Duration) ServerOption

Timeout with timeout option

func Upgrader

func Upgrader(upgrader websocket.FastHTTPUpgrader) ServerOption

Upgrader with websocket.FastHTTPUpgrader option

type Session

type Session struct {
	Id string `json:"id"`
	// contains filtered or unexported fields
}

Session websocket client session

func (*Session) Close

func (s *Session) Close() error

Close 关闭

func (*Session) ID

func (s *Session) ID() string

ID is client session unique id

func (*Session) Load

func (s *Session) Load(key string) string

Load 加载数据

func (*Session) Receive

func (s *Session) Receive(request *protocol.Request) error

Receive 接收

func (*Session) Send

func (s *Session) Send(reply *protocol.Reply) error

Send 发送

func (*Session) Store

func (s *Session) Store(key, value string)

Store 存储元数据

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport is a websocket transport.

func (*Transport) Endpoint

func (t *Transport) Endpoint() string

Endpoint returns the transport endpoint.

func (*Transport) Kind

func (t *Transport) Kind() transport.Kind

Kind returns the transport kind.

func (*Transport) Operation

func (t *Transport) Operation() string

Operation returns the transport operation.

func (*Transport) ReplyHeader

func (t *Transport) ReplyHeader() transport.Header

ReplyHeader returns the reply header.

func (*Transport) RequestHeader

func (t *Transport) RequestHeader() transport.Header

RequestHeader returns the request header.

type Transporter

type Transporter interface {
	transport.Transporter
}

Transporter is a websocket transport

type UnimplementedOption

type UnimplementedOption struct {
}

UnimplementedOption does not alter the Call configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL