Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve ignore and up websocket 1.5.0 #1684

Merged
merged 2 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pkg/
bin/
cbuild
**/.DS_Store
.vscode/
.test/
main
gf
4 changes: 2 additions & 2 deletions cmd/gf/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=
github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/fsnotify/fsnotify v1.5.1
github.com/go-redis/redis/v8 v8.11.4
github.com/go-sql-driver/mysql v1.6.0
github.com/gorilla/websocket v1.4.2
github.com/gorilla/websocket v1.5.0
github.com/grokify/html-strip-tags-go v0.0.1
github.com/olekukonko/tablewriter v0.0.5
go.opentelemetry.io/otel v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=
github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
Expand Down
24 changes: 12 additions & 12 deletions net/ghttp/ghttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"reflect"
"time"

"github.com/gogf/gf/v2/net/gsvc"
"github.com/gorilla/websocket"

"github.com/gogf/gf/v2/container/gmap"
"github.com/gogf/gf/v2/container/gtype"
"github.com/gogf/gf/v2/net/gsvc"
"github.com/gogf/gf/v2/os/gcache"
"github.com/gogf/gf/v2/os/gsession"
"github.com/gogf/gf/v2/protocol/goai"
Expand All @@ -31,7 +31,7 @@ type (
servers []*gracefulServer // Underlying http.Server array.
serverCount *gtype.Int // Underlying http.Server count.
closeChan chan struct{} // Used for underlying server closing event notification.
serveTree map[string]interface{} // The route map tree.
serveTree map[string]interface{} // The route maps tree.
serveCache *gcache.Cache // Server caches for internal usage.
routesMap map[string][]registeredRouteItem // Route map mainly for route dumps and repeated route checks.
statusHandlerMap map[string][]HandlerFunc // Custom status handler map.
Expand Down Expand Up @@ -70,8 +70,8 @@ type (
// handlerFuncInfo contains the HandlerFunc address and its reflection type.
handlerFuncInfo struct {
Func HandlerFunc // Handler function address.
Type reflect.Type // Reflect type information for current handler, which is used for extension of handler feature.
Value reflect.Value // Reflect value information for current handler, which is used for extension of handler feature.
Type reflect.Type // Reflect type information for current handler, which is used for extensions of the handler feature.
Value reflect.Value // Reflect value information for current handler, which is used for extensions of the handler feature.
}

// handlerItem is the registered handler for route handling,
Expand All @@ -84,7 +84,7 @@ type (
InitFunc HandlerFunc // Initialization function when request enters the object (only available for object register type).
ShutFunc HandlerFunc // Shutdown function when request leaves out the object (only available for object register type).
Middleware []HandlerFunc // Bound middleware array.
HookName string // Hook type name, only available for hook type.
HookName string // Hook type name, only available for the hook type.
Router *Router // Router object.
Source string // Registering source file `path:line`.
}
Expand Down Expand Up @@ -141,15 +141,15 @@ const (
)

var (
// methodsMap stores all supported HTTP method,
// it is used for quick HTTP method searching using map.
// methodsMap stores all supported HTTP method.
// It is used for quick HTTP method searching using map.
methodsMap = make(map[string]struct{})

// serverMapping stores more than one server instances for current process.
// serverMapping stores more than one server instances for current processes.
// The key is the name of the server, and the value is its instance.
serverMapping = gmap.NewStrAnyMap(true)

// serverRunning marks the running server count.
// serverRunning marks the running server counts.
// If there is no successful server running or all servers' shutdown, this value is 0.
serverRunning = gtype.NewInt()

Expand All @@ -160,17 +160,17 @@ var (
return true
},
}
// allDoneChan is the event for all server have done its serving and exit.
// allDoneChan is the event for all servers have done its serving and exit.
// It is used for process blocking purpose.
allDoneChan = make(chan struct{}, 1000)

// serverProcessInitialized is used for lazy initialization for server.
// The process can only be initialized once.
serverProcessInitialized = gtype.NewBool()

// gracefulEnabled is used for graceful reload feature, which is false in default.
// gracefulEnabled is used for a graceful reload feature, which is false in default.
gracefulEnabled = false

// defaultValueTags is the struct tag names for default value storing.
// defaultValueTags are the struct tag names for default value storing.
defaultValueTags = []string{"d", "default"}
)
2 changes: 1 addition & 1 deletion net/ghttp/ghttp_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// BuildParams builds the request string for the http client. The `params` can be type of:
// string/[]byte/map/struct/*struct.
//
// The optional parameter `noUrlEncode` specifies whether ignore the url encoding for the data.
// The optional parameter `noUrlEncode` specifies whether to ignore the url encoding for the data.
func BuildParams(params interface{}, noUrlEncode ...bool) (encodedParamStr string) {
return httputil.BuildParams(params, noUrlEncode...)
}
Expand Down
1 change: 1 addition & 0 deletions net/ghttp/ghttp_middleware_handler_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/gogf/gf/v2/internal/intlog"
)

// DefaultHandlerResponse is the default implementation of HandlerResponse.
type DefaultHandlerResponse struct {
Code int `json:"code" dc:"Error code"`
Message string `json:"message" dc:"Error message"`
Expand Down
4 changes: 2 additions & 2 deletions net/ghttp/ghttp_middleware_tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"fmt"
"io/ioutil"

"github.com/gogf/gf/v2/os/gctx"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
Expand All @@ -22,6 +21,7 @@ import (
"github.com/gogf/gf/v2/internal/httputil"
"github.com/gogf/gf/v2/internal/utils"
"github.com/gogf/gf/v2/net/gtrace"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
)
Expand Down Expand Up @@ -73,7 +73,7 @@ func internalMiddlewareServerTracing(r *Request) {
// Inject tracing context.
r.SetCtx(ctx)

// If it is now using default trace provider, it then does no complex tracing jobs.
// If it is now using a default trace provider, it then does no complex tracing jobs.
if gtrace.IsUsingDefaultProvider() {
r.Middleware.Next()
return
Expand Down
8 changes: 4 additions & 4 deletions net/ghttp/ghttp_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Request struct {
Response *Response // Corresponding Response of this request.
Router *Router // Matched Router for this request. Note that it's not available in HOOK handler.
EnterTime int64 // Request starting time in microseconds.
LeaveTime int64 // Request ending time in microseconds.
LeaveTime int64 // Request to end time in microseconds.
Middleware *middleware // Middleware manager.
StaticFile *staticFile // Static file object for static file serving.

Expand All @@ -49,10 +49,10 @@ type Request struct {
parsedBody bool // A bool marking whether the request body parsed.
parsedForm bool // A bool marking whether request Form parsed for HTTP method PUT, POST, PATCH.
paramsMap map[string]interface{} // Custom parameters map.
routerMap map[string]string // Router parameters map, which might be nil if there're no router parameters.
routerMap map[string]string // Router parameters map, which might be nil if there are no router parameters.
queryMap map[string]interface{} // Query parameters map, which is nil if there's no query string.
formMap map[string]interface{} // Form parameters map, which is nil if there's no form data from client.
bodyMap map[string]interface{} // Body parameters map, which might be nil if there're no body content.
formMap map[string]interface{} // Form parameters map, which is nil if there's no form of data from the client.
bodyMap map[string]interface{} // Body parameters map, which might be nil if their nobody content.
error error // Current executing error of the request.
exitAll bool // A bool marking whether current request is exited.
parsedHost string // The parsed host name for current host used by GetHost function.
Expand Down
2 changes: 1 addition & 1 deletion net/ghttp/ghttp_request_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/gogf/gf/v2/encoding/gbase64"
)

// BasicAuth enables the http basic authentication feature with given passport and password
// BasicAuth enables the http basic authentication feature with a given passport and password
// and asks client for authentication. It returns true if authentication success, else returns
// false if failure.
func (r *Request) BasicAuth(user, pass string, tips ...string) bool {
Expand Down
4 changes: 2 additions & 2 deletions net/ghttp/ghttp_request_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (m *middleware) Next() {
var item *handlerParsedItem
var loop = true
for loop {
// Check whether the request is exited.
// Check whether the request is excited.
if m.request.IsExited() || m.handlerIndex >= len(m.request.handlers) {
break
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func (m *middleware) Next() {
loop = false
})
}
// Check the http status code after all handler and middleware done.
// Check the http status code after all handlers and middleware done.
if m.request.IsExited() || m.handlerIndex >= len(m.request.handlers) {
if m.request.Response.Status == 0 {
if m.request.Middleware.served {
Expand Down
2 changes: 1 addition & 1 deletion net/ghttp/ghttp_request_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (r *Request) parseForm() {
}
}

// GetMultipartForm parses and returns the form as multipart form.
// GetMultipartForm parses and returns the form as multipart forms.
func (r *Request) GetMultipartForm() *multipart.Form {
r.parseForm()
return r.MultipartForm
Expand Down
4 changes: 2 additions & 2 deletions net/ghttp/ghttp_request_param_ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (r *Request) SetCtx(ctx context.Context) {
r.context = ctx
}

// GetCtxVar retrieves and returns a Var with given key name.
// GetCtxVar retrieves and returns a Var with a given key name.
// The optional parameter `def` specifies the default value of the Var if given `key`
// does not exist in the context.
func (r *Request) GetCtxVar(key interface{}, def ...interface{}) *gvar.Var {
Expand All @@ -59,7 +59,7 @@ func (r *Request) GetCtxVar(key interface{}, def ...interface{}) *gvar.Var {
return gvar.New(value)
}

// SetCtxVar sets custom parameter to context with key-value pair.
// SetCtxVar sets custom parameter to context with key-value pairs.
func (r *Request) SetCtxVar(key interface{}, value interface{}) {
r.context = context.WithValue(r.Context(), key, value)
}
2 changes: 1 addition & 1 deletion net/ghttp/ghttp_request_param_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type UploadFile struct {
ctx context.Context
}

// UploadFiles is array type for *UploadFile.
// UploadFiles is an array type of *UploadFile.
type UploadFiles []*UploadFile

// Save saves the single uploading file to directory path and returns the saved file name.
Expand Down
2 changes: 1 addition & 1 deletion net/ghttp/ghttp_request_param_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/gogf/gf/v2/util/gconv"
)

// SetForm sets custom form value with key-value pair.
// SetForm sets custom form value with key-value pairs.
func (r *Request) SetForm(key string, value interface{}) {
r.parseForm()
if r.formMap == nil {
Expand Down
2 changes: 1 addition & 1 deletion net/ghttp/ghttp_request_param_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// GetPage creates and returns the pagination object for given `totalSize` and `pageSize`.
// NOTE THAT the page parameter name from client is constantly defined as gpage.DefaultPageName
// NOTE THAT the page parameter name from clients is constantly defined as gpage.DefaultPageName
// for simplification and convenience.
func (r *Request) GetPage(totalSize, pageSize int) *gpage.Page {
// It must have Router object attribute.
Expand Down
6 changes: 3 additions & 3 deletions net/ghttp/ghttp_request_param_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ package ghttp

import "github.com/gogf/gf/v2/container/gvar"

// SetParam sets custom parameter with key-value pair.
// SetParam sets custom parameter with key-value pairs.
func (r *Request) SetParam(key string, value interface{}) {
if r.paramsMap == nil {
r.paramsMap = make(map[string]interface{})
}
r.paramsMap[key] = value
}

// SetParamMap sets custom parameter with key-value pair map.
// SetParamMap sets custom parameter with key-value pair maps.
func (r *Request) SetParamMap(data map[string]interface{}) {
if r.paramsMap == nil {
r.paramsMap = make(map[string]interface{})
Expand All @@ -26,7 +26,7 @@ func (r *Request) SetParamMap(data map[string]interface{}) {
}
}

// GetParam returns custom parameter with given name `key`.
// GetParam returns custom parameter with a given name `key`.
// It returns `def` if `key` does not exist.
// It returns nil if `def` is not passed.
func (r *Request) GetParam(key string, def ...interface{}) *gvar.Var {
Expand Down
18 changes: 9 additions & 9 deletions net/ghttp/ghttp_request_param_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/gogf/gf/v2/util/gconv"
)

// SetQuery sets custom query value with key-value pair.
// SetQuery sets custom query value with key-value pairs.
func (r *Request) SetQuery(key string, value interface{}) {
r.parseQuery()
if r.queryMap == nil {
Expand All @@ -20,7 +20,7 @@ func (r *Request) SetQuery(key string, value interface{}) {
r.queryMap[key] = value
}

// GetQuery retrieves and returns parameter with given name `key` from query string
// GetQuery retrieves and return parameter with the given name `key` from query string
// and request body. It returns `def` if `key` does not exist in the query and `def` is given,
// or else it returns nil.
//
Expand All @@ -47,8 +47,8 @@ func (r *Request) GetQuery(key string, def ...interface{}) *gvar.Var {
return nil
}

// GetQueryMap retrieves and returns all parameters passed from client using HTTP GET method
// as map. The parameter `kvMap` specifies the keys retrieving from client parameters,
// GetQueryMap retrieves and returns all parameters passed from the client using HTTP GET method
// as the map. The parameter `kvMap` specifies the keys retrieving from client parameters,
// the associated values are the default values if the client does not pass.
//
// Note that if there are multiple parameters with the same name, the parameters are retrieved and overwrote
Expand Down Expand Up @@ -94,8 +94,8 @@ func (r *Request) GetQueryMap(kvMap ...map[string]interface{}) map[string]interf
return m
}

// GetQueryMapStrStr retrieves and returns all parameters passed from client using HTTP GET method
// as map[string]string. The parameter `kvMap` specifies the keys
// GetQueryMapStrStr retrieves and returns all parameters passed from the client using the HTTP GET method as a
// map[string]string. The parameter `kvMap` specifies the keys
// retrieving from client parameters, the associated values are the default values if the client
// does not pass.
func (r *Request) GetQueryMapStrStr(kvMap ...map[string]interface{}) map[string]string {
Expand All @@ -110,7 +110,7 @@ func (r *Request) GetQueryMapStrStr(kvMap ...map[string]interface{}) map[string]
return nil
}

// GetQueryMapStrVar retrieves and returns all parameters passed from client using HTTP GET method
// GetQueryMapStrVar retrieves and returns all parameters passed from the client using the HTTP GET method
// as map[string]*gvar.Var. The parameter `kvMap` specifies the keys
// retrieving from client parameters, the associated values are the default values if the client
// does not pass.
Expand All @@ -126,8 +126,8 @@ func (r *Request) GetQueryMapStrVar(kvMap ...map[string]interface{}) map[string]
return nil
}

// GetQueryStruct retrieves all parameters passed from client using HTTP GET method
// and converts them to given struct object. Note that the parameter `pointer` is a pointer
// GetQueryStruct retrieves all parameters passed from the client using the HTTP GET method
// and converts them to a given struct object. Note that the parameter `pointer` is a pointer
// to the struct object. The optional parameter `mapping` is used to specify the key to
// attribute mapping.
func (r *Request) GetQueryStruct(pointer interface{}, mapping ...map[string]string) error {
Expand Down
Loading