Compare commits

..

3 Commits

Author SHA1 Message Date
58cb86af97 Added baseURL prefix 2025-11-16 14:22:05 +01:00
11900eeecd Fixed req with insecured tls 2025-11-15 21:16:34 +01:00
4f9ef33ab1 Added baseURL for rest api clients 2025-11-15 20:57:30 +01:00
3 changed files with 22 additions and 11 deletions

View File

@@ -4,10 +4,11 @@ import (
"fmt"
basket "git.ego.freeddns.org/egommerce/api-entities/basket/dto"
cnf "git.ego.freeddns.org/egommerce/go-api-pkg/config"
)
func NewBasketAPI() *BasketAPI {
return &BasketAPI{NewHttpClient()}
return &BasketAPI{NewHttpClient(cnf.GetEnv("API_REST_BASKET", "basket-svc"))}
}
type BasketAPI struct {

View File

@@ -2,7 +2,9 @@ package api
import (
"bytes"
"crypto/tls"
"encoding/json"
"fmt"
"net/http"
)
@@ -11,12 +13,13 @@ type HttpClient struct {
userAgent string
}
func NewHttpClient(apiURL string) *HttpClient {
return &HttpClient{baseURL: apiURL, userAgent: "internal-http-client"}
func NewHttpClient(baseURL string) *HttpClient {
return &HttpClient{baseURL: baseURL, userAgent: "internal-http-client"}
}
func (c *HttpClient) SendGet(api, url string, data, out any) error {
res, err := c.sendRequest(api, url, http.MethodGet, data)
func (c *HttpClient) SendGet(url string, data, out any) error {
fmt.Printf("Sending req to: %s%s\n", c.baseURL, url)
res, err := c.sendRequest(c.baseURL, url, http.MethodGet, data)
if err != nil {
return err
}
@@ -30,8 +33,8 @@ func (c *HttpClient) SendGet(api, url string, data, out any) error {
return nil
}
func (c *HttpClient) SendPost(api, url string, data, out any) (any, error) {
res, err := c.sendRequest(api, url, http.MethodPost, data)
func (c *HttpClient) SendPost(url string, data, out any) (any, error) {
res, err := c.sendRequest(c.baseURL, url, http.MethodPost, data)
if err != nil {
return nil, err
}
@@ -45,9 +48,15 @@ func (c *HttpClient) SendPost(api, url string, data, out any) (any, error) {
return out, nil
}
func (c *HttpClient) sendRequest(api, url, method string, data any) (*http.Response, error) {
apiUrl := api + url // FIXME
client := &http.Client{}
func (c *HttpClient) sendRequest(baseURL, actionURL, method string, data any) (*http.Response, error) {
apiUrl := baseURL + actionURL
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)
if err != nil {

View File

@@ -4,10 +4,11 @@ import (
"fmt"
pricing "git.ego.freeddns.org/egommerce/api-entities/pricing/dto"
cnf "git.ego.freeddns.org/egommerce/go-api-pkg/config"
)
func NewPricingAPI() *PricingAPI {
return &PricingAPI{NewHttpClient()}
return &PricingAPI{NewHttpClient(cnf.GetEnv("API_REST_PRICING", "pricing-svc"))}
}
type PricingAPI struct {