Documentation ¶
Overview ¶
Package curl contains the tools about rendering and parsing curl command
Example (ParseCommands) ¶
cmd := []string{"curl", "-i", "-s", "-L", "https://github.com/chaos-mesh/chaos-mesh"} flags, err := parseCommands(cmd) if err != nil { fmt.Println(err.Error()) } fmt.Printf("%+v", flags)
Output: &{Method:GET URL:https://github.com/chaos-mesh/chaos-mesh Header:map[] Body: FollowLocation:true JsonContent:false}
Example (ParseCommands_postJson) ¶
cmd := []string{"curl", "-i", "-s", "-X", "POST", "-d", "{\"foo\": \"bar\"}", "-H", "Content-Type: application/json", "https://jsonplaceholder.typicode.com/posts"} flags, err := parseCommands(cmd) if err != nil { fmt.Println(err.Error()) } fmt.Printf("%+v", flags)
Output: &{Method:POST URL:https://jsonplaceholder.typicode.com/posts Header:map[] Body:{"foo": "bar"} FollowLocation:false JsonContent:true}
Example (ParseCommands_withCustomHeader) ¶
cmd := []string{"curl", "-i", "-s", "-L", "-H", "User-Agent: Go-http-client/1.1", "https://github.com/chaos-mesh/chaos-mesh"} flags, err := parseCommands(cmd) if err != nil { fmt.Println(err.Error()) } fmt.Printf("%+v", flags)
Output: &{Method:GET URL:https://github.com/chaos-mesh/chaos-mesh Header:map[User-Agent:[Go-http-client/1.1]] Body: FollowLocation:true JsonContent:false}
Example (RenderCommands) ¶
some example usage of renderCommands notice that the output could not be used in shell directly, you need quotes and escape
commands, _ := renderCommands(CommandFlags{ Method: http.MethodGet, URL: "https://github.com/chaos-mesh/chaos-mesh", Header: nil, Body: "", FollowLocation: true, JsonContent: false, }) fmt.Println(strings.Join(commands, " "))
Output: curl -i -s -L https://github.com/chaos-mesh/chaos-mesh
Example (RenderCommands_postJson) ¶
commands, _ := renderCommands(CommandFlags{ Method: http.MethodPost, URL: "https://jsonplaceholder.typicode.com/posts", Header: nil, Body: "{\"foo\": \"bar\"}", FollowLocation: false, JsonContent: true, }) fmt.Println(strings.Join(commands, " "))
Output: curl -i -s -X POST -d {"foo": "bar"} -H Content-Type: application/json https://jsonplaceholder.typicode.com/posts
Example (RenderCommands_withCustomHeader) ¶
commands, _ := renderCommands(CommandFlags{ Method: http.MethodGet, URL: "https://github.com/chaos-mesh/chaos-mesh", Header: Header{ "User-Agent": []string{"Go-http-client/1.1"}, }, Body: "", FollowLocation: true, JsonContent: false, }) fmt.Println(strings.Join(commands, " "))
Output: curl -i -s -L -H User-Agent: Go-http-client/1.1 https://github.com/chaos-mesh/chaos-mesh
Index ¶
Examples ¶
Constants ¶
View Source
const ApplicationJson = "application/json"
View Source
const HeaderContentType = "Content-Type"
Variables ¶
This section is empty.
Functions ¶
func IsValidRenderedTask ¶
func RenderWorkflowTaskTemplate ¶
func RenderWorkflowTaskTemplate(request RequestForm) (*v1alpha1.Template, error)
Types ¶
type CommandFlags ¶
type CommandFlags struct { Method string `json:"method"` URL string `json:"url"` Header Header `json:"header"` Body string `json:"body"` FollowLocation bool `json:"followLocation"` JsonContent bool `json:"jsonContent"` }
CommandFlags could be parsed from flags of curl command line.
type Header ¶
Header is copied from http.Header, for speed up swagger_spec code generator without --parseDependency
type RequestForm ¶
type RequestForm struct { CommandFlags Name string `json:"name"` }
RequestForm should contain all the fields shown on frontend
func ParseWorkflowTaskTemplate ¶
func ParseWorkflowTaskTemplate(template *v1alpha1.Template) (*RequestForm, error)
Click to show internal directories.
Click to hide internal directories.