Exemplo n.º 1
0
func init() {
	core.Handler("http.request", Request)

	// Add http.request function to core
	// core.Add("http.request", core.Function{
	// 	Description: "Makes a HTTP request",
	// 	Arguments: core.Variables{
	// 		"hostname": core.String("Request hostname", ""),
	// 		"header":   core.Map("Request header", nil),
	// 		"scheme":   core.String("Request URL scheme (http or https)", "http"),
	// 		"method":   core.String("Request method", "GET"),
	// 		"query":    core.Interface("Request query (map or string)", nil),
	// 		"url":      core.String("Request URL", ""),
	// 	},
	// 	Returns: core.Variables{
	// 		"status": core.Int("Response status code", 0),
	// 		"header": core.Map("Response header", nil),
	// 		"body":   core.Stream("Response body"),
	// 	},
	// 	Function: Request,
	// })

	// Method shortcuts for http.request eq. http.get
	methods := []string{"get", "put", "post", "delete"}

	// Add all shortcuts
	for _, method := range methods {
		core.Action("http."+method, &action.Action{
			Name: "http.request",
			Ctx: action.Map{
				"method": strings.ToUpper(method),
			},
		})
	}
}
Exemplo n.º 2
0
func main() {
	defer glog.Flush()
	flag.Parse()
	actions, err := fileToActions(filename)
	if err != nil {
		fmt.Println(err)
		return
	}

	if len(os.Args) <= 1 {
		fmt.Println("cmds needs at least one argument\n")
		fmt.Println("available commands:\n")
		for name := range actions {
			fmt.Printf("  %s\n", name)
		}
		return
	}

	for name, a := range actions {
		core.Action(name, a)
	}

	res, err := local.Run(&action.Action{Name: os.Args[1]})
	if res != nil {
		res = mapBytes(res)
		printMap(res, 1)
		fmt.Printf("\n")
	}
	if err != nil {
		fmt.Printf("ERROR %v\n", err)
	} else {
		fmt.Println("OK")
	}
}