Newer
Older
httpcat / src / client.go
package main

import (
	"fmt"
)

type ClientCommand struct {
	URL    string `short:"u" long:"uri" description:"The URI to send the reqest to." required:"true"`
	Accept string `short:"a" long:"accept" description:"Add 'Accept' header to request."`
	Method string `short:"m" long:"method" description:"HTTP method for request" default:"GET"`
	Body   string `short:"b" long:"body" description:"Request body to send (for POST/PUT/PATCH)"`
}

func (c *ClientCommand) Execute(args []string) error {
	fmt.Println("Send request to ", c.URL)
	return nil
}

// func sendRequest(uri string) {

// 	client := http.Client{}

// 	request, _ := http.NewRequest("GET", uri, nil)

// 	// add Accept header if required by user
// 	if accept != "" {
// 		request.Header.Add("Accept", accept)
// 	}

// 	response, err := client.Do(request)

// 	if err != nil {
// 		fmt.Fprintln(os.Stderr, err)
// 	} else {

// 		// print entire response
// 		if entire {
// 			dump, _ := httputil.DumpResponse(response, true)
// 			fmt.Println(string(dump[:]))

// 			// print only the response body
// 		} else {
// 			body, _ := ioutil.ReadAll(response.Body)
// 			fmt.Println(string(body[:]))
// 		}
// 	}
// }