From fb625f9cbf8f7616ba972de33163c9893b6bf942 Mon Sep 17 00:00:00 2001 From: Javad Date: Wed, 12 Oct 2022 08:33:48 +0330 Subject: [PATCH] improved forker interfaces - separated child methods - update name initializer echo framework --- _example/echo/main.go | 2 +- forker.go | 10 +++++----- go.mod | 2 -- go.sum | 4 ---- interface.go | 16 ++++++---------- 5 files changed, 12 insertions(+), 22 deletions(-) diff --git a/_example/echo/main.go b/_example/echo/main.go index 5ec0c30..aa19407 100644 --- a/_example/echo/main.go +++ b/_example/echo/main.go @@ -11,7 +11,7 @@ func main() { e.GET("/", Greeting) - e.Logger.Fatal(f.Start(":8080")) + e.Logger.Fatal(f.StartEcho(":8080")) } func Greeting(c echo.Context) error { diff --git a/forker.go b/forker.go index 5df4331..33261e7 100644 --- a/forker.go +++ b/forker.go @@ -21,9 +21,6 @@ const ( type Fork struct { echo *echo.Echo - Network Network // Network is net type tcp4, tcp, tcp6, udp, udp4, udp6 - ReusePort bool // ReusePort use for windows support child process base on system call - serveFunc func(ln net.Listener) error serveTLSFunc func(ln net.Listener, certFile, keyFile string) error @@ -32,6 +29,9 @@ type Fork struct { files []*os.File childsPid []int + + Network Network // Network is net type tcp4, tcp, tcp6, udp, udp4, udp6 + ReusePort bool // ReusePort use for windows support child process base on system call } type processSignal struct { @@ -80,8 +80,8 @@ func NewEchoForker(opts ...Option) EchoForker { return forker } -// Start listener echo -func (f *Fork) Start(address string) error { +// StartEcho listener echo +func (f *Fork) StartEcho(address string) error { if isChild() { ln, err := f.listen(address) if err != nil { diff --git a/go.mod b/go.mod index 33d944e..f46daba 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( ) require ( - github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/labstack/gommon v0.3.1 // indirect github.com/mattn/go-colorable v0.1.11 // indirect github.com/mattn/go-isatty v0.0.14 // indirect @@ -19,5 +18,4 @@ require ( golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875 // indirect golang.org/x/text v0.3.7 // indirect - golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect ) diff --git a/go.sum b/go.sum index 39b1f80..4938f12 100644 --- a/go.sum +++ b/go.sum @@ -3,8 +3,6 @@ github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHG github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= -github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/klauspost/compress v1.15.0 h1:xqfchp4whNFxn5A4XFyyYtitiWI8Hy5EW59jEwcyL6U= github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/labstack/echo/v4 v4.9.0 h1:wPOF1CE6gvt/kmbMR4dGzWvHMPT+sAEUJOwOTtvITVY= @@ -48,8 +46,6 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/time v0.0.0-20220922220347-f3bd1da661af h1:Yx9k8YCG3dvF87UAn2tu2HQLf2dt/eR1bXxpLMWeH+Y= -golang.org/x/time v0.0.0-20220922220347-f3bd1da661af/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/interface.go b/interface.go index 598878b..416b89e 100644 --- a/interface.go +++ b/interface.go @@ -2,25 +2,21 @@ package forker import ( "github.com/labstack/echo/v4" - "net" - "os/exec" ) type Forker interface { + child ListenAndServe(address string) error ListenAndServeTLS(address, certFile, keyFile string) error - NumOfChild() int - ChildPids() []int - - forker(address string) (err error) - listen(address string) (net.Listener, error) - setTCPListenerFiles(address string) error - doCmd() (*exec.Cmd, error) } type EchoForker interface { - Start(address string) error + child + StartEcho(address string) error GetEcho() *echo.Echo +} + +type child interface { NumOfChild() int ChildPids() []int }