重构: 各类型 Controller 接口精简,配合 framework-v2 internal/handler 收拢公共实现
app.go/condflow.go/cron.go/event_stream.go/executor.go/gobridge.go/grpc.go/job.go/mcp.go/mqtt.go/res_virtual_table.go/ws.go/controller.go/support/service.go 精简掉搬到 framework-v2 internal/handler 里的公共默认实现,只保留接口定义。
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
package contracts
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"git.fsdpf.net/go/req"
|
||||
"github.com/samber/do/v2"
|
||||
)
|
||||
|
||||
type EventStream interface {
|
||||
@@ -21,47 +19,3 @@ type EventStream interface {
|
||||
// 发送数据
|
||||
Sent(data, event string) error
|
||||
}
|
||||
|
||||
type EsHandleController struct {
|
||||
Controller
|
||||
w http.ResponseWriter
|
||||
flusher http.Flusher
|
||||
request *http.Request
|
||||
}
|
||||
|
||||
func (this EsHandleController) Request() *http.Request {
|
||||
return this.request
|
||||
}
|
||||
|
||||
func (this EsHandleController) Route() req.Route {
|
||||
return this.Request().Context().Value(req.RouteCtx{Name: "Route"}).(req.Route)
|
||||
}
|
||||
|
||||
func (this EsHandleController) User() req.User {
|
||||
return this.Request().Context().Value(req.RouteCtx{Name: "User"}).(req.User)
|
||||
}
|
||||
|
||||
func (this EsHandleController) Execute(req.GlobalParams) error {
|
||||
return ErrFuncNotImplemented
|
||||
}
|
||||
|
||||
func (this EsHandleController) Sent(data, event string) error {
|
||||
if _, err := io.WriteString(this.w, "event: "+event+"\ndata: "+data+"\n\n"); err != nil {
|
||||
return err
|
||||
}
|
||||
this.flusher.Flush()
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewEventStreamController(container do.Injector, request *http.Request, w http.ResponseWriter) EventStream {
|
||||
w.Header().Set("Content-Type", "text/event-stream")
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
w.Header().Set("Connection", "keep-alive")
|
||||
|
||||
return &EsHandleController{
|
||||
Controller: &BaseController{container},
|
||||
request: request,
|
||||
w: w,
|
||||
flusher: w.(http.Flusher),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user