GithubHelp home page GithubHelp logo

yankawayu / go-socket Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 0.0 402 KB

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

License: MIT License

Go 100.00%

go-socket's Introduction

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.

go-socket's People

Contributors

yankawayu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.