diff --git a/cmd/web/go.mod b/cmd/web/go.mod index 138a37d7..c62e82ad 100644 --- a/cmd/web/go.mod +++ b/cmd/web/go.mod @@ -26,7 +26,7 @@ require ( github.com/issue9/config v0.8.0 // indirect github.com/issue9/conv v1.3.5 // indirect github.com/issue9/errwrap v0.3.2 // indirect - github.com/issue9/mux/v9 v9.1.1 // indirect + github.com/issue9/mux/v9 v9.1.2 // indirect github.com/issue9/query/v3 v3.1.3 // indirect github.com/issue9/scheduled v0.21.3 // indirect github.com/issue9/sliceutil v0.17.0 // indirect diff --git a/cmd/web/go.sum b/cmd/web/go.sum index 33ef4ce2..065806f4 100644 --- a/cmd/web/go.sum +++ b/cmd/web/go.sum @@ -30,8 +30,8 @@ github.com/issue9/localeutil v0.29.1 h1:C5vxqwcAFa9gzMWDni8KsZ2GYtKD+I20RMlKl78t github.com/issue9/localeutil v0.29.1/go.mod h1:daxDbw51s4GWKjz6pxhh8baHzWDJEUUcsVrqaKs/A8o= github.com/issue9/logs/v7 v7.6.4 h1:NFM4oM2ggLPPZNgDb8PAOSqELtJOx7PTwoFd3o814wk= github.com/issue9/logs/v7 v7.6.4/go.mod h1:6fIj8OABk/qWm1c3E9f9oXe0FWwRyoZNWh449D391Zk= -github.com/issue9/mux/v9 v9.1.1 h1:o+oMKaQA8+90RusjkQw9WUWT5ttfoZTdX6TdlSgCtYM= -github.com/issue9/mux/v9 v9.1.1/go.mod h1:CLtV5ZfIrAmfaC/qxn07wXc3GALI45GYCsdE3c/h9CQ= +github.com/issue9/mux/v9 v9.1.2 h1:Ng5uv8bwsduZV6w14gv0HR78ahBs8Fm0JWlc7Xjtbd4= +github.com/issue9/mux/v9 v9.1.2/go.mod h1:CLtV5ZfIrAmfaC/qxn07wXc3GALI45GYCsdE3c/h9CQ= github.com/issue9/query/v3 v3.1.3 h1:Y6ETEYXxaKqhpM4lXPKCffhJ72VuKQbrAwgwHlacu0Y= github.com/issue9/query/v3 v3.1.3/go.mod h1:a/W/+7iel9K+5rRT4AFAKR8+OJeV5axeF6tK9My4lNA= github.com/issue9/rands/v3 v3.0.1 h1:EnX9WNushGgHCzoL/R5eBPaLfvjLO/c7CGHNgLK0JhY= diff --git a/mimetype/sse/server.go b/mimetype/sse/server.go index 16622c08..ed6cb1c0 100644 --- a/mimetype/sse/server.go +++ b/mimetype/sse/server.go @@ -137,8 +137,11 @@ func (srv *Server[T]) NewSource(sid T, ctx *web.Context) (s *Source, wait func() srv.sources.Store(sid, s) go func() { - s.connect(ctx) // 阻塞,出错退出 - defer close(s.buf) // 退出之前关闭,防止退出之后,依然有数据源源不断地从 Sent 输入。 + s.connect(ctx) // 阻塞,出错退出 + defer func() { + close(s.buf) // 退出之前关闭,防止退出之后,依然有数据源源不断地从 Sent 输入。 + s.buf = nil + }() defer srv.sources.Delete(sid) // 如果 connect 返回,说明断开了连接,删除 sources 中的记录。 }() return s, s.wait @@ -231,8 +234,11 @@ func (s *Source) LastEventID() string { return s.lastID } // Sent 发送消息 // // id 和 event 都可以为空,表示不需要这些值; -// 如果不想输出 retry 可以输出一个非整数,按照规则客户端会忽略非整数的值; -func (s *Source) Sent(data []string, event, id string) { s.buf <- s.bytes(data, event, id) } +func (s *Source) Sent(data []string, event, id string) { + if s.buf != nil { + s.buf <- s.bytes(data, event, id) + } +} func (s *Source) bytes(data []string, event, id string) *bytes.Buffer { if len(data) == 0 { diff --git a/server/config/codec.go b/server/config/codec.go index 9ba00fbb..d6129fd5 100644 --- a/server/config/codec.go +++ b/server/config/codec.go @@ -59,6 +59,7 @@ type mimetypeConfig struct { // - form // - html // - gob + // - yaml // - nop 没有具体实现的方法,对于上传等需要自行处理的情况可以指定此值。 Target string `json:"target" yaml:"target" xml:"target,attr"` } diff --git a/web.go b/web.go index 7bf80eac..56e63d68 100644 --- a/web.go +++ b/web.go @@ -24,7 +24,7 @@ import ( ) // Version 当前框架的版本 -const Version = "0.100.6" +const Version = "0.100.7" type ( Logger = logs.Logger