Skip to content

Commit e7e5a2b

Browse files
committed
Implement skeleton of websocket connect
1 parent 263d659 commit e7e5a2b

15 files changed

+455
-9
lines changed

app/contexts.go

Lines changed: 50 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controllers.go

Lines changed: 64 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/hrefs.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/media_types.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/test/connect_v1_testing.go

Lines changed: 100 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/test/discover_v1_testing.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/test/public_testing.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/user_types.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

connect_v1.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"github.com/arduino/arduino-create-agent/app"
5+
"github.com/goadesign/goa"
6+
"golang.org/x/net/websocket"
7+
"io"
8+
)
9+
10+
// ConnectV1Controller implements the connect_v1 resource.
11+
type ConnectV1Controller struct {
12+
*goa.Controller
13+
}
14+
15+
// NewConnectV1Controller creates a connect_v1 controller.
16+
func NewConnectV1Controller(service *goa.Service) *ConnectV1Controller {
17+
return &ConnectV1Controller{Controller: service.NewController("ConnectV1Controller")}
18+
}
19+
20+
// Websocket runs the websocket action.
21+
func (c *ConnectV1Controller) Websocket(ctx *app.WebsocketConnectV1Context) error {
22+
c.WebsocketWSHandler(ctx).ServeHTTP(ctx.ResponseWriter, ctx.Request)
23+
return nil
24+
}
25+
26+
// WebsocketWSHandler establishes a websocket connection to run the websocket action.
27+
func (c *ConnectV1Controller) WebsocketWSHandler(ctx *app.WebsocketConnectV1Context) websocket.Handler {
28+
return func(ws *websocket.Conn) {
29+
// ConnectV1Controller_Websocket: start_implement
30+
31+
// Put your logic here
32+
33+
// ConnectV1Controller_Websocket: end_implement
34+
ws.Write([]byte("websocket connect_v1"))
35+
// Dummy echo websocket server
36+
io.Copy(ws, ws)
37+
}
38+
}

design/connect.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package design
2+
3+
import (
4+
. "github.com/goadesign/goa/design"
5+
. "github.com/goadesign/goa/design/apidsl"
6+
)
7+
8+
var _ = Resource("connect_v1", func() {
9+
Action("websocket", func() {
10+
Routing(GET("/v1/connect"))
11+
Scheme("ws")
12+
Description("Opens a websocket connection to the device, allowing to read/write")
13+
Params(func() {
14+
Param("port", String, "The port where the device resides", func() {
15+
Example("/dev/ttyACM0")
16+
})
17+
Param("baud", Integer, "The speed of the connection. Defaults to 9600", func() {
18+
Example(9600)
19+
Default(9600)
20+
})
21+
Required("port", "baud")
22+
})
23+
Response(BadRequest)
24+
Response(SwitchingProtocols)
25+
})
26+
})

design/design.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package design
22

33
import (
4-
. "github.com/goadesign/goa/design"
54
. "github.com/goadesign/goa/design/apidsl"
65
)
76

@@ -26,4 +25,5 @@ var _ = Resource("public", func() {
2625

2726
Files("swagger.json", "swagger/swagger.json")
2827
Files("docs", "templates/docs.html")
28+
Files("debug", "templates/debug.html")
2929
})

0 commit comments

Comments
 (0)