把所有没必要的内部类型参数隐藏
This commit is contained in:
parent
562ef11e2a
commit
f7279cb755
|
@ -1,7 +1,7 @@
|
|||
package curl2info
|
||||
|
||||
func init() {
|
||||
optionTrie = NewTrie()
|
||||
optionTrie = newTrie()
|
||||
oelist := []*optionExecute{
|
||||
{"-H", 10, parseHeader, nil},
|
||||
{"-X", 10, parseOptX, nil},
|
||||
|
@ -43,7 +43,7 @@ func (et *extract) Execute(soption string) string {
|
|||
}
|
||||
|
||||
// OptionTrie 设置的前缀树
|
||||
var optionTrie *Trie
|
||||
var optionTrie *hTrie
|
||||
|
||||
type optionExecute struct {
|
||||
Prefix string
|
||||
|
|
|
@ -99,38 +99,6 @@ func (curl *CURL) CreateWorkflow(ses *requests.Session) *requests.Workflow {
|
|||
return wf
|
||||
}
|
||||
|
||||
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},
|
||||
{"--call", 10, parseCallBack, &extract{re: "--call +(.+)", 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())
|
||||
}
|
||||
|
||||
// ParseRawCURL curl_bash 可以用trie改进 没空改
|
||||
func ParseRawCURL(scurl string) (cURL *CURL, err error) {
|
||||
|
||||
|
@ -184,7 +152,7 @@ func ParseRawCURL(scurl string) (cURL *CURL, err error) {
|
|||
}
|
||||
|
||||
func judgeOptions(u *CURL, soption string) *parseFunction {
|
||||
word := TrieStrWord(soption)
|
||||
word := trieStrWord(soption)
|
||||
if ioe := optionTrie.SearchMostPrefix(&word); ioe != nil {
|
||||
oe := ioe.(*optionExecute)
|
||||
return oe.BuildFunction(u, soption)
|
||||
|
|
36
structure.go
36
structure.go
|
@ -2,35 +2,35 @@ package curl2info
|
|||
|
||||
import "container/heap"
|
||||
|
||||
// TrieWord Trie 需要的Word接口
|
||||
type TrieWord interface {
|
||||
// trieWord Trie 需要的Word接口
|
||||
type trieWord interface {
|
||||
GetWord() string
|
||||
}
|
||||
|
||||
// TrieStrWord 最简单的TrieWord 结构
|
||||
type TrieStrWord string
|
||||
type trieStrWord string
|
||||
|
||||
// GetWord 获取单词
|
||||
func (tsw *TrieStrWord) GetWord() string {
|
||||
func (tsw *trieStrWord) GetWord() string {
|
||||
return (string)(*tsw)
|
||||
}
|
||||
|
||||
// Trie 前缀树
|
||||
type Trie struct {
|
||||
type hTrie struct {
|
||||
isWord bool
|
||||
value interface{}
|
||||
char byte
|
||||
prev *Trie
|
||||
next map[byte]*Trie
|
||||
prev *hTrie
|
||||
next map[byte]*hTrie
|
||||
}
|
||||
|
||||
// NewTrie Initialize your data structure here.
|
||||
func NewTrie() *Trie {
|
||||
return &Trie{next: make(map[byte]*Trie)}
|
||||
// newTrie Initialize your data structure here.
|
||||
func newTrie() *hTrie {
|
||||
return &hTrie{next: make(map[byte]*hTrie)}
|
||||
}
|
||||
|
||||
// Insert a word into the trie.
|
||||
func (trie *Trie) Insert(iword TrieWord) {
|
||||
func (trie *hTrie) Insert(iword trieWord) {
|
||||
cur := trie
|
||||
word := iword.GetWord()
|
||||
l := len(word)
|
||||
|
@ -40,7 +40,7 @@ func (trie *Trie) Insert(iword TrieWord) {
|
|||
if next, ok := cur.next[c]; ok {
|
||||
cur = next
|
||||
} else {
|
||||
create := NewTrie()
|
||||
create := newTrie()
|
||||
cur.next[c] = create
|
||||
create.char = c
|
||||
create.prev = cur
|
||||
|
@ -53,7 +53,7 @@ func (trie *Trie) Insert(iword TrieWord) {
|
|||
}
|
||||
|
||||
// AllWords 所有单词
|
||||
func (trie *Trie) AllWords() []string {
|
||||
func (trie *hTrie) AllWords() []string {
|
||||
var result []string
|
||||
for _, v := range trie.next {
|
||||
look(v, "", &result)
|
||||
|
@ -61,7 +61,7 @@ func (trie *Trie) AllWords() []string {
|
|||
return result
|
||||
}
|
||||
|
||||
func look(cur *Trie, content string, result *[]string) {
|
||||
func look(cur *hTrie, content string, result *[]string) {
|
||||
content += string(cur.char)
|
||||
if cur.isWord {
|
||||
*result = append(*result, content)
|
||||
|
@ -72,7 +72,7 @@ func look(cur *Trie, content string, result *[]string) {
|
|||
}
|
||||
|
||||
// Remove 移除单词
|
||||
func (trie *Trie) Remove(word string) {
|
||||
func (trie *hTrie) Remove(word string) {
|
||||
cur := trie
|
||||
l := len(word)
|
||||
for i := 0; i < l; i++ {
|
||||
|
@ -104,7 +104,7 @@ func (trie *Trie) Remove(word string) {
|
|||
}
|
||||
|
||||
// SearchMostPrefix Returns if the word is in the trie.
|
||||
func (trie *Trie) SearchMostPrefix(iword TrieWord) interface{} {
|
||||
func (trie *hTrie) SearchMostPrefix(iword trieWord) interface{} {
|
||||
cur := trie
|
||||
word := iword.GetWord()
|
||||
|
||||
|
@ -126,7 +126,7 @@ func (trie *Trie) SearchMostPrefix(iword TrieWord) interface{} {
|
|||
}
|
||||
|
||||
// Match Returns if the word is in the trie.
|
||||
func (trie *Trie) Match(iword TrieWord) interface{} {
|
||||
func (trie *hTrie) Match(iword trieWord) interface{} {
|
||||
cur := trie
|
||||
word := iword.GetWord()
|
||||
|
||||
|
@ -144,7 +144,7 @@ func (trie *Trie) Match(iword TrieWord) interface{} {
|
|||
}
|
||||
|
||||
// StartsWith Returns if there is any word in the trie that starts with the given prefix. */
|
||||
func (trie *Trie) StartsWith(prefix string) bool {
|
||||
func (trie *hTrie) StartsWith(prefix string) bool {
|
||||
cur := trie
|
||||
l := len(prefix)
|
||||
for i := 0; i < l; i++ {
|
||||
|
|
Loading…
Reference in New Issue
Block a user