(genpkg string, svc *expr.HTTPServiceExpr, services *httpcodegen.ServicesData)
| 10 | ) |
| 11 | |
| 12 | func websocketClientFile(genpkg string, svc *expr.HTTPServiceExpr, services *httpcodegen.ServicesData) *codegen.File { |
| 13 | data := services.Get(svc.Name()) |
| 14 | if !httpcodegen.HasWebSocket(data) { |
| 15 | return nil |
| 16 | } |
| 17 | |
| 18 | svcName := data.Service.PathName |
| 19 | title := fmt.Sprintf("%s WebSocket JSON-RPC client", svc.Name()) |
| 20 | |
| 21 | // Build imports list for WebSocket clients |
| 22 | imports := make([]*codegen.ImportSpec, 0, 15+len(data.Service.UserTypeImports)) |
| 23 | imports = append(imports, |
| 24 | &codegen.ImportSpec{Path: "bytes"}, |
| 25 | &codegen.ImportSpec{Path: "context"}, |
| 26 | &codegen.ImportSpec{Path: "encoding/json"}, |
| 27 | &codegen.ImportSpec{Path: "fmt"}, |
| 28 | &codegen.ImportSpec{Path: "io"}, |
| 29 | &codegen.ImportSpec{Path: "net/http"}, |
| 30 | &codegen.ImportSpec{Path: "strconv"}, |
| 31 | &codegen.ImportSpec{Path: "sync"}, |
| 32 | &codegen.ImportSpec{Path: "sync/atomic"}, |
| 33 | &codegen.ImportSpec{Path: "time"}, |
| 34 | &codegen.ImportSpec{Path: "github.com/gorilla/websocket"}, |
| 35 | codegen.GoaImport(""), |
| 36 | codegen.GoaImport("jsonrpc"), |
| 37 | codegen.GoaNamedImport("http", "goahttp"), |
| 38 | &codegen.ImportSpec{Path: genpkg + "/" + svcName, Name: data.Service.PkgName}, |
| 39 | ) |
| 40 | imports = append(imports, data.Service.UserTypeImports...) |
| 41 | |
| 42 | sections := []*codegen.SectionTemplate{ |
| 43 | codegen.Header(title, "client", imports), |
| 44 | } |
| 45 | |
| 46 | // Add common error handling types for all streams |
| 47 | sections = append(sections, &codegen.SectionTemplate{ |
| 48 | Name: "jsonrpc-websocket-stream-error-types", |
| 49 | Source: jsonrpcTemplates.Read(websocketStreamErrorTypesT), |
| 50 | }) |
| 51 | |
| 52 | // Process only WebSocket endpoints and generate stream implementations only |
| 53 | for _, e := range data.Endpoints { |
| 54 | if !httpcodegen.IsWebSocketEndpoint(e) { |
| 55 | continue |
| 56 | } |
| 57 | |
| 58 | // Add stream implementation (endpoint methods are in client.go) |
| 59 | sections = append(sections, &codegen.SectionTemplate{ |
| 60 | Name: "jsonrpc-websocket-client-stream", |
| 61 | Source: jsonrpcTemplates.Read(websocketClientStreamT), |
| 62 | Data: e.ClientWebSocket, |
| 63 | }) |
| 64 | } |
| 65 | |
| 66 | return &codegen.File{ |
| 67 | Path: filepath.Join(codegen.Gendir, "jsonrpc", svcName, "client", "websocket.go"), |
| 68 | SectionTemplates: sections, |
| 69 | } |
no test coverage detected