Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 58cb86af97 | |||
| 11900eeecd | |||
| 4f9ef33ab1 |
@@ -4,10 +4,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
basket "git.ego.freeddns.org/egommerce/api-entities/basket/dto"
|
basket "git.ego.freeddns.org/egommerce/api-entities/basket/dto"
|
||||||
|
cnf "git.ego.freeddns.org/egommerce/go-api-pkg/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewBasketAPI() *BasketAPI {
|
func NewBasketAPI() *BasketAPI {
|
||||||
return &BasketAPI{NewHttpClient()}
|
return &BasketAPI{NewHttpClient(cnf.GetEnv("API_REST_BASKET", "basket-svc"))}
|
||||||
}
|
}
|
||||||
|
|
||||||
type BasketAPI struct {
|
type BasketAPI struct {
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -11,12 +13,13 @@ type HttpClient struct {
|
|||||||
userAgent string
|
userAgent string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHttpClient(apiURL string) *HttpClient {
|
func NewHttpClient(baseURL string) *HttpClient {
|
||||||
return &HttpClient{baseURL: apiURL, userAgent: "internal-http-client"}
|
return &HttpClient{baseURL: baseURL, userAgent: "internal-http-client"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HttpClient) SendGet(api, url string, data, out any) error {
|
func (c *HttpClient) SendGet(url string, data, out any) error {
|
||||||
res, err := c.sendRequest(api, url, http.MethodGet, data)
|
fmt.Printf("Sending req to: %s%s\n", c.baseURL, url)
|
||||||
|
res, err := c.sendRequest(c.baseURL, url, http.MethodGet, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -30,8 +33,8 @@ func (c *HttpClient) SendGet(api, url string, data, out any) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HttpClient) SendPost(api, url string, data, out any) (any, error) {
|
func (c *HttpClient) SendPost(url string, data, out any) (any, error) {
|
||||||
res, err := c.sendRequest(api, url, http.MethodPost, data)
|
res, err := c.sendRequest(c.baseURL, url, http.MethodPost, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -45,9 +48,15 @@ func (c *HttpClient) SendPost(api, url string, data, out any) (any, error) {
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HttpClient) sendRequest(api, url, method string, data any) (*http.Response, error) {
|
func (c *HttpClient) sendRequest(baseURL, actionURL, method string, data any) (*http.Response, error) {
|
||||||
apiUrl := api + url // FIXME
|
apiUrl := baseURL + actionURL
|
||||||
client := &http.Client{}
|
|
||||||
|
tr := &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // FIXME dev mode
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create an HTTP client with the custom transport
|
||||||
|
client := &http.Client{Transport: tr} // FIXME dev mode
|
||||||
|
|
||||||
json, err := json.Marshal(&data)
|
json, err := json.Marshal(&data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
pricing "git.ego.freeddns.org/egommerce/api-entities/pricing/dto"
|
pricing "git.ego.freeddns.org/egommerce/api-entities/pricing/dto"
|
||||||
|
cnf "git.ego.freeddns.org/egommerce/go-api-pkg/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewPricingAPI() *PricingAPI {
|
func NewPricingAPI() *PricingAPI {
|
||||||
return &PricingAPI{NewHttpClient()}
|
return &PricingAPI{NewHttpClient(cnf.GetEnv("API_REST_PRICING", "pricing-svc"))}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PricingAPI struct {
|
type PricingAPI struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user