Skip to content

Commit

Permalink
improved forker interfaces
Browse files Browse the repository at this point in the history
- separated child methods
- update name initializer echo framework
  • Loading branch information
Ja7ad committed Oct 12, 2022
1 parent cf8bb2d commit fb625f9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 22 deletions.
2 changes: 1 addition & 1 deletion _example/echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions forker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
16 changes: 6 additions & 10 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit fb625f9

Please sign in to comment.