package curl2info func init() { optionTrie = newTrie() oelist := []*optionExecute{ {"-H", 10, parseHeader, nil}, {"-X", 10, parseOptX, nil}, {"-A", 15, parseUserAgent, &extract{re: "^-A +(.+)", execute: extractData}}, {"-I", 15, parseOptI, nil}, {"-d", 10, parseBodyASCII, &extract{re: "^-d +(.+)", execute: extractData}}, {"-u", 15, parseUser, &extract{re: "^-u +(.+)", execute: extractData}}, {"-k", 15, parseInsecure, nil}, // Body {"--data", 10, parseBodyASCII, &extract{re: "--data +(.+)", execute: extractData}}, {"--data-urlencode", 10, parseBodyURLEncode, &extract{re: "--data-urlencode +(.+)", execute: extractData}}, {"--data-binary", 10, parseBodyBinary, &extract{re: "--data-binary +(.+)", execute: extractData}}, {"--data-ascii", 10, parseBodyASCII, &extract{re: "--data-ascii +(.+)", execute: extractData}}, {"--data-raw", 10, parseBodyRaw, &extract{re: "--data-raw +(.+)", execute: extractData}}, //"--" {"--header", 10, parseHeader, nil}, {"--insecure", 15, parseInsecure, nil}, {"--task", 10, parseITask, &extract{re: "--task +(.+)", execute: extractData}}, {"--user-agent", 15, parseUserAgent, &extract{re: "--user-agent +(.+)", execute: extractData}}, {"--user", 15, parseUser, &extract{re: "--user +(.+)", execute: extractData}}, {"--connect-timeout", 15, parseTimeout, &extract{re: "--connect-timeout +(.+)", execute: extractData}}, } for _, oe := range oelist { optionTrie.Insert(oe) } // log.Println("support options:", optionTrie.AllWords()) } // extract 用于提取设置的数据 type extract struct { re string execute func(re, soption string) string } func (et *extract) Execute(soption string) string { return et.execute(et.re, soption) } // OptionTrie 设置的前缀树 var optionTrie *hTrie type optionExecute struct { Prefix string Priority int Execute func(*CURL, string) // 执行函数 Extract *extract // 提取的方法结构与参数 } func (oe *optionExecute) GetWord() string { return oe.Prefix + " " } func (oe *optionExecute) BuildFunction(curl *CURL, soption string) *parseFunction { data := soption if oe.Extract != nil { data = oe.Extract.Execute(data) } return &parseFunction{ParamCURL: curl, ParamData: data, ExecuteFunction: oe.Execute, Priority: oe.Priority} }