Skip to content

Commit

Permalink
Make struct:pkg:path Meta work for WebSocket endpoints (#3400)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael committed Oct 23, 2023
1 parent d3789bd commit 8af299c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 38 deletions.
32 changes: 17 additions & 15 deletions http/codegen/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,24 @@ func serverFile(genpkg string, svc *expr.HTTPServiceExpr) *codegen.File {
"addLeadingSlash": addLeadingSlash,
"removeTrailingIndexHTML": removeTrailingIndexHTML,
}
imports := []*codegen.ImportSpec{
{Path: "bufio"},
{Path: "context"},
{Path: "fmt"},
{Path: "io"},
{Path: "mime/multipart"},
{Path: "net/http"},
{Path: "path"},
{Path: "strings"},
{Path: "github.com/gorilla/websocket"},
codegen.GoaImport(""),
codegen.GoaNamedImport("http", "goahttp"),
{Path: genpkg + "/" + svcName, Name: data.Service.PkgName},
{Path: genpkg + "/" + svcName + "/" + "views", Name: data.Service.ViewsPkg},
}
imports = append(imports, data.Service.UserTypeImports...)
sections := []*codegen.SectionTemplate{
codegen.Header(title, "server", []*codegen.ImportSpec{
{Path: "bufio"},
{Path: "context"},
{Path: "fmt"},
{Path: "io"},
{Path: "mime/multipart"},
{Path: "net/http"},
{Path: "path"},
{Path: "strings"},
{Path: "github.com/gorilla/websocket"},
codegen.GoaImport(""),
codegen.GoaNamedImport("http", "goahttp"),
{Path: genpkg + "/" + svcName, Name: data.Service.PkgName},
{Path: genpkg + "/" + svcName + "/" + "views", Name: data.Service.ViewsPkg},
}),
codegen.Header(title, "server", imports),
}

sections = append(sections, &codegen.SectionTemplate{Name: "server-struct", Source: serverStructT, Data: data})
Expand Down
50 changes: 27 additions & 23 deletions http/codegen/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,20 @@ func websocketServerFile(genpkg string, svc *expr.HTTPServiceExpr) *codegen.File
}
svcName := data.Service.PathName
title := fmt.Sprintf("%s WebSocket server streaming", svc.Name())
imports := []*codegen.ImportSpec{
{Path: "context"},
{Path: "io"},
{Path: "net/http"},
{Path: "sync"},
{Path: "time"},
{Path: "github.com/gorilla/websocket"},
codegen.GoaImport(""),
codegen.GoaNamedImport("http", "goahttp"),
{Path: genpkg + "/" + svcName, Name: data.Service.PkgName},
}
imports = append(imports, data.Service.UserTypeImports...)
sections := []*codegen.SectionTemplate{
codegen.Header(title, "server", []*codegen.ImportSpec{
{Path: "context"},
{Path: "io"},
{Path: "net/http"},
{Path: "sync"},
{Path: "time"},
{Path: "github.com/gorilla/websocket"},
codegen.GoaImport(""),
codegen.GoaNamedImport("http", "goahttp"),
{Path: genpkg + "/" + svcName, Name: data.Service.PkgName},
}),
codegen.Header(title, "server", imports),
}
sections = append(sections, serverStructWSSections(data)...)
sections = append(sections, serverWSSections(data)...)
Expand All @@ -262,19 +264,21 @@ func websocketClientFile(genpkg string, svc *expr.HTTPServiceExpr) *codegen.File
}
svcName := data.Service.PathName
title := fmt.Sprintf("%s WebSocket client streaming", svc.Name())
imports := []*codegen.ImportSpec{
{Path: "context"},
{Path: "io"},
{Path: "net/http"},
{Path: "sync"},
{Path: "time"},
{Path: "github.com/gorilla/websocket"},
codegen.GoaImport(""),
codegen.GoaNamedImport("http", "goahttp"),
{Path: genpkg + "/" + svcName + "/" + "views", Name: data.Service.ViewsPkg},
{Path: genpkg + "/" + svcName, Name: data.Service.PkgName},
}
imports = append(imports, data.Service.UserTypeImports...)
sections := []*codegen.SectionTemplate{
codegen.Header(title, "client", []*codegen.ImportSpec{
{Path: "context"},
{Path: "io"},
{Path: "net/http"},
{Path: "sync"},
{Path: "time"},
{Path: "github.com/gorilla/websocket"},
codegen.GoaImport(""),
codegen.GoaNamedImport("http", "goahttp"),
{Path: genpkg + "/" + svcName + "/" + "views", Name: data.Service.ViewsPkg},
{Path: genpkg + "/" + svcName, Name: data.Service.PkgName},
}),
codegen.Header(title, "client", imports),
}
sections = append(sections, clientStructWSSections(data)...)
sections = append(sections, clientWSSections(data)...)
Expand Down

0 comments on commit 8af299c

Please sign in to comment.