GitXplorerGitXplorer
d

nexus

public
6 stars
4 forks
1 issues

Commits

List of commits on branch master.
Unverified
a25035b1db5c1a580c466a76c53e7d9c68fdbe3f

adding bind method

dds0nt committed 7 years ago
Unverified
82f1b460d03562c45af3d69b12c2b6c840adc81d

exposing connection

dds0nt committed 7 years ago
Unverified
0274258ddb7dbb61949060b4dd915934cecae15b

exposing websocket Upgrader

dds0nt committed 7 years ago
Unverified
fc1098da78e84a4070136caa01cccfb2a51d297c

changing fmt.printf debug line to be turned off by verbose false

dds0nt committed 7 years ago
Unverified
89cf8057294364eb1a5598caa7ed8c1894b7598f

adding ServeHTTP

dds0nt committed 8 years ago
Unverified
9b64be636cbdfb2017a8958034dc8c482f5c5b5a

bettering the readme

dds0nt committed 8 years ago

README

The README file for this repository.

Nexus

Codeship Build Status

Nexus is a small websocket server framework.

If in json format, it sends and receives messages as shown in the tags

type Packet struct {
	Type string `json:"type"`
	Data string `json:"data"`
}

Using the delimited format serializes and deserializes faster by simply appending things together.

It sends and receives messages in the format:

# Format
<type_length>:<type><data>

# Examples
5:tokenTOKEN_STRING_GGGGGGGGGGGGGGGG
4:ping
4:chat{"message":"hello"}

Nexus provides a simple interface for registering a handler for each message type:

func main() {

	n := nexus.NewNexus()

	n.Handle("token", handleToken)
	n.Handle("chat", handleChat)

	http.ListenAndServe(":9090", n.Handler)
}

func handleToken(c *nexus.Client, p *nexus.Packet) {		
	user, err := lookupUserByToken(p.Data)
	if err != nil {
		// send a response here
		return
	}

	// store the user in the client's Env for using later
	c.Env["user"] = user
}

func handleChat(c *nexus.Client, p *nexus.Packet) {
	if _, ok := c.Env["user"] !ok {
		// unauthorized
		return
	}

	n.All().Broadcast(p)
}

Cheers! I'll add more later as I think of ways to keep it simple with websockets