del(websocket): move ws out of rest
This commit is contained in:
+1
-19
@@ -450,22 +450,4 @@ The following event types may be sent with a message event:
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| query | string | GET | Search query to match against users | N/A | NO |
|
||||
|
||||
|
||||
|
||||
|
||||
# Websocket
|
||||
|
||||
## Bidirectional websocket chat connection
|
||||
|
||||
#### Method
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/websocket/client` | WebSockets | GET | Client ID, Session ID |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| query | string | GET | Search query to match against users | N/A | NO |
|
||||
@@ -442,28 +442,5 @@
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Websocket",
|
||||
"package": "sam",
|
||||
"entrypoint": "websocket",
|
||||
"protocol": "WebSockets",
|
||||
"authentication": ["Client ID", "Session ID"],
|
||||
"struct": [
|
||||
{
|
||||
"name": "Websocket",
|
||||
"fields": [
|
||||
{ "type": "uint64", "name": "UserID" },
|
||||
{ "type": "User", "name": "User", "complex": true }
|
||||
]
|
||||
}
|
||||
],
|
||||
"apis": [
|
||||
{
|
||||
"name": "client",
|
||||
"method": "GET",
|
||||
"title": "Bidirectional websocket chat connection"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
{
|
||||
"Title": "Websocket",
|
||||
"Package": "sam",
|
||||
"Interface": "Websocket",
|
||||
"Struct": [
|
||||
{
|
||||
"fields": [
|
||||
{
|
||||
"name": "UserID",
|
||||
"type": "uint64"
|
||||
},
|
||||
{
|
||||
"complex": true,
|
||||
"name": "User",
|
||||
"type": "User"
|
||||
}
|
||||
],
|
||||
"name": "Websocket"
|
||||
}
|
||||
],
|
||||
"Protocol": "WebSockets",
|
||||
"Authentication": [
|
||||
"Client ID",
|
||||
"Session ID"
|
||||
],
|
||||
"Path": "/websocket",
|
||||
"APIs": [
|
||||
{
|
||||
"Name": "client",
|
||||
"Method": "GET",
|
||||
"Title": "Bidirectional websocket chat connection",
|
||||
"Path": "/client",
|
||||
"Parameters": null
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -29,7 +29,3 @@ func (*Message) Authenticator() func(http.Handler) http.Handler {
|
||||
func (*User) Authenticator() func(http.Handler) http.Handler {
|
||||
return pass
|
||||
}
|
||||
|
||||
func (*Websocket) Authenticator() func(http.Handler) http.Handler {
|
||||
return pass
|
||||
}
|
||||
|
||||
+2
-9
@@ -10,8 +10,8 @@ package rest
|
||||
1. run [spec](https://github.com/titpetric/spec) in the same folder,
|
||||
2. run `./_gen.php` in this folder.
|
||||
|
||||
You may edit `websocket.go`, `websocket.util.go` or `websocket_test.go` to
|
||||
implement your API calls, helper functions and tests. The file `websocket.go`
|
||||
You may edit `user.go`, `user.util.go` or `user_test.go` to
|
||||
implement your API calls, helper functions and tests. The file `user.go`
|
||||
is only generated the first time, and will not be overwritten if it exists.
|
||||
*/
|
||||
|
||||
@@ -30,7 +30,6 @@ func MountRoutes(r chi.Router) {
|
||||
organisation := &server.OrganisationHandlers{Organisation{}.New()}
|
||||
team := &server.TeamHandlers{Team{}.New()}
|
||||
user := &server.UserHandlers{User{}.New()}
|
||||
websocket := &server.WebsocketHandlers{Websocket{}.New()}
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(channel.Channel.Authenticator())
|
||||
r.Route("/channel", func(r chi.Router) {
|
||||
@@ -84,12 +83,6 @@ func MountRoutes(r chi.Router) {
|
||||
r.Get("/search", user.Search)
|
||||
})
|
||||
})
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(websocket.Websocket.Authenticator())
|
||||
r.Route("/websocket", func(r chi.Router) {
|
||||
r.Get("/client", websocket.Client)
|
||||
})
|
||||
})
|
||||
|
||||
var printRoutes func(chi.Routes, string, string)
|
||||
printRoutes = func(r chi.Routes, indent string, prefix string) {
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package server
|
||||
|
||||
/*
|
||||
Hello! This file is auto-generated from `docs/src/spec.json`.
|
||||
|
||||
For development:
|
||||
In order to update the generated files, edit this file under the location,
|
||||
add your struct fields, imports, API definitions and whatever you want, and:
|
||||
|
||||
1. run [spec](https://github.com/titpetric/spec) in the same folder,
|
||||
2. run `./_gen.php` in this folder.
|
||||
|
||||
You may edit `websocket.go`, `websocket.util.go` or `websocket_test.go` to
|
||||
implement your API calls, helper functions and tests. The file `websocket.go`
|
||||
is only generated the first time, and will not be overwritten if it exists.
|
||||
*/
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// HTTP handlers are a superset of internal APIs
|
||||
type WebsocketHandlers struct {
|
||||
Websocket WebsocketAPI
|
||||
}
|
||||
|
||||
// Internal API interface
|
||||
type WebsocketAPI interface {
|
||||
Client(context.Context, *WebsocketClientRequest) (interface{}, error)
|
||||
|
||||
// Authenticate API requests
|
||||
Authenticator() func(http.Handler) http.Handler
|
||||
}
|
||||
|
||||
// HTTP API interface
|
||||
type WebsocketHandlersAPI interface {
|
||||
Client(http.ResponseWriter, *http.Request)
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package server
|
||||
|
||||
/*
|
||||
Hello! This file is auto-generated from `docs/src/spec.json`.
|
||||
|
||||
For development:
|
||||
In order to update the generated files, edit this file under the location,
|
||||
add your struct fields, imports, API definitions and whatever you want, and:
|
||||
|
||||
1. run [spec](https://github.com/titpetric/spec) in the same folder,
|
||||
2. run `./_gen.php` in this folder.
|
||||
|
||||
You may edit `websocket.go`, `websocket.util.go` or `websocket_test.go` to
|
||||
implement your API calls, helper functions and tests. The file `websocket.go`
|
||||
is only generated the first time, and will not be overwritten if it exists.
|
||||
*/
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/titpetric/factory/resputil"
|
||||
)
|
||||
|
||||
func (wh *WebsocketHandlers) Client(w http.ResponseWriter, r *http.Request) {
|
||||
params := WebsocketClientRequest{}.new()
|
||||
resputil.JSON(w, params.Fill(r), func() (interface{}, error) { return wh.Websocket.Client(r.Context(), params) })
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package server
|
||||
|
||||
/*
|
||||
Hello! This file is auto-generated from `docs/src/spec.json`.
|
||||
|
||||
For development:
|
||||
In order to update the generated files, edit this file under the location,
|
||||
add your struct fields, imports, API definitions and whatever you want, and:
|
||||
|
||||
1. run [spec](https://github.com/titpetric/spec) in the same folder,
|
||||
2. run `./_gen.php` in this folder.
|
||||
|
||||
You may edit `websocket.go`, `websocket.util.go` or `websocket_test.go` to
|
||||
implement your API calls, helper functions and tests. The file `websocket.go`
|
||||
is only generated the first time, and will not be overwritten if it exists.
|
||||
*/
|
||||
|
||||
import (
|
||||
"github.com/go-chi/chi"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var _ = chi.URLParam
|
||||
|
||||
// Websocket client request parameters
|
||||
type WebsocketClientRequest struct {
|
||||
}
|
||||
|
||||
func (WebsocketClientRequest) new() *WebsocketClientRequest {
|
||||
return &WebsocketClientRequest{}
|
||||
}
|
||||
|
||||
func (w *WebsocketClientRequest) Fill(r *http.Request) error {
|
||||
r.ParseForm()
|
||||
get := map[string]string{}
|
||||
post := map[string]string{}
|
||||
urlQuery := r.URL.Query()
|
||||
for name, param := range urlQuery {
|
||||
get[name] = string(param[0])
|
||||
}
|
||||
postVars := r.Form
|
||||
for name, param := range postVars {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ RequestFiller = WebsocketClientRequest{}.new()
|
||||
@@ -1,21 +0,0 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/crusttech/crust/sam/rest/server"
|
||||
_ "github.com/crusttech/crust/sam/types"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type Websocket struct{}
|
||||
|
||||
func (Websocket) New() *Websocket {
|
||||
return &Websocket{}
|
||||
}
|
||||
|
||||
func (*Websocket) Client(ctx context.Context, r *server.WebsocketClientRequest) (interface{}, error) {
|
||||
return nil, errors.New("Not implemented: Websocket.client")
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package types
|
||||
|
||||
/*
|
||||
Hello! This file is auto-generated from `docs/src/spec.json`.
|
||||
|
||||
For development:
|
||||
In order to update the generated files, edit this file under the location,
|
||||
add your struct fields, imports, API definitions and whatever you want, and:
|
||||
|
||||
1. run [spec](https://github.com/titpetric/spec) in the same folder,
|
||||
2. run `./_gen.php` in this folder.
|
||||
|
||||
You may edit `websocket.go`, `websocket.util.go` or `websocket_test.go` to
|
||||
implement your API calls, helper functions and tests. The file `websocket.go`
|
||||
is only generated the first time, and will not be overwritten if it exists.
|
||||
*/
|
||||
|
||||
type (
|
||||
// Websocket -
|
||||
Websocket struct {
|
||||
UserID uint64 `db:"user_id"`
|
||||
User User `db:"user"`
|
||||
|
||||
changed []string
|
||||
}
|
||||
)
|
||||
|
||||
// New constructs a new instance of Websocket
|
||||
func (Websocket) New() *Websocket {
|
||||
return &Websocket{}
|
||||
}
|
||||
|
||||
// Get the value of UserID
|
||||
func (w *Websocket) GetUserID() uint64 {
|
||||
return w.UserID
|
||||
}
|
||||
|
||||
// Set the value of UserID
|
||||
func (w *Websocket) SetUserID(value uint64) *Websocket {
|
||||
if w.UserID != value {
|
||||
w.changed = append(w.changed, "UserID")
|
||||
w.UserID = value
|
||||
}
|
||||
return w
|
||||
}
|
||||
|
||||
// Get the value of User
|
||||
func (w *Websocket) GetUser() User {
|
||||
return w.User
|
||||
}
|
||||
|
||||
// Set the value of User
|
||||
func (w *Websocket) SetUser(value User) *Websocket {
|
||||
w.changed = append(w.changed, "User")
|
||||
w.User = value
|
||||
return w
|
||||
}
|
||||
|
||||
// Changes returns the names of changed fields
|
||||
func (w *Websocket) Changes() []string {
|
||||
return w.changed
|
||||
}
|
||||
Reference in New Issue
Block a user