more cleanup
This commit is contained in:
@@ -31,9 +31,6 @@ type RequestInit struct {
|
||||
}
|
||||
|
||||
func (o *RequestInit) Validate() error {
|
||||
if o.Method == "" {
|
||||
o.Method = "GET"
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -44,35 +41,20 @@ type Response struct {
|
||||
Headers map[string]string `json:"headers"`
|
||||
}
|
||||
|
||||
type AddArgs struct {
|
||||
A int `json:"a"`
|
||||
B int `json:"b"`
|
||||
}
|
||||
|
||||
func (a AddArgs) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type GreetArgs struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (g GreetArgs) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Fetch(_ context.Context, args FetchArgs) (Response, error) {
|
||||
func Fetch(ctx context.Context, args FetchArgs) (Response, error) {
|
||||
method := "GET"
|
||||
headers := make(map[string]string)
|
||||
|
||||
if args.Init != nil {
|
||||
method = args.Init.Method
|
||||
if args.Init.Method != "" {
|
||||
method = args.Init.Method
|
||||
}
|
||||
if args.Init.Headers != nil {
|
||||
maps.Copy(headers, args.Init.Headers)
|
||||
}
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(method, args.Input, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, method, args.Input, nil)
|
||||
if err != nil {
|
||||
return Response{}, fmt.Errorf("failed to create request: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user