...

Package curl

import "github.com/chaos-mesh/chaos-mesh/pkg/curl"
Overview
Index
Examples

Overview ▾

Package curl contains the tools about rendering and parsing curl command

Example (ParseCommands)

Code:

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 (RenderCommands)

some example usage of renderCommands notice that the output could not be used in shell directly, you need quotes and escape

Code:

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

Constants

const ApplicationJson = "application/json"
const HeaderContentType = "Content-Type"

func IsValidRenderedTask

func IsValidRenderedTask(template *v1alpha1.Template) bool

func RenderWorkflowTaskTemplate

func RenderWorkflowTaskTemplate(request RequestForm) (*v1alpha1.Template, error)

type CommandFlags

CommandFlags could be parsed from flags of curl command line.

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"`
}

type Commands

type Commands []string

Header is copied from http.Header, for speed up swagger_spec code generator without --parseDependency

type Header map[string][]string

type RequestForm

RequestForm should contain all the fields shown on frontend

type RequestForm struct {
    CommandFlags
    Name string `json:"name"`
}

func ParseWorkflowTaskTemplate

func ParseWorkflowTaskTemplate(template *v1alpha1.Template) (*RequestForm, error)