From 26a10947e38812bd9cc8e4221321a08500b74a07 Mon Sep 17 00:00:00 2001 From: q191201771 <191201771@qq.com> Date: Wed, 1 Jun 2022 21:04:35 +0800 Subject: [PATCH] [refactor] rename HttpSubSession -> BasicHttpSubSession --- ...b_session.go => basic_http_sub_session.go} | 44 +++++++++---------- pkg/base/http_server.go | 2 + pkg/base/{t_http_api.go => t_http_an__api.go} | 2 - ...{t_http_notify.go => t_http_an__notify.go} | 4 +- pkg/base/t_session.go | 2 +- pkg/httpflv/server_sub_session.go | 4 +- pkg/httpts/server_sub_session.go | 4 +- pkg/innertest/iface_impl.go | 8 ++-- pkg/logic/{group.go => group__.go} | 2 - ...{server_manager.go => server_manager__.go} | 0 10 files changed, 33 insertions(+), 39 deletions(-) rename pkg/base/{http_sub_session.go => basic_http_sub_session.go} (71%) rename pkg/base/{t_http_api.go => t_http_an__api.go} (97%) rename pkg/base/{t_http_notify.go => t_http_an__notify.go} (96%) rename pkg/logic/{group.go => group__.go} (99%) rename pkg/logic/{server_manager.go => server_manager__.go} (100%) diff --git a/pkg/base/http_sub_session.go b/pkg/base/basic_http_sub_session.go similarity index 71% rename from pkg/base/http_sub_session.go rename to pkg/base/basic_http_sub_session.go index 7075ae6..5b41fb4 100644 --- a/pkg/base/http_sub_session.go +++ b/pkg/base/basic_http_sub_session.go @@ -15,17 +15,15 @@ import ( "github.com/q191201771/naza/pkg/connection" ) -// TODO(chef): refactor 更名为BasicHttpSubSession 202205 - -type HttpSubSession struct { - HttpSubSessionOption +type BasicHttpSubSession struct { + BasicHttpSubSessionOption suffix string conn connection.Connection sessionStat BasicSessionStat } -type HttpSubSessionOption struct { +type BasicHttpSubSessionOption struct { Conn net.Conn ConnModOption connection.ModOption SessionType SessionType @@ -34,11 +32,11 @@ type HttpSubSessionOption struct { WebSocketKey string } -func NewHttpSubSession(option HttpSubSessionOption) *HttpSubSession { - s := &HttpSubSession{ - HttpSubSessionOption: option, - conn: connection.New(option.Conn, option.ConnModOption), - sessionStat: NewBasicSessionStat(option.SessionType, ""), +func NewBasicHttpSubSession(option BasicHttpSubSessionOption) *BasicHttpSubSession { + s := &BasicHttpSubSession{ + BasicHttpSubSessionOption: option, + conn: connection.New(option.Conn, option.ConnModOption), + sessionStat: NewBasicSessionStat(option.SessionType, ""), } return s } @@ -47,19 +45,19 @@ func NewHttpSubSession(option HttpSubSessionOption) *HttpSubSession { // IServerSessionLifecycle interface // --------------------------------------------------------------------------------------------------------------------- -func (session *HttpSubSession) RunLoop() error { +func (session *BasicHttpSubSession) RunLoop() error { buf := make([]byte, 128) _, err := session.conn.Read(buf) return err } -func (session *HttpSubSession) Dispose() error { +func (session *BasicHttpSubSession) Dispose() error { return session.conn.Close() } // --------------------------------------------------------------------------------------------------------------------- -func (session *HttpSubSession) WriteHttpResponseHeader(b []byte) { +func (session *BasicHttpSubSession) WriteHttpResponseHeader(b []byte) { if session.IsWebSocket { session.write(UpdateWebSocketHeader(session.WebSocketKey)) } else { @@ -67,7 +65,7 @@ func (session *HttpSubSession) WriteHttpResponseHeader(b []byte) { } } -func (session *HttpSubSession) Write(b []byte) { +func (session *BasicHttpSubSession) Write(b []byte) { if session.IsWebSocket { wsHeader := WsHeader{ Fin: true, @@ -87,7 +85,7 @@ func (session *HttpSubSession) Write(b []byte) { // IObject interface // --------------------------------------------------------------------------------------------------------------------- -func (session *HttpSubSession) UniqueKey() string { +func (session *BasicHttpSubSession) UniqueKey() string { return session.sessionStat.UniqueKey() } @@ -95,15 +93,15 @@ func (session *HttpSubSession) UniqueKey() string { // ISessionUrlContext interface // --------------------------------------------------------------------------------------------------------------------- -func (session *HttpSubSession) Url() string { +func (session *BasicHttpSubSession) Url() string { return session.UrlCtx.Url } -func (session *HttpSubSession) AppName() string { +func (session *BasicHttpSubSession) AppName() string { return session.UrlCtx.PathWithoutLastItem } -func (session *HttpSubSession) StreamName() string { +func (session *BasicHttpSubSession) StreamName() string { var suffix string switch session.SessionType { case SessionTypeFlvSub: @@ -116,27 +114,27 @@ func (session *HttpSubSession) StreamName() string { return strings.TrimSuffix(session.UrlCtx.LastItemOfPath, suffix) } -func (session *HttpSubSession) RawQuery() string { +func (session *BasicHttpSubSession) RawQuery() string { return session.UrlCtx.RawQuery } // ----- ISessionStat -------------------------------------------------------------------------------------------------- -func (session *HttpSubSession) GetStat() StatSession { +func (session *BasicHttpSubSession) GetStat() StatSession { return session.sessionStat.GetStat() } -func (session *HttpSubSession) UpdateStat(intervalSec uint32) { +func (session *BasicHttpSubSession) UpdateStat(intervalSec uint32) { session.sessionStat.UpdateStatWitchConn(session.conn, intervalSec) } -func (session *HttpSubSession) IsAlive() (readAlive, writeAlive bool) { +func (session *BasicHttpSubSession) IsAlive() (readAlive, writeAlive bool) { return session.sessionStat.IsAliveWitchConn(session.conn) } // --------------------------------------------------------------------------------------------------------------------- -func (session *HttpSubSession) write(b []byte) { +func (session *BasicHttpSubSession) write(b []byte) { // TODO(chef) handle write error _, _ = session.conn.Write(b) } diff --git a/pkg/base/http_server.go b/pkg/base/http_server.go index 232e615..21a497d 100644 --- a/pkg/base/http_server.go +++ b/pkg/base/http_server.go @@ -140,6 +140,8 @@ func (s *HttpServerManager) Dispose() error { return nazaerrors.CombineErrors(es...) } +// --------------------------------------------------------------------------------------------------------------------- + // 为传入的`Addr`地址创建http或https监听 // func listen(ctx LocalAddrCtx) (net.Listener, error) { diff --git a/pkg/base/t_http_api.go b/pkg/base/t_http_an__api.go similarity index 97% rename from pkg/base/t_http_api.go rename to pkg/base/t_http_an__api.go index c7f86b0..f480ed6 100644 --- a/pkg/base/t_http_api.go +++ b/pkg/base/t_http_an__api.go @@ -10,8 +10,6 @@ package base // 文档见: https://pengrl.com/lal/#/HTTPAPI -// TODO(chef): refactor 重命名为t_http_an_api.go 202205 - // ----- request ------------------------------------------------------------------------------------------------------- const ( diff --git a/pkg/base/t_http_notify.go b/pkg/base/t_http_an__notify.go similarity index 96% rename from pkg/base/t_http_notify.go rename to pkg/base/t_http_an__notify.go index d8b673d..98feeaf 100644 --- a/pkg/base/t_http_notify.go +++ b/pkg/base/t_http_an__notify.go @@ -8,9 +8,7 @@ package base -// 文档见: https://pengrl.com/p/20101/ - -// TODO(chef): refactor 重命名为t_http_an_notify.go 202205 +// 文档见: https://pengrl.com/lal/#/HTTPNotify type SessionEventCommonInfo struct { ServerId string `json:"server_id"` diff --git a/pkg/base/t_session.go b/pkg/base/t_session.go index 5894370..eb59a48 100644 --- a/pkg/base/t_session.go +++ b/pkg/base/t_session.go @@ -18,7 +18,7 @@ package base // // other: rtmp.ClientSession, (rtmp.ServerSession) // rtsp.BaseInSession, rtsp.BaseOutSession, rtsp.ClientCommandSession, rtsp.ServerCommandSession -// base.HttpSubSession +// base.BasicHttpSubSession // --------------------------------------------------------------------------------------------------------------------- diff --git a/pkg/httpflv/server_sub_session.go b/pkg/httpflv/server_sub_session.go index 5c5784e..e77f40d 100644 --- a/pkg/httpflv/server_sub_session.go +++ b/pkg/httpflv/server_sub_session.go @@ -19,7 +19,7 @@ import ( var flvHttpResponseHeader []byte type SubSession struct { - core *base.HttpSubSession + core *base.BasicHttpSubSession IsFresh bool ShouldWaitVideoKeyFrame bool } @@ -27,7 +27,7 @@ type SubSession struct { func NewSubSession(conn net.Conn, urlCtx base.UrlContext, isWebSocket bool, websocketKey string) *SubSession { uk := base.GenUkFlvSubSession() s := &SubSession{ - core: base.NewHttpSubSession(base.HttpSubSessionOption{ + core: base.NewBasicHttpSubSession(base.BasicHttpSubSessionOption{ Conn: conn, ConnModOption: func(option *connection.Option) { option.WriteChanSize = SubSessionWriteChanSize diff --git a/pkg/httpts/server_sub_session.go b/pkg/httpts/server_sub_session.go index 119b000..7fdb5e5 100644 --- a/pkg/httpts/server_sub_session.go +++ b/pkg/httpts/server_sub_session.go @@ -18,14 +18,14 @@ import ( var tsHttpResponseHeader []byte type SubSession struct { - core *base.HttpSubSession + core *base.BasicHttpSubSession IsFresh bool ShouldWaitBoundary bool } func NewSubSession(conn net.Conn, urlCtx base.UrlContext, isWebSocket bool, websocketKey string) *SubSession { s := &SubSession{ - core: base.NewHttpSubSession(base.HttpSubSessionOption{ + core: base.NewBasicHttpSubSession(base.BasicHttpSubSessionOption{ Conn: conn, ConnModOption: func(option *connection.Option) { option.WriteChanSize = SubSessionWriteChanSize diff --git a/pkg/innertest/iface_impl.go b/pkg/innertest/iface_impl.go index a7ec5e0..ac14f77 100644 --- a/pkg/innertest/iface_impl.go +++ b/pkg/innertest/iface_impl.go @@ -79,7 +79,7 @@ var ( _ base.IServerSessionLifecycle = &httpts.SubSession{} // other - _ base.IServerSessionLifecycle = &base.HttpSubSession{} + _ base.IServerSessionLifecycle = &base.BasicHttpSubSession{} _ base.IServerSessionLifecycle = &rtsp.ServerCommandSession{} ) @@ -98,7 +98,7 @@ var ( _ base.ISessionStat = &httpflv.SubSession{} _ base.ISessionStat = &httpts.SubSession{} // other - _ base.ISessionStat = &base.HttpSubSession{} + _ base.ISessionStat = &base.BasicHttpSubSession{} _ base.ISessionStat = &rtmp.ClientSession{} _ base.ISessionStat = &rtsp.BaseInSession{} _ base.ISessionStat = &rtsp.BaseOutSession{} @@ -120,7 +120,7 @@ var ( _ base.ISessionUrlContext = &httpflv.SubSession{} _ base.ISessionUrlContext = &httpts.SubSession{} // other - _ base.ISessionUrlContext = &base.HttpSubSession{} + _ base.ISessionUrlContext = &base.BasicHttpSubSession{} _ base.ISessionUrlContext = &rtmp.ClientSession{} _ base.ISessionUrlContext = &rtsp.ClientCommandSession{} ) @@ -140,7 +140,7 @@ var ( _ base.IObject = &httpflv.SubSession{} _ base.IObject = &httpts.SubSession{} //// other - _ base.IObject = &base.HttpSubSession{} + _ base.IObject = &base.BasicHttpSubSession{} _ base.IObject = &rtmp.ClientSession{} _ base.IObject = &rtsp.BaseInSession{} _ base.IObject = &rtsp.BaseOutSession{} diff --git a/pkg/logic/group.go b/pkg/logic/group__.go similarity index 99% rename from pkg/logic/group.go rename to pkg/logic/group__.go index 89f6ffa..6ade469 100644 --- a/pkg/logic/group.go +++ b/pkg/logic/group__.go @@ -24,8 +24,6 @@ import ( "github.com/q191201771/lal/pkg/sdp" ) -// TODO(chef): [refactor] 文件名修改为group__.go 202205 - type IGroupObserver interface { CleanupHlsIfNeeded(appName string, streamName string, path string) diff --git a/pkg/logic/server_manager.go b/pkg/logic/server_manager__.go similarity index 100% rename from pkg/logic/server_manager.go rename to pkg/logic/server_manager__.go