Skip to content

Commit

Permalink
up: update server and add new echo server
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Mar 19, 2023
1 parent e38d70e commit 1d55805
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 20 deletions.
2 changes: 1 addition & 1 deletion binding/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func Bind(r *http.Request, obj any) error {
return Auto(r, obj)
}

// Auto bind request data to an struct ptr
// Auto bind request data to a ptr value
//
// body, err := ioutil.ReadAll(c.Request().Body)
// if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/gookit/color v1.5.2
github.com/gookit/goutil v0.6.6
github.com/gookit/goutil v0.6.7
github.com/gookit/validate v1.4.6
github.com/gorilla/websocket v1.5.0
github.com/monoculum/formam v3.5.5+incompatible
Expand All @@ -13,6 +13,6 @@ require (
require (
github.com/gookit/filter v1.1.4 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
)
14 changes: 7 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ github.com/gookit/filter v1.1.4 h1:SXd6PEumiP/0jtF2crQRaz1wmKwHbW9xg5Ds6/ZP16w=
github.com/gookit/filter v1.1.4/go.mod h1:0CEPQvudso375RitQf9X8HerUg9cz8N7c/yn6b1RMzM=
github.com/gookit/goutil v0.5.12/go.mod h1:6vhWm/bSYXGE8poqFbFz6IGM7jV2r6qVhyK567SX/AI=
github.com/gookit/goutil v0.5.15/go.mod h1:ozPE16eJS9f89aVbVk05ocEJsia3KPrYUqPTs8GvUTw=
github.com/gookit/goutil v0.6.6 h1:XdvnPocHpKDXA+eykfc/F846Y1V2Vyo3+cV8rfliG90=
github.com/gookit/goutil v0.6.6/go.mod h1:D++7kbQd/6vECyYTxB5tq6AKDIG9ZYwZNhubWJvN9dw=
github.com/gookit/goutil v0.6.7 h1:Sz0y5eslPZ8M2lUhRaSMnwEeX5nb9z7SoCsw0ZbMwe4=
github.com/gookit/goutil v0.6.7/go.mod h1:ti+JpLBGSN83ga6SSZa6uozhntToWSzOPm2z1hvpQSc=
github.com/gookit/validate v1.4.6 h1:Ix8NRy2+6z4YGHWXgZL9+emy9wRI2GWyhW2smPcIlSU=
github.com/gookit/validate v1.4.6/go.mod h1:1rjeYaYlMK/8od4oge5C+Gt/3DnHkXymLPda7+3urC8=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
Expand Down Expand Up @@ -48,19 +48,19 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
Expand Down
8 changes: 0 additions & 8 deletions server.go

This file was deleted.

33 changes: 33 additions & 0 deletions server/echo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package server

import (
"github.com/gookit/rux"
"github.com/gookit/rux/render"
)

// NewEchoServer instance
func NewEchoServer() *Server {
s := &Server{
Router: *rux.New(),
}

s.Any("/{all}", func(c *rux.Context) {
bs, err := c.RawBodyData()
if err != nil {
c.AbortThen().AddError(err)
return
}

data := rux.M{
"headers": c.Req.Header,
"uri": c.Req.RequestURI,
"query": c.QueryValues(),
"body": string(bs),
}

// c.JSON(200, data)
c.Respond(200, data, render.NewJSONIndented())
})

return s
}
19 changes: 19 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package server

import (
"github.com/gookit/rux"
)

// Server struct
type Server struct {
rux.Router
// server start error
err error
Host string
Port int
}

// MustRun server
func (s *Server) MustRun(addr string) {
s.Listen(addr)
}
3 changes: 2 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func simpleFmtPath(path string) string {
if path == "" {
return "/"
}

return "/" + strings.TrimLeft(path, "/")
}

Expand Down Expand Up @@ -84,6 +83,8 @@ func resolveAddress(addr []string) (fullAddr string) {
}

return ip + ":" + port
case 2:
return addr[0] + ":" + addr[1]
default:
panic("too much parameters")
}
Expand Down

0 comments on commit 1d55805

Please sign in to comment.