chore: change interface{} to any (#2818)

* chore: change interface{} to any

* chore: update goctl version to 1.5.0

* chore: update goctl deps
This commit is contained in:
Kevin Wan
2023-01-24 16:32:02 +08:00
committed by GitHub
parent 7e0ac77139
commit ae87114282
221 changed files with 1910 additions and 2207 deletions

View File

@@ -28,7 +28,7 @@ var interceptors = []internal.Interceptor{
// Do sends an HTTP request with the given arguments and returns an HTTP response.
// data is automatically marshal into a *httpRequest, typically it's defined in an API file.
func Do(ctx context.Context, method, url string, data interface{}) (*http.Response, error) {
func Do(ctx context.Context, method, url string, data any) (*http.Response, error) {
req, err := buildRequest(ctx, method, url, data)
if err != nil {
return nil, err
@@ -54,7 +54,7 @@ func (c defaultClient) do(r *http.Request) (*http.Response, error) {
return http.DefaultClient.Do(r)
}
func buildFormQuery(u *nurl.URL, val map[string]interface{}) string {
func buildFormQuery(u *nurl.URL, val map[string]any) string {
query := u.Query()
for k, v := range val {
query.Add(k, fmt.Sprint(v))
@@ -63,13 +63,13 @@ func buildFormQuery(u *nurl.URL, val map[string]interface{}) string {
return query.Encode()
}
func buildRequest(ctx context.Context, method, url string, data interface{}) (*http.Request, error) {
func buildRequest(ctx context.Context, method, url string, data any) (*http.Request, error) {
u, err := nurl.Parse(url)
if err != nil {
return nil, err
}
var val map[string]map[string]interface{}
var val map[string]map[string]any
if data != nil {
val, err = mapping.Marshal(data)
if err != nil {
@@ -111,13 +111,13 @@ func buildRequest(ctx context.Context, method, url string, data interface{}) (*h
return req, nil
}
func fillHeader(r *http.Request, val map[string]interface{}) {
func fillHeader(r *http.Request, val map[string]any) {
for k, v := range val {
r.Header.Add(k, fmt.Sprint(v))
}
}
func fillPath(u *nurl.URL, val map[string]interface{}) error {
func fillPath(u *nurl.URL, val map[string]any) error {
used := make(map[string]lang.PlaceholderType)
fields := strings.Split(u.Path, slash)

View File

@@ -12,7 +12,7 @@ import (
)
// Parse parses the response.
func Parse(resp *http.Response, val interface{}) error {
func Parse(resp *http.Response, val any) error {
if err := ParseHeaders(resp, val); err != nil {
return err
}
@@ -21,12 +21,12 @@ func Parse(resp *http.Response, val interface{}) error {
}
// ParseHeaders parses the response headers.
func ParseHeaders(resp *http.Response, val interface{}) error {
func ParseHeaders(resp *http.Response, val any) error {
return encoding.ParseHeaders(resp.Header, val)
}
// ParseJsonBody parses the response body, which should be in json content type.
func ParseJsonBody(resp *http.Response, val interface{}) error {
func ParseJsonBody(resp *http.Response, val any) error {
defer resp.Body.Close()
if isContentTypeJson(resp) {

View File

@@ -14,7 +14,7 @@ type (
// Service represents a remote HTTP service.
Service interface {
// Do sends an HTTP request with the given arguments and returns an HTTP response.
Do(ctx context.Context, method, url string, data interface{}) (*http.Response, error)
Do(ctx context.Context, method, url string, data any) (*http.Response, error)
// DoRequest sends a HTTP request to the service.
DoRequest(r *http.Request) (*http.Response, error)
}
@@ -43,7 +43,7 @@ func NewServiceWithClient(name string, cli *http.Client, opts ...Option) Service
}
// Do sends an HTTP request with the given arguments and returns an HTTP response.
func (s namedService) Do(ctx context.Context, method, url string, data interface{}) (*http.Response, error) {
func (s namedService) Do(ctx context.Context, method, url string, data any) (*http.Response, error) {
req, err := buildRequest(ctx, method, url, data)
if err != nil {
return nil, err