Skip to content

Go-socket is an open-source, high-performance socket framework for building backend services in Golang.

License

Notifications You must be signed in to change notification settings

YanKawaYu/go-socket

Repository files navigation

go-socket Build Status Go Report Card Go Reference

Go-socket is an open-source, high-performance socket framework for building backend services in Golang.

The protocol of Go-socket is called GOSOC, which is similar to MQTT. Since MQTT is designed for the Internet of Things(loT), it's extremely efficient. For more information, please read GOSOC.

Together with go-socket-client, you will be able to build a server/client system communicating with each other using sockets.

The Go-socket is designed to work independently on each server as long as there are common databases to store data. Therefore, you can deploy it on as many servers as you want, so that it can hold on up to 1 million users at the same time. Just put a load balancer like nginx in front of those servers to balance all the requests from clients. The following diagram describe the deployment:

architecture

Getting started

Getting Go-socket

With Go module support, simply add the following import

import "github.com/YanKawaYu/go-socket"

to your code, and then go [build|run|test] will automatically fetch the necessary dependencies.

Otherwise, run the following Go command to install the go-socket package:

$ go get -u github.com/YanKawaYu/go-socket

If you hadn't created a module, make sure you run this command first

go mod init Example

Running Go-socket

After you import go-socket package, you can start with a simplest example like the following example.go:

package main

import (
	"github.com/yankawayu/go-socket"
)

func main() {
	appConfig := &gosocket.AppConfig{
		TcpAddr:   "0.0.0.0",
		TcpPort:   8080,
		TlsEnable: false,
	}
	fastLog := gosocket.GetFastLog("app.access", false)
	// listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
	gosocket.Run(appConfig, nil, gosocket.GetLog(false), fastLog)
}

Make sure you create a runtime directory for logging and then use the Go command to run the demo:

# create a directory for logging
$ mkdir -m 777 runtime
# run example.go and access the server with telnet
$ go run example.go
$ telnet 127.0.0.1 8080

Go versions

Since we use go.uber.org/zap as the log component, it only supports the two most recent minor versions of Go. Therefore, the requirement of the Go version for this framework is the same.

Learn more examples

Learn and practice more examples, please read the Go-socket Quick Start which includes API examples

Source code

There are several major classes in the framework. Their relationships can be explained through the following diagram.

go-socket

For more details, you should see the comments in the source code.

Contributing

For now, I'm the only one that maintaining Go-socket. Any pull requests, suggestions or issues are appreciated!

License

Go-socket is under the MIT license. See the LICENSE file for details.

The encoding and decoding part of this software is modified from this repository. Thanks to the author Zhangxuan,Xu.

What's next

The ultimate goal of this project is to support a high performance IM server developed by Go. I would like to release it in the future.

About

Go-socket is an open-source, high-performance socket framework for building backend services in Golang.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages