Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Go DDP Server


## Example

```go
package main

import (
"github.com/meteorhacks/goddp/server"
)

func main() {
server := server.New()
server.Method("hello", methodHandler)
server.Listen(":1337")
}

func methodHandler(p []interface{}) (interface{}, error) {
return "result", nil
}
```
1 change: 1 addition & 0 deletions client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package client
14 changes: 0 additions & 14 deletions main.go

This file was deleted.

3 changes: 2 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"

"github.com/gorilla/websocket"
"github.com/meteorhacks/goddp/utils/random"
)

type Server struct {
Expand Down Expand Up @@ -70,7 +71,7 @@ func (s *Server) handler(w http.ResponseWriter, r *http.Request) {
func (s *Server) handleConnect(c *websocket.Conn, m *Message) {
err := c.WriteJSON(map[string]string{
"msg": "connected",
"session": randomId(17),
"session": random.Id(17),
})

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion server/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package server

type MethodHandler func([]interface{}) (interface{}, error)

// This has the all the possible messgae a DDP message can have
// This has the all the possible fields a DDP message can have
type Message struct {
Msg string `json:"msg"`
Session string `json:"session"`
Expand Down
15 changes: 0 additions & 15 deletions server/utils.go

This file was deleted.

18 changes: 18 additions & 0 deletions utils/random/random.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package random

import (
"math/rand"
)

var dict = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

func Id(n int) string {
a := make([]rune, n)
l := len(dict)

for i := range a {
a[i] = dict[rand.Intn(l)]
}

return string(a)
}