You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.4 KiB
66 lines
1.4 KiB
package main |
|
|
|
// import ( |
|
// "fmt" |
|
// "net/http" |
|
|
|
// "github.com/gorilla/websocket" |
|
// ) |
|
|
|
// type Message struct { |
|
// Name string `json:"name"` |
|
// Data interface{} `json:"data"` |
|
// } |
|
|
|
// type Client struct { |
|
// send chan Message |
|
// socket *websocket.Conn |
|
// // findHandler FindHandler |
|
// // session *r.Session |
|
// } |
|
|
|
// type Handler func(*Client, interface{}) |
|
|
|
// var upgrader = websocket.Upgrader{ |
|
// ReadBufferSize: 1024, |
|
// WriteBufferSize: 1024, |
|
// CheckOrigin: func(r *http.Request) bool { return true }, |
|
// } |
|
|
|
// type Router struct { |
|
// rules map[string]Handler |
|
// // session *r.Session |
|
// } |
|
|
|
// func NewRouter() *Router { |
|
// return &Router{ |
|
// rules: make(map[string]Handler), |
|
// // session: session, |
|
// } |
|
// } |
|
|
|
// func (r *Router) Handle(msgName string, handler Handler) { |
|
// r.rules[msgName] = handler |
|
// } |
|
|
|
// func (r *Router) FindHandler(msgName string) (Handler, bool) { |
|
// handler, found := r.rules[msgName] |
|
// return handler, found |
|
// } |
|
|
|
// func (e *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
|
// socket, err := upgrader.Upgrade(w, r, nil) |
|
// if err != nil { |
|
// w.WriteHeader(http.StatusInternalServerError) |
|
// fmt.Fprint(w, err.Error()) |
|
// return |
|
// } |
|
// client := NewClient(socket, e.FindHandler, e.session) |
|
// go client.Write() |
|
// client.Read() |
|
// } |
|
|
|
// // func main() { |
|
// // router := NewRouter() |
|
// // // router.Handle('channel add', addChannel) |
|
// // }
|
|
|