mirror of
https://github.com/raz-varren/sacrificial-socket.git
synced 2025-10-18 22:14:38 +08:00
I fmted
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package ssgrpc
|
||||
|
||||
import (
|
||||
"google.golang.org/grpc"
|
||||
"github.com/raz-varren/sacrificial-socket/backend/ssgrpc/transport"
|
||||
"google.golang.org/grpc"
|
||||
//"sync"
|
||||
)
|
||||
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package ssgrpc
|
||||
|
||||
import (
|
||||
"golang.org/x/net/context"
|
||||
"github.com/raz-varren/sacrificial-socket/backend/ssgrpc/token"
|
||||
"github.com/raz-varren/sacrificial-socket/log"
|
||||
"golang.org/x/net/context"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
@@ -3,12 +3,12 @@ package ssgrpc
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc/metadata"
|
||||
ss "github.com/raz-varren/sacrificial-socket"
|
||||
"github.com/raz-varren/sacrificial-socket/backend/ssgrpc/token"
|
||||
"github.com/raz-varren/sacrificial-socket/backend/ssgrpc/transport"
|
||||
"github.com/raz-varren/sacrificial-socket/log"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
@@ -2,13 +2,13 @@ package ssgrpc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
ss "github.com/raz-varren/sacrificial-socket"
|
||||
"github.com/raz-varren/sacrificial-socket/backend/ssgrpc/transport"
|
||||
"github.com/raz-varren/sacrificial-socket/log"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"net"
|
||||
ss "github.com/raz-varren/sacrificial-socket"
|
||||
"github.com/raz-varren/sacrificial-socket/backend/ssgrpc/transport"
|
||||
"github.com/raz-varren/sacrificial-socket/log"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -44,7 +44,7 @@ func NewBackend(tlsKeyFile, tlsCertFile, grpcHostPort string, sharedKey []byte,
|
||||
}
|
||||
}
|
||||
|
||||
//NewInsecureBackend returns a GRPCMHB that will use no encryption or authentication to connect to the
|
||||
//NewInsecureBackend returns a GRPCMHB that will use no encryption or authentication to connect to the
|
||||
//peers in peerList
|
||||
//
|
||||
//It is highly discouraged to use this for production systems, as all data will be sent in clear
|
||||
|
@@ -2,11 +2,11 @@ package ssmongo
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
ss "github.com/raz-varren/sacrificial-socket"
|
||||
"github.com/raz-varren/sacrificial-socket/log"
|
||||
"gopkg.in/mgo.v2"
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
"io"
|
||||
ss "github.com/raz-varren/sacrificial-socket"
|
||||
"github.com/raz-varren/sacrificial-socket/log"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
@@ -14,13 +14,13 @@ import (
|
||||
//MMHB implements ss.MultihomeBackend and uses MongoDB to syncronize between
|
||||
//multiple machines running ss.SocketServer
|
||||
type MMHB struct {
|
||||
session *mgo.Session
|
||||
serverC *mgo.Collection
|
||||
roomcastC *mgo.Collection
|
||||
broadcastC *mgo.Collection
|
||||
server backendServer
|
||||
session *mgo.Session
|
||||
serverC *mgo.Collection
|
||||
roomcastC *mgo.Collection
|
||||
broadcastC *mgo.Collection
|
||||
server backendServer
|
||||
pollFrequency time.Duration
|
||||
l *sync.RWMutex
|
||||
l *sync.RWMutex
|
||||
}
|
||||
|
||||
//NewMongoDBBackend returns a new instance of MMHB which satisfies the ss.MultihomeBackend interface.
|
||||
@@ -46,13 +46,13 @@ func NewBackend(mongoURL, serverName, serverGroup string, pollFrequency time.Dur
|
||||
}
|
||||
|
||||
return &MMHB{
|
||||
session: m,
|
||||
serverC: db.C("ss.activeServers"),
|
||||
roomcastC: db.C("ss.roomcasts"),
|
||||
broadcastC: db.C("ss.broadcasts"),
|
||||
server: s,
|
||||
session: m,
|
||||
serverC: db.C("ss.activeServers"),
|
||||
roomcastC: db.C("ss.roomcasts"),
|
||||
broadcastC: db.C("ss.broadcasts"),
|
||||
server: s,
|
||||
pollFrequency: pollFrequency,
|
||||
l: &sync.RWMutex{},
|
||||
l: &sync.RWMutex{},
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -3,11 +3,11 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"github.com/raz-varren/sacrificial-socket"
|
||||
"github.com/raz-varren/sacrificial-socket/backend/ssgrpc"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"github.com/raz-varren/sacrificial-socket"
|
||||
"github.com/raz-varren/sacrificial-socket/backend/ssgrpc"
|
||||
"strings"
|
||||
//"time"
|
||||
)
|
||||
@@ -101,20 +101,20 @@ func EchoJSON(s *ss.Socket, data []byte) {
|
||||
var m message
|
||||
err := json.Unmarshal(data, &m)
|
||||
check(err)
|
||||
|
||||
|
||||
s.Emit("echojson", m)
|
||||
}
|
||||
|
||||
func Join(s *ss.Socket, data []byte) {
|
||||
d := string(data)
|
||||
s.Join(d)
|
||||
s.Emit("echo", "joined room:" + d)
|
||||
s.Emit("echo", "joined room:"+d)
|
||||
}
|
||||
|
||||
func Leave(s *ss.Socket, data []byte) {
|
||||
d := string(data)
|
||||
s.Leave(d)
|
||||
s.Emit("echo", "left room:" + d)
|
||||
s.Emit("echo", "left room:"+d)
|
||||
}
|
||||
|
||||
func Roomcast(s *ss.Socket, data []byte) {
|
||||
@@ -129,7 +129,7 @@ func RoomcastBin(s *ss.Socket, data []byte) {
|
||||
var r roomcast
|
||||
err := json.Unmarshal(data, &r)
|
||||
check(err)
|
||||
|
||||
|
||||
s.Roomcast(r.Room, "roomcastbin", []byte(r.Data))
|
||||
}
|
||||
|
||||
@@ -141,12 +141,11 @@ func RoomcastJSON(s *ss.Socket, data []byte) {
|
||||
s.Roomcast(r.Room, "roomcastjson", r)
|
||||
}
|
||||
|
||||
|
||||
func Broadcast(s *ss.Socket, data []byte) {
|
||||
s.Broadcast("broadcast", string(data))
|
||||
}
|
||||
|
||||
func BroadcastBin(s *ss.Socket, data []byte){
|
||||
func BroadcastBin(s *ss.Socket, data []byte) {
|
||||
s.Broadcast("broadcastbin", data)
|
||||
}
|
||||
|
||||
@@ -154,7 +153,7 @@ func BroadcastJSON(s *ss.Socket, data []byte) {
|
||||
var m message
|
||||
err := json.Unmarshal(data, &m)
|
||||
check(err)
|
||||
|
||||
|
||||
s.Broadcast("broadcastjson", m)
|
||||
}
|
||||
|
||||
|
@@ -2,9 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
ss "github.com/raz-varren/sacrificial-socket"
|
||||
"log"
|
||||
"net/http"
|
||||
ss "github.com/raz-varren/sacrificial-socket"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@@ -8,12 +8,12 @@ Sacrificial-Socket also has a MultihomeBackend interface for syncronizing broadc
|
||||
package ss
|
||||
|
||||
import (
|
||||
"github.com/raz-varren/sacrificial-socket/log"
|
||||
"golang.org/x/net/websocket"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"github.com/raz-varren/sacrificial-socket/log"
|
||||
"sync"
|
||||
"syscall"
|
||||
)
|
||||
@@ -158,14 +158,13 @@ func (serv *SocketServer) loop(ws *websocket.Conn) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
eventName := ""
|
||||
contentIdx := 0
|
||||
|
||||
for idx, chr := range msg {
|
||||
if chr == startOfDataByte {
|
||||
eventName = string(msg[:idx])
|
||||
contentIdx = idx+1
|
||||
contentIdx = idx + 1
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@@ -2,10 +2,10 @@ package ss_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/raz-varren/sacrificial-socket"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"github.com/raz-varren/sacrificial-socket"
|
||||
)
|
||||
|
||||
func ExampleNewServer() {
|
||||
|
Reference in New Issue
Block a user