nano

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: MIT Imports: 24 Imported by: 0

README

nano

Getting started

To make it easy for you to get started with GitLab, here's a list of recommended next steps.

Already a pro? Just edit this README.md and make it your own. Want to make it easy? Use the template at the bottom!

Add your files

cd existing_repo
git remote add origin http://43.198.203.51/baili/nano.git
git branch -M main
git push -uf origin main

Integrate with your tools

Collaborate with your team

Test and Deploy

Use the built-in continuous integration in GitLab.


Editing this README

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to makeareadme.com for this template.

Suggestions for a good README

Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.

Name

Choose a self-explaining name for your project.

Description

Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.

Badges

On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.

Visuals

Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.

Installation

Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.

Usage

Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.

Support

Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.

Roadmap

If you have ideas for releases in the future, it is a good idea to list them in the README.

Contributing

State if you are open to contributions and what your requirements are for accepting them.

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.

Authors and acknowledgment

Show your appreciation to those who have contributed to the project.

License

For open source projects, say how it is licensed.

Project status

If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCloseClosedGroup   = errors.New("close closed group")
	ErrClosedGroup        = errors.New("group closed")
	ErrMemberNotFound     = errors.New("member not found in the group")
	ErrSessionDuplication = errors.New("session has existed in the current group")
)

Errors that could be occurred during message handling.

View Source
var VERSION = "0.5.0"

VERSION returns current nano version

Functions

func Listen

func Listen(addr string, opts ...Option)

Listen listens on the TCP network address addr and then calls Serve with handler to handle requests on incoming connections.

func Shutdown

func Shutdown()

Shutdown send a signal to let 'nano' shutdown itself.

Types

type Group

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

Group represents a session group which used to manage a number of sessions, data send to the group will send to all session in it.

func NewGroup

func NewGroup(n string) *Group

NewGroup returns a new group instance

func (*Group) Add

func (c *Group) Add(session *session.Session) error

Add add session to group

func (*Group) Broadcast

func (c *Group) Broadcast(route string, v interface{}) error

Broadcast push the message(s) to all members

func (*Group) Close

func (c *Group) Close() error

Close destroy group, which will release all resource in the group

func (*Group) Contains

func (c *Group) Contains(uid int64) bool

Contains check whether a UID is contained in current group or not

func (*Group) Count

func (c *Group) Count() int

Count get current member amount in the group

func (*Group) ForEachAcceptor added in v0.1.3

func (c *Group) ForEachAcceptor(sds *[]pkg.SessionData) error

func (*Group) Leave

func (c *Group) Leave(s *session.Session) error

Leave remove specified UID related session from group

func (*Group) LeaveAll

func (c *Group) LeaveAll() error

LeaveAll clear all sessions in the group

func (*Group) Member

func (c *Group) Member(uid int64) (*session.Session, error)

Member returns specified UID's session

func (*Group) Members

func (c *Group) Members() []int64

Members returns all member's UID in current group

func (*Group) Multicast

func (c *Group) Multicast(route string, v interface{}, filter SessionFilter) error

Multicast push the message to the filtered clients

type Groups added in v0.1.3

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

func NewGroups added in v0.1.3

func NewGroups() *Groups

func (*Groups) Add added in v0.1.3

func (cs *Groups) Add(roomNo uint32, group *Group) error

Add add group to groups

func (*Groups) Contains added in v0.1.3

func (cs *Groups) Contains(roomNo uint32) bool

Contains check whether a roomNo is contained in current group or not

func (*Groups) Count added in v0.1.3

func (c *Groups) Count() int

Count get current member amount in the groups

func (*Groups) Leave added in v0.1.3

func (c *Groups) Leave(roomNo uint32) error

Leave remove specified DeskNo related group from groups

func (*Groups) LeaveAll added in v0.1.3

func (c *Groups) LeaveAll() error

LeaveAll clear all group in the groups

func (*Groups) Member added in v0.1.3

func (cs *Groups) Member(roomNo uint32) (*Group, error)

Member returns specified roomNo's Group

func (*Groups) Members added in v0.1.3

func (c *Groups) Members() []uint32

Members returns all member's roomNo in current group

type Option

type Option func(*cluster.Options)

func WithAdvertiseAddr

func WithAdvertiseAddr(addr string, retryInterval ...time.Duration) Option

WithAdvertiseAddr sets the advertise address option, it will be the listen address in master node and an advertise address which cluster member to connect

func WithCheckOriginFunc

func WithCheckOriginFunc(fn func(*http.Request) bool) Option

WithCheckOriginFunc sets the function that check `Origin` in http headers

func WithClientAddr

func WithClientAddr(addr string) Option

WithMemberAddr sets the listen address which is used to establish connection between cluster members. Will select an available port automatically if no member address setting and panic if no available port

func WithComponents

func WithComponents(components *component.Components) Option

WithComponents sets the Components

func WithCustomerRemoteServiceRoute

func WithCustomerRemoteServiceRoute(route cluster.CustomerRemoteServiceRoute) Option

WithCustomerRemoteServiceRoute register remote service route

func WithDebugMode

func WithDebugMode() Option

WithDebugMode let 'nano' to run under Debug mode.

func WithDictionary

func WithDictionary(dict map[string]uint16) Option

SetDictionary sets routes map

func WithGrpcOptions

func WithGrpcOptions(opts ...grpc.DialOption) Option

WithGrpcOptions sets the grpc dial options

func WithHandshakeValidator

func WithHandshakeValidator(fn func([]byte) error) Option

WithHandshakeValidator sets the function that Verify `handshake` data

func WithHeartbeatInterval

func WithHeartbeatInterval(d time.Duration) Option

WithHeartbeatInterval sets Heartbeat time interval

func WithIsWebsocket

func WithIsWebsocket(enableWs bool) Option

WithIsWebsocket indicates whether current node WebSocket is enabled

func WithLabel

func WithLabel(label string) Option

WithLabel sets the current node label in cluster

func WithLogger

func WithLogger(l log.Logger) Option

WithLogger overrides the default logger

func WithMaster

func WithMaster() Option

WithMaster sets the option to indicate whether the current node is master node

func WithNodeId

func WithNodeId(nodeId uint64) Option

WithNodeId set nodeId use snowflake nodeId generate sessionId, default: pid

func WithPipeline

func WithPipeline(pipeline pipeline.Pipeline) Option

func WithSerializer

func WithSerializer(serializer serialize.Serializer) Option

WithSerializer customizes application serializer, which automatically Marshal and UnMarshal handler payload

func WithTSLConfig

func WithTSLConfig(certificate, key string) Option

WithTSLConfig sets the `key` and `certificate` of TSL

func WithTimerPrecision

func WithTimerPrecision(precision time.Duration) Option

SetTimerPrecision sets the ticker precision, and time precision can not less than a Millisecond, and can not change after application running. The default precision is time.Second

func WithUnregisterCallback

func WithUnregisterCallback(fn func(member cluster.Member)) Option

WithUnregisterCallback master unregister member event call fn

func WithWSPath

func WithWSPath(path string) Option

type SessionFilter

type SessionFilter func(*session.Session) bool

SessionFilter represents a filter which was used to filter session when Multicast, the session will receive the message while filter returns true.

Directories

Path Synopsis
benchmark
io
examples
internal
env
env represents the environment of the current process, includes work path and config path etc.
env represents the environment of the current process, includes work path and config path etc.
log
pkg

Jump to

Keyboard shortcuts

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