more cleanup

This commit is contained in:
2026-01-28 22:28:42 -05:00
parent ffcb6f658b
commit e04fe8cef3
4 changed files with 84 additions and 71 deletions

View File

@@ -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)
}