Skip to content

Commit 8ec17df

Browse files
committed
Rearrange code so go get can be used
- remove example main file - add README.md file
1 parent 8c933c7 commit 8ec17df

File tree

7 files changed

+44
-31
lines changed

7 files changed

+44
-31
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Go DDP Server
2+
3+
4+
## Example
5+
6+
```go
7+
package main
8+
9+
import (
10+
"github.com/meteorhacks/goddp/server"
11+
)
12+
13+
func main() {
14+
server := server.New()
15+
server.Method("hello", methodHandler)
16+
server.Listen(":1337")
17+
}
18+
19+
func methodHandler(p []interface{}) (interface{}, error) {
20+
return "result", nil
21+
}
22+
```

client/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package client

main.go

Lines changed: 0 additions & 14 deletions
This file was deleted.

server/server.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88

99
"github.com/gorilla/websocket"
10+
"github.com/meteorhacks/goddp/utils/random"
1011
)
1112

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

7677
if err != nil {

server/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package server
22

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

5-
// This has the all the possible messgae a DDP message can have
5+
// This has the all the possible fields a DDP message can have
66
type Message struct {
77
Msg string `json:"msg"`
88
Session string `json:"session"`

server/utils.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

utils/random/random.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package random
2+
3+
import (
4+
"math/rand"
5+
)
6+
7+
var dict = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
8+
9+
func Id(n int) string {
10+
a := make([]rune, n)
11+
l := len(dict)
12+
13+
for i := range a {
14+
a[i] = dict[rand.Intn(l)]
15+
}
16+
17+
return string(a)
18+
}

0 commit comments

Comments
 (0)