Skip to content
A modern, fast and scalable websocket framework with elegant API written in Go
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Update issue templates Jun 29, 2019
_examples Add nats support for the Server.Ask method - redis will support this … Jul 13, 2019
gobwas add a protobuf example to showcase that msg.Body can be any data May 31, 2019
gorilla add a protobuf example to showcase that msg.Body can be any data May 31, 2019
stackexchange export nats subject prefix Jul 14, 2019
.fossa.yml add .fossa.yml and the generated report on NOTICE file Jun 2, 2019
.gitattributes Init Feb 20, 2019
.gitignore add custom events with channels example Feb 22, 2019
.travis.yml rename project to 'kataras/neffos' and move client side to 'kataras/n… May 23, 2019
AUTHORS project renamed from kataras/ws to kataras/neffos May 26, 2019
CODE_OF_CONDUCT.md Init Feb 20, 2019
CONTRIBUTING.md add CONTRIBUTING document Jun 29, 2019
LICENSE change license to MIT and start writing the godocs Feb 22, 2019
NOTICE update deps Jul 13, 2019
README.md minor: add 'On' to Namespaces and Events and doc example for custom C… Jul 15, 2019
broadcaster.go rename project to 'kataras/neffos' and move client side to 'kataras/n… May 23, 2019
client.go Export the ability of custom ConnHandlers and a lot of improvements t… Jul 9, 2019
client_test.go add the ability to broadcast to a single connection by its ID as requ… Jun 2, 2019
conn.go make Ask to work inside handlers themselves without the need of a new… Jul 17, 2019
conn_handler.go add the ability to join and leave rooms through events like namespace… Jul 16, 2019
conn_handler_example_test.go minor: add 'On' to Namespaces and Events and doc example for custom C… Jul 15, 2019
conn_handler_struct_test.go Export the ability of custom ConnHandlers and a lot of improvements t… Jul 9, 2019
conn_namespace.go make Ask to work inside handlers themselves without the need of a new… Jul 17, 2019
conn_namespace_test.go make Ask to work inside handlers themselves without the need of a new… Jul 17, 2019
conn_room.go make the `Server#Broadcast` to accept a stringer, it just needs the c… May 28, 2019
conn_test.go New feature: Scale-out using Redis built-in StackExchange implementation Jul 11, 2019
debug.go see prev commit for the great news - prep for v0.0.6 Jul 11, 2019
doc.go See releases for v0.0.4 Jul 7, 2019
event.go godocs for event.go and some README contents May 25, 2019
gh_logo.png . May 26, 2019
go.mod update deps Jul 13, 2019
go.sum Updated nats/go.mod - ref to: nats-io/nats.go@3e0b176 Jul 15, 2019
message.go minor: add 'On' to Namespaces and Events and doc example for custom C… Jul 15, 2019
message_test.go Add nats support for the Server.Ask method - redis will support this … Jul 13, 2019
process.go rename project to 'kataras/neffos' and move client side to 'kataras/n… May 23, 2019
process_test.go rename project to 'kataras/neffos' and move client side to 'kataras/n… May 23, 2019
reflect.go New feature: Scale-out using Redis built-in StackExchange implementation Jul 11, 2019
server.go remove a doc comment on Server.Ask - it is available when scaling-out… Jul 15, 2019
server_test.go add a Server#Ask as requested at: #1 (comment) Jul 12, 2019
stackexchange.go Add nats support for the Server.Ask method - redis will support this … Jul 13, 2019
waiter_once.go rename project to 'kataras/neffos' and move client side to 'kataras/n… May 23, 2019

README.md

build status report card view examples chat frontend pkg

About neffos

Neffos is a cross-platform real-time framework with expressive, elegant API written in Go. Neffos takes the pain out of development by easing common tasks used in real-time backend and frontend applications such as:

  • Scale-out using redis or nats*
  • Adaptive request upgradation and server dialing
  • Acknowledgements
  • Namespaces
  • Rooms
  • Broadcast
  • Event-Driven architecture
  • Request-Response architecture
  • Error Awareness
  • Asynchronous Broadcast
  • Timeouts
  • Encoding
  • Reconnection
  • Modern neffos API client for Browsers, Nodejs* and Go

Learning neffos

Qick View

Server

import (
    // [...]
    "github.com/kataras/neffos"
    "github.com/kataras/neffos/gorilla"
)

func runServer() {
    events := make(neffos.Namespaces)
    events.On("/v1", "workday", func(ns *neffos.NSConn, msg neffos.Message) error {
        date := string(msg.Body)

        t, err := time.Parse("01-02-2006", date)
        if err != nil {
            if n := ns.Conn.Increment("tries"); n >= 3 && n%3 == 0 {
                // Return custom error text to the client.
                return fmt.Errorf("Why not try this one? 06-24-2019")
            } else if n >= 6 && n%2 == 0 {
                // Fire the "notify" client event.
                ns.Emit("notify", []byte("What are you doing?"))
            }
            // Return the parse error back to the client.
            return err
        }

        weekday := t.Weekday()

        if weekday == time.Saturday || weekday == time.Sunday {
            return neffos.Reply([]byte("day off"))
        }

        // Reply back to the client.
        responseText := fmt.Sprintf("it's %s, do your job.", weekday)
        return neffos.Reply([]byte(responseText))
    })

    websocketServer := neffos.New(gorilla.DefaultUpgrader, events)

    // Fire the "/v1:notify" event to all clients after server's 1 minute.
    time.AfterFunc(1*time.Minute, func() {
        websocketServer.Broadcast(nil, neffos.Message{
            Namespace: "/v1",
            Event:     "notify",
            Body:      []byte("server is up and running for 1 minute"),
        })
    })

    router := http.NewServeMux()
    router.Handle("/", websocketServer)

    log.Println("Serving websockets on localhost:8080")
    log.Fatal(http.ListenAndServe(":8080", router))
}

Go Client

func runClient() {
    ctx := context.TODO()
    events := make(neffos.Namespaces)
    events.On("/v1", "notify", func(c *neffos.NSConn, msg neffos.Message) error {
        log.Printf("Server says: %s\n", string(msg.Body))
        return nil
    })

    // Connect to the server.
    client, err := neffos.Dial(ctx,
        gorilla.DefaultDialer,
        "ws://localhost:8080",
        events)
    if err != nil {
        panic(err)
    }

    // Connect to a namespace.
    c, err := client.Connect(ctx, "/v1")
    if err != nil {
        panic(err)
    }

    fmt.Println("Please specify a date of format: mm-dd-yyyy")

    for {
        fmt.Print(">> ")
        var date string
        fmt.Scanln(&date)

        // Send to the server and wait reply to this message.
        response, err := c.Ask(ctx, "workday", []byte(date))
        if err != nil {
            if neffos.IsCloseError(err) {
                // Check if the error is a close signal,
                // or make use of the `<- client.NotifyClose`
                // read-only channel instead.
                break
            }

            // >> 13-29-2019
            // error received: parsing time "13-29-2019": month out of range
            fmt.Printf("error received: %v\n", err)
            continue
        }

        // >> 06-29-2019
        // it's a day off!
        //
        // >> 06-24-2019
        // it's Monday, do your job.
        fmt.Println(string(response.Body))
    }
}

Javascript Client

Navigate to: https://github.com/kataras/neffos.js

Neffos contains extensive and thorough wiki making it easy to get started with the framework.

For a more detailed technical documentation you can head over to our godocs. And for executable code you can always visit the _examples repository's subdirectory.

Do you like to read while traveling?

You can request a PDF version of the E-Book today and be participated in the development of neffos.

https://iris-go.com/images/neffos-book-overview.png

Contributing

We'd love to see your contribution to the neffos real-time framework! For more information about contributing to the neffos project please check the CONTRIBUTING.md file.

Security Vulnerabilities

If you discover a security vulnerability within neffos, please send an e-mail to neffos-go@outlook.com. All security vulnerabilities will be promptly addressed.

License

The word "neffos" has a greek origin and it is translated to "cloud" in English dictionary.

The neffos real-time framework is open-source software licensed under the MIT license.

You can’t perform that action at this time.