增加获取 full url 方法

This commit is contained in:
2022-06-30 17:26:19 +08:00
parent 1326ec76a8
commit f8a6482e0a
3 changed files with 111 additions and 2 deletions

28
rpc.go
View File

@ -9,10 +9,13 @@ package rpc
import (
"errors"
"fmt"
"strings"
"sync"
"time"
httpclient "github.com/ddliu/go-httpclient"
"github.com/ddliu/go-httpclient"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
@ -248,7 +251,15 @@ func (r *request) Connect() error {
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:24 2022/6/30
func (r *request) Send() error {
func (r *request) Send(ctx *gin.Context, serviceFlag string, apiFlag string, parameter map[string]interface{}, receiver interface{}) error {
var (
serviceConfig *Service
apiConfig *Api
err error
)
if serviceConfig, apiConfig, err = r.GetServiceApi(serviceFlag, apiFlag); nil != err {
return err
}
return nil
}
@ -271,3 +282,16 @@ func (r *request) GetHttpClient(header map[string]string, timeout ApiTimeout) *h
client.WithOption(httpclient.OPT_TIMEOUT_MS, time.Duration(timeout.Read)*time.Millisecond)
return client
}
// getFullURL ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:23 2022/6/30
func (r *request) getFullURL(serviceConfig *Service, apiConfig *Api, parameter map[string]interface{}) string {
fullURL := strings.ReplaceAll(serviceConfig.Domain+"/"+apiConfig.URI, "//", "/")
for name, val := range parameter {
fullURL = strings.ReplaceAll(fullURL, "{{"+name+"}}", fmt.Sprintf("%v", val))
}
return fullURL
}