package services import ( "bytes" "context" "encoding/json" "fmt" "io" "net/http" "pkg.jojmatic.com/root/rpaas-core-service/pkg/models" ) type BranchService interface { RegisterBranch(endpoint string, body *models.BranchRegisterBody) (map[string]interface{}, error) } type BranchServiceImpl struct { ctx context.Context } func NewBranchService(ctx context.Context) *BranchServiceImpl { return &BranchServiceImpl{ ctx: ctx, } } func (bc *BranchServiceImpl) RegisterBranch(endpoint string, body *models.BranchRegisterBody) (map[string]interface{}, error) { url := endpoint + "v1/branch/register" branchInfo, err := json.Marshal(body) resp, err := http.Post(url, "application/json", bytes.NewBuffer(branchInfo)) if err != nil { return nil, err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("register company failed, status code: %d", resp.StatusCode) } var datajson map[string]interface{} data, _ := io.ReadAll(resp.Body) if err := json.Unmarshal(data, &datajson); err != nil { return nil, err } return datajson, err }