clear general tool

This commit is contained in:
2025-08-28 18:03:38 +07:00
parent f060a01b98
commit af9d04de07
22 changed files with 5349 additions and 2154 deletions

View File

@@ -22,8 +22,8 @@ type VClaimService interface {
Post(ctx context.Context, endpoint string, payload interface{}, result interface{}) error
Put(ctx context.Context, endpoint string, payload interface{}, result interface{}) error
Delete(ctx context.Context, endpoint string, result interface{}) error
GetRawResponse(ctx context.Context, endpoint string) (*ResponDTO, error)
PostRawResponse(ctx context.Context, endpoint string, payload interface{}) (*ResponDTO, error)
GetRawResponse(ctx context.Context, endpoint string) (*ResponDTOVclaim, error)
PostRawResponse(ctx context.Context, endpoint string, payload interface{}) (*ResponDTOVclaim, error)
}
// Service struct for VClaim service
@@ -33,7 +33,7 @@ type Service struct {
}
// Response structures
type ResponMentahDTO struct {
type ResponMentahDTOVclaim struct {
MetaData struct {
Code string `json:"code"`
Message string `json:"message"`
@@ -41,7 +41,7 @@ type ResponMentahDTO struct {
Response string `json:"response"`
}
type ResponDTO struct {
type ResponDTOVclaim struct {
MetaData struct {
Code string `json:"code"`
Message string `json:"message"`
@@ -133,7 +133,7 @@ func (s *Service) prepareRequest(ctx context.Context, method, endpoint string, b
}
// processResponse processes response from VClaim API
func (s *Service) processResponse(res *http.Response) (*ResponDTO, error) {
func (s *Service) processResponse(res *http.Response) (*ResponDTOVclaim, error) {
defer res.Body.Close()
log.Info().
@@ -170,7 +170,7 @@ func (s *Service) processResponse(res *http.Response) (*ResponDTO, error) {
}
// Parse raw response
var respMentah ResponMentahDTO
var respMentah ResponMentahDTOVclaim
if err := json.Unmarshal(body, &respMentah); err != nil {
log.Error().
Err(err).
@@ -186,7 +186,7 @@ func (s *Service) processResponse(res *http.Response) (*ResponDTO, error) {
Msg("Response metadata")
// Create final response
finalResp := &ResponDTO{
finalResp := &ResponDTOVclaim{
MetaData: respMentah.MetaData,
}
@@ -312,7 +312,7 @@ func (s *Service) Delete(ctx context.Context, endpoint string, result interface{
}
// GetRawResponse returns raw response without mapping
func (s *Service) GetRawResponse(ctx context.Context, endpoint string) (*ResponDTO, error) {
func (s *Service) GetRawResponse(ctx context.Context, endpoint string) (*ResponDTOVclaim, error) {
req, err := s.prepareRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return nil, err
@@ -327,7 +327,7 @@ func (s *Service) GetRawResponse(ctx context.Context, endpoint string) (*ResponD
}
// PostRawResponse returns raw response without mapping
func (s *Service) PostRawResponse(ctx context.Context, endpoint string, payload interface{}) (*ResponDTO, error) {
func (s *Service) PostRawResponse(ctx context.Context, endpoint string, payload interface{}) (*ResponDTOVclaim, error) {
var buf bytes.Buffer
if payload != nil {
if err := json.NewEncoder(&buf).Encode(payload); err != nil {
@@ -349,7 +349,7 @@ func (s *Service) PostRawResponse(ctx context.Context, endpoint string, payload
}
// mapToResult maps the final response to the result interface
func mapToResult(resp *ResponDTO, result interface{}) error {
func mapToResult(resp *ResponDTOVclaim, result interface{}) error {
respBytes, err := json.Marshal(resp)
if err != nil {
return fmt.Errorf("failed to marshal final response: %w", err)