Giter VIP home page Giter VIP logo

golem's Introduction

golem v0.4.4

A lightweight extendable Go WebSocket-framework with client library.

Status

The project can be considered dead. There has been no development in recent years. It is still available on github for research and archiving purposes.

License

Golem is available under the Apache License, Version 2.0

Installation

go get github.com/trevex/golem

Client

A client is also available and heavily used in the examples. More information on how the client is used can be found in the client repository.

Simple Example

Server:

type Hello struct {
	From string `json:"from"`
}
type Answer struct {
	Msg string `json:"msg"`
}
func hello(conn *golem.Connection, data *Hello) {
	conn.Emit("answer", &Answer{"Thanks, "+ data.From + "!"})
}
func main() {
	myrouter := golem.NewRouter()
	myrouter.On("hello", hello)
	http.HandleFunc("/ws", myrouter.Handler())
	http.ListenAndServe(":8080", nil)
}

Client:

var conn = new golem.Connection("ws://127.0.0.1:8080/ws", true);
conn.on("answer", function(data) {
    console.log("Answer: "+data.msg);
});
conn.on("open", function() {
    conn.emit("hello", { from: "Client" });
});

Output in client console would be Thanks, Client!.

Documentation

The documentation is provided via godoc.

Wiki & Tutorials

More informations and insights can be found on the wiki page along with a tutorial series to learn how to use golem:

More Examples

Several examples are available in the example repository. To use them simply checkout the repository and make sure you installed (go get) golem before. A more detailed guide on how to use them is located in their repository.

History

  • v0.1.0
    • Basic API layout and documentation
  • v0.2.0
    • Evented communication system and routing
    • Basic room implementation (lobbies renamed to rooms for clarity)
  • v0.3.0
    • Protocol extensions through Parsers
    • Room manager for collections of rooms
  • v0.4.0
    • Protocol interchangable
    • Several bugfixes
    • Client up-to-date
  • v0.4.2
    • Connection type can be extended
    • Close added to connection
  • v0.4.3
    • RoomManager emiting create- and remove-events (remove if room has insufficient users)
  • v0.4.4
    • RoomManager manages set of connection dependent options, see example_chat_options.go
    • Router provides OnConnect callback

Special thanks

  • Gary Burd (for the great WebSocket protocol implementation and insights through his examples)
  • Andrew Gallant (for help on golang-nuts mailing list)
  • Kortschak (for help on golang-nuts mailing list)

Contributors

TODO

  • Verbose and configurable logging
  • Testing

golem's People

Contributors

garyburd avatar jefferai avatar trevex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

golem's Issues

Ending a connection inside of a OnConnect callback

First off, a thanks is in order - thanks for the excellent Websocket framework and excellent documentation/examples!

  • I'm utilizing the framework's custom OnConnect function in my app.
  • During this stage, the user has successfully initiated a websocket connection, and now I'm going to do some stuff.
  • But what if something goes wrong? Instead of doing a log.Fatal on the whole server, it is obviously much better to just immediately terminate that specific websocket connection.

So, I tried to do something like this:

router.OnConnect(connOpen)

func connOpen(conn *ExtendedConnection, r *http.Request) {
    // Get the session (this may be an empty session)
    session, err := sessionStore.Get(r, sessionName)
    if err != nil {
        log.Error("Unable to get the session for HTTP request:", r)
        conn.Connection.Close() // This DOES NOT work
        return
    }

    // Get the username from the session
    username := session.Values["username"].(string)

    // Transfer the username from the session to a field in the ExtendedConnection for use later
    // conn.Username = username
}

However, this doesn't actually work - you can't close the connection from inside a OnConnect callback, because the connection hasn't actually started yet, as illustrated here in the source code: https://github.com/trevex/golem/blob/master/router.go#L137

How is this supposed to be done in the Golem framework?

Edit - I reworded the question and the example code so that it would be more clear.

Add ability to define your own Connection

As it stands, golem is not flexible enough to handle some of the uses cases I had in mind, more specifically the ability to define some opaque data on the Connection for a chat application where I first authorize the connection
I do not want to re-authorize or cache this extra data (caching would involve having a global map[*Connection]mydata that I would need to protect from concurrent modification by different goroutines, and re-auth on every single event is wasteful)
If I missed a detail that makes this possible, please forgive me.

SetConnectionExtension reflect panic

Hi, for example_connection_extension.go after refreshing page, I've got:

2014/07/29 09:43:11 http: panic serving 127.0.0.1:59175: reflect: Call with too many input arguments
goroutine 22 [running]:
net/http.func·011()
        /usr/local/go/src/pkg/net/http/server.go:1100 +0xb7
runtime.panic(0x61e1e0, 0xc208000ad0)
        /usr/local/go/src/pkg/runtime/panic.c:248 +0x18d
reflect.Value.call(0x6225e0, 0x763fb8, 0x0, 0x130, 0x6d7530, 0x4, 0xc208032500, 0x2, 0x2, 0x0, ...)
        /usr/local/go/src/pkg/reflect/value.go:475 +0x162c
reflect.Value.Call(0x6225e0, 0x763fb8, 0x0, 0x130, 0xc208032500, 0x2, 0x2, 0x0, 0x0, 0x0)
        /usr/local/go/src/pkg/reflect/value.go:411 +0xd7
github.com/trevex/golem.func·021(0xc208025080, 0xc2080284e0)
        /home/theaidem/work/golang/sandbox/websockets_ex/src/github.com/trevex/golem/router.go:301 +0x398
github.com/trevex/golem.func·012(0x7fb0574a6a08, 0xc2080503c0, 0xc2080284e0)
        /home/theaidem/work/golang/sandbox/websockets_ex/src/github.com/trevex/golem/router.go:138 +0x7cc
net/http.HandlerFunc.ServeHTTP(0xc208000380, 0x7fb0574a6a08, 0xc2080503c0, 0xc2080284e0)
        /usr/local/go/src/pkg/net/http/server.go:1235 +0x40
net/http.(*ServeMux).ServeHTTP(0xc208024690, 0x7fb0574a6a08, 0xc2080503c0, 0xc2080284e0)
        /usr/local/go/src/pkg/net/http/server.go:1511 +0x1a3
net/http.serverHandler.ServeHTTP(0xc208004300, 0x7fb0574a6a08, 0xc2080503c0, 0xc2080284e0)
        /usr/local/go/src/pkg/net/http/server.go:1673 +0x19f
net/http.(*conn).serve(0xc20804e300)
        /usr/local/go/src/pkg/net/http/server.go:1174 +0xa7e
created by net/http.(*Server).Serve
        /usr/local/go/src/pkg/net/http/server.go:1721 +0x313

I use golang-1.3
Any ideas, how to fix it?

OnClose callback not receiving extended connection

When settings extended connection its sensible to expect the same connection throughout the API like:

router.OnClose(func(conn *ExtendedConnection) {
})

but it doesn't work since the signature for OnClose expects *golem.Connection.

test on connection stress

I would like to ask what is the test figures for these outcomes

  1. connection with 1000 concurrent connections with open 65540 open files and unlimited processes
  2. operate over 10 hours
  3. see any race detections?

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.