package
0.0.0-20211113143533-446cb24580d7
Repository: https://github.com/jlzan1314/go-toolkit.git
Documentation: pkg.go.dev
# README
Next
该模块实现了与php-fpm进程通信的功能,将http请求转发给php-fpm进程处理。
// CreateHandler 创建服务处理器
func CreateHandler(params *Config, network, address string) http.Handler {
fpmAddr := address
if network == "unix" {
fpmAddr = fmt.Sprintf("%s:%s", network, address)
}
rootDir := filepath.Dir(params.EndpointFile)
conf := next.Config{
EndpointFile: params.EndpointFile,
ServerIP: params.ServiceIP,
ServerPort: params.ServicePort,
SoftwareName: "php-server",
SoftwareVersion: "0.0.1",
Rules: []next.Rule{next.NewPHPRule(rootDir, []string{fpmAddr})},
RequestLogHandler: func(rc *next.RequestContext) {
var message bytes.Buffer
if err := params.AccessLogTemplate.Execute(&message, rc); err != nil {
log.Module("server").Errorf("invalid log format: %s", err.Error())
} else {
if params.Debug {
log.Module("server.request").
WithContext(rc.ToMap()).Debugf(message.String())
} else {
log.Module("server.request").Debugf(message.String())
}
}
},
}
return next.CreateHttpHandler(&conf)
}
http.HandleFunc("/", CreateHandler(config, network, address).ServeHTTP)
srv := &http.Server{Handler: http.DefaultServeMux}
go func() {
if err := srv.Serve(listener); err != nil {
log.Debugf("The http server has stopped: %v", err)
}
}()
该模块大部分代码是从Caddy中提取出来的,参考 https://github.com/mholt/caddy/tree/master/caddyhttp/fastcgi
# Functions
CreateHTTPHandler create a http handler for request processing.
Dial connects to the fcgi responder at the specified network address, using default net.Dialer.
DialContext is like Dial but passes ctx to dialer.Dial.
DialWithDialerContext connects to the fcgi responder at the specified network address, using custom net.Dialer and a context.
IndexFile looks for a file in /root/fpath/indexFile for each string in indexFiles.
NewPHPRule create a rule for php.
NewResponseWriter create a new ResposneWriter wrapper.
# Constants
AbortRequest is the abort request flag.
Authorizer is the authorizer flag.
BeginRequest is the begin request flag.
CantMultiplexConns is the multiplexed connections flag.
Data is the data flag.
EndRequest is the end request flag.
FCGIHeaderLen describes header length.
FCGIKeepConn describes keep connection mode.
FCGIListenSockFileno describes listen socket file number.
FCGINullRequestID describes the null request ID.
Filter is the filter flag.
GetValues is the get values flag.
GetValuesResult is the get values result flag.
MaxConns is the maximum connections flag.
MaxRequests is the maximum requests flag.
MaxType is the maximum type flag.
MultiplexConns is the multiplex connections flag.
Overloaded is the overloaded flag.
Params is the parameters flag.
RequestComplete is the completed request flag.
Responder is the responder flag.
Stderr is the standard error flag.
Stdin is the standard input flag.
Stdout is the standard output flag.
UnknownRole is the unknown role flag.
UnknownType is the unknown type flag.
Version1 describes the version.
# Variables
ErrIndexMissingSplit describes an index configuration error.
# Structs
Config config object for create a handler.
FCGIClient implements a FastCGI client, which is a standard for interfacing external applications with Web servers.
Handler is a middleware type that can handle requests as a FastCGI client.
HTTPHandler http request handler wrapper.
RequestContext request context information.
ResponseWriter is a response wrapper.
Rule represents a FastCGI handling rule.
# Type aliases
No description provided by the author
LogError is a non fatal error that allows requests to go through.
RequestLogHandler request log handler func.