Skip to content

Commit

Permalink
feat: add http client
Browse files Browse the repository at this point in the history
  • Loading branch information
mgjules committed Apr 11, 2022
1 parent 8f0ba08 commit c8e78ae
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/dgraph-io/ristretto v0.1.0
github.com/gin-contrib/zap v0.0.2
github.com/gin-gonic/gin v1.7.7
github.com/go-resty/resty/v2 v2.7.0
github.com/google/uuid v1.2.0
github.com/iancoleman/strcase v0.2.0
github.com/imdario/mergo v0.3.12
Expand Down Expand Up @@ -62,7 +63,7 @@ require (
go.uber.org/dig v1.14.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/crypto v0.0.0-20210317152858-513c2a44f670 // indirect
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect
golang.org/x/net v0.0.0-20211029224645-99673261e6eb // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
golang.org/x/sys v0.0.0-20220329152356-43be30ef3008 // indirect
golang.org/x/text v0.3.7 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD87
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -222,6 +224,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d h1:20cMwl2fHAzkJMEA+8J4JgqBQcQGzbisXo31MIeenXI=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb h1:pirldcYWx7rx7kE5r+9WsOXPXK0+WH5+uZ7uPmJ44uM=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
25 changes: 25 additions & 0 deletions http/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package http

import (
"github.com/JulesMike/spoty/config"
"github.com/JulesMike/spoty/json"
"github.com/go-resty/resty/v2"
)

// Client is a simple wrapper around resty.Client.
type Client struct {
*resty.Client
}

// NewClient creates a new Client.
func NewClient(cfg *config.Config) *Client {
client := resty.New()
client.JSONMarshal = json.Marshal
client.JSONUnmarshal = json.Unmarshal
if !cfg.Prod {
client.EnableTrace()
client.SetDebug(true)
}

return &Client{client}
}
7 changes: 4 additions & 3 deletions http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ const (
_readHeaderTimeout = 2 * time.Second
)

// Module exported for initialising a new Server.
// Module exported for initialising a new Server and Client.
var Module = fx.Options(
fx.Provide(New),
fx.Provide(NewServer),
fx.Provide(NewClient),
)

// Server is the main HTTP server.
Expand All @@ -43,7 +44,7 @@ type Server struct {
}

// New creates a new Server.
func New(
func NewServer(
cfg *config.Config,
logger *logger.Logger,
tracer *tracer.Tracer,
Expand Down

0 comments on commit c8e78ae

Please sign in to comment.