示例#1
0
func Dispatch(req goreq.Request) (string, error) {
	// --debug to show only request uri (plus data if POSTing)
	for _, arg := range os.Args {
		if arg == "-d" || arg == "--debug" {
			httpreq, _ := req.NewRequest()
			fmt.Printf("%# v", pretty.Formatter(httpreq))
			os.Exit(0)
		}
	}

	// dispatch
	res, err := req.Do()
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	body, err := res.Body.ToString()

	// --prettify
	for _, arg := range os.Args {
		if arg == "--prettify" {
			body, _ = PrettifyJson(body)
		}
	}
	return body, err
}