diff --git a/ctl/label.go b/ctl/label.go index c69084864..db94bf720 100644 --- a/ctl/label.go +++ b/ctl/label.go @@ -10,6 +10,7 @@ import ( "regexp" "strings" + "github.com/halfrost/LeetCode-Go/ctl/util" "github.com/spf13/cobra" ) @@ -75,7 +76,7 @@ var ( ) func getChapterFourFileOrder() ([]string, []int) { - solutions, solutionIds := LoadChapterFourDir() + solutions, solutionIds := util.LoadChapterFourDir() chapterFourFileOrder := []string{"_index"} chapterFourFileOrder = append(chapterFourFileOrder, solutions...) fmt.Printf("ChapterFour 中包括 _index 有 %v 个文件, len(id) = %v\n", len(chapterFourFileOrder), len(solutionIds)) @@ -149,7 +150,7 @@ func addPreNextLabel(order, preOrder []string, chapterFourIds []int, preChapter, tmp = "\n\n" + delLine + fmt.Sprintf("

下一页➡️

\n", chapter, order[index+1]) } else { if chapter == "ChapterFour" { - tmp = "\n\n" + preNextHeader + fmt.Sprintf("

⬅️上一章

\n", preChapter, preOrder[len(preOrder)-1]) + fmt.Sprintf("

下一页➡️

\n", chapter, GetChpaterFourFileNum(chapterFourIds[(index-1)+1]), order[index+1]) + preNextFotter + tmp = "\n\n" + preNextHeader + fmt.Sprintf("

⬅️上一章

\n", preChapter, preOrder[len(preOrder)-1]) + fmt.Sprintf("

下一页➡️

\n", chapter, util.GetChpaterFourFileNum(chapterFourIds[(index-1)+1]), order[index+1]) + preNextFotter } else { tmp = "\n\n" + preNextHeader + fmt.Sprintf("

⬅️上一章

\n", preChapter, preOrder[len(preOrder)-1]) + fmt.Sprintf("

下一页➡️

\n", chapter, order[index+1]) + preNextFotter } @@ -157,26 +158,26 @@ func addPreNextLabel(order, preOrder []string, chapterFourIds []int, preChapter, } else if index == len(order)-1 { if chapter == "ChapterFour" { // 最后一页不需要“下一页” - tmp = "\n\n" + delLine + fmt.Sprintf("

⬅️上一页

\n", chapter, GetChpaterFourFileNum(chapterFourIds[(index-1)-1]), order[index-1]) + tmp = "\n\n" + delLine + fmt.Sprintf("

⬅️上一页

\n", chapter, util.GetChpaterFourFileNum(chapterFourIds[(index-1)-1]), order[index-1]) } else { tmp = "\n\n" + preNextHeader + fmt.Sprintf("

⬅️上一页

\n", chapter, order[index-1]) + fmt.Sprintf("

下一章➡️

\n", nextChapter) + preNextFotter } } else if index == 1 { if chapter == "ChapterFour" { - tmp = "\n\n" + preNextHeader + fmt.Sprintf("

⬅️上一页

\n", chapter) + fmt.Sprintf("

下一页➡️

\n", chapter, GetChpaterFourFileNum(chapterFourIds[(index-1)+1]), order[index+1]) + preNextFotter + tmp = "\n\n" + preNextHeader + fmt.Sprintf("

⬅️上一页

\n", chapter) + fmt.Sprintf("

下一页➡️

\n", chapter, util.GetChpaterFourFileNum(chapterFourIds[(index-1)+1]), order[index+1]) + preNextFotter } else { tmp = "\n\n" + preNextHeader + fmt.Sprintf("

⬅️上一页

\n", chapter) + fmt.Sprintf("

下一页➡️

\n", chapter, order[index+1]) + preNextFotter } } else { if chapter == "ChapterFour" { - tmp = "\n\n" + preNextHeader + fmt.Sprintf("

⬅️上一页

\n", chapter, GetChpaterFourFileNum(chapterFourIds[(index-1)-1]), order[index-1]) + fmt.Sprintf("

下一页➡️

\n", chapter, GetChpaterFourFileNum(chapterFourIds[(index-1)+1]), order[index+1]) + preNextFotter + tmp = "\n\n" + preNextHeader + fmt.Sprintf("

⬅️上一页

\n", chapter, util.GetChpaterFourFileNum(chapterFourIds[(index-1)-1]), order[index-1]) + fmt.Sprintf("

下一页➡️

\n", chapter, util.GetChpaterFourFileNum(chapterFourIds[(index-1)+1]), order[index+1]) + preNextFotter } else { tmp = "\n\n" + preNextHeader + fmt.Sprintf("

⬅️上一页

\n", chapter, order[index-1]) + fmt.Sprintf("

下一页➡️

\n", chapter, order[index+1]) + preNextFotter } } if chapter == "ChapterFour" && index > 0 { - path = fmt.Sprintf("%v/%v", GetChpaterFourFileNum(chapterFourIds[(index-1)]), path) + path = fmt.Sprintf("%v/%v", util.GetChpaterFourFileNum(chapterFourIds[(index-1)]), path) } exist, err = needAdd(fmt.Sprintf("../website/content/%v/%v.md", chapter, path)) @@ -191,7 +192,7 @@ func addPreNextLabel(order, preOrder []string, chapterFourIds []int, preChapter, fmt.Println(err) return } - WriteFile(fmt.Sprintf("../website/content/%v/%v.md", chapter, path), res) + util.WriteFile(fmt.Sprintf("../website/content/%v/%v.md", chapter, path), res) count++ } } @@ -241,7 +242,7 @@ func delPreNextLabel(order []string, chapterFourIds []int, chapter string) { lineNum = 3 } if chapter == "ChapterFour" && index > 0 { - path = fmt.Sprintf("%v/%v", GetChpaterFourFileNum(chapterFourIds[(index-1)]), path) + path = fmt.Sprintf("%v/%v", util.GetChpaterFourFileNum(chapterFourIds[(index-1)]), path) } exist, err := needAdd(fmt.Sprintf("../website/content/%v/%v.md", chapter, path)) @@ -262,7 +263,7 @@ func delPreNextLabel(order []string, chapterFourIds []int, chapter string) { // fmt.Println(err) // return // } - // WriteFile(fmt.Sprintf("../website/content/ChapterOne/%v.md", v), res) + // util.WriteFile(fmt.Sprintf("../website/content/ChapterOne/%v.md", v), res) } func needAdd(filePath string) (bool, error) { diff --git a/ctl/models/go.mod b/ctl/models/go.mod new file mode 100644 index 000000000..2b1389a7f --- /dev/null +++ b/ctl/models/go.mod @@ -0,0 +1,7 @@ +module github.com/halfrost/LeetCode-Go/ctl/models + +go 1.19 + +replace github.com/halfrost/LeetCode-Go/ctl/models => ../util + +require github.com/halfrost/LeetCode-Go/ctl/util v0.0.0-20220910225043-e3bb5aff34d0 diff --git a/ctl/models/go.sum b/ctl/models/go.sum new file mode 100644 index 000000000..2c3eec0c9 --- /dev/null +++ b/ctl/models/go.sum @@ -0,0 +1,2 @@ +github.com/halfrost/LeetCode-Go/ctl/util v0.0.0-20220910225043-e3bb5aff34d0 h1:WAOAj59szR52uAnEQljAt7ucpbGGOsy0xgR/NeP4Xbc= +github.com/halfrost/LeetCode-Go/ctl/util v0.0.0-20220910225043-e3bb5aff34d0/go.mod h1:+cA8KYcbGxP2Itd3NG+QJVGL/MEZISKlei0tvgDeEag= diff --git a/ctl/lcproblems.go b/ctl/models/lcproblems.go similarity index 99% rename from ctl/lcproblems.go rename to ctl/models/lcproblems.go index f6bf03c20..e73537d64 100644 --- a/ctl/lcproblems.go +++ b/ctl/models/lcproblems.go @@ -1,4 +1,4 @@ -package main +package models import ( "fmt" diff --git a/ctl/mdrow.go b/ctl/models/mdrow.go similarity index 99% rename from ctl/mdrow.go rename to ctl/models/mdrow.go index 85de4bb90..5ad90ec0e 100644 --- a/ctl/mdrow.go +++ b/ctl/models/mdrow.go @@ -1,4 +1,4 @@ -package main +package models import ( "fmt" diff --git a/ctl/tagproblem.go b/ctl/models/tagproblem.go similarity index 96% rename from ctl/tagproblem.go rename to ctl/models/tagproblem.go index 8acb2f6ef..5bc04ab8c 100644 --- a/ctl/tagproblem.go +++ b/ctl/models/tagproblem.go @@ -1,10 +1,12 @@ -package main +package models import ( "encoding/json" "fmt" "strconv" "strings" + + "github.com/halfrost/LeetCode-Go/ctl/util" ) // Graphql define @@ -152,15 +154,15 @@ func standardizedTitle(orig string, frontendQuestionID int32) string { func GenerateTagMdRows(solutionIds []int, metaMap map[int]TagList, mdrows []Mdrow, internal bool) []TagList { tl := []TagList{} for _, row := range mdrows { - if BinarySearch(solutionIds, int(row.FrontendQuestionID)) != -1 { + if util.BinarySearch(solutionIds, int(row.FrontendQuestionID)) != -1 { tmp := TagList{} tmp.FrontendQuestionID = row.FrontendQuestionID tmp.QuestionTitle = strings.TrimSpace(row.QuestionTitle) s7 := standardizedTitle(row.QuestionTitle, row.FrontendQuestionID) if internal { - tmp.SolutionPath = fmt.Sprintf("[Go]({{< relref \"/ChapterFour/%v/%v.md\" >}})", GetChpaterFourFileNum(int(row.FrontendQuestionID)), fmt.Sprintf("%04d.%v", int(row.FrontendQuestionID), s7)) + tmp.SolutionPath = fmt.Sprintf("[Go]({{< relref \"/ChapterFour/%v/%v.md\" >}})", util.GetChpaterFourFileNum(int(row.FrontendQuestionID)), fmt.Sprintf("%04d.%v", int(row.FrontendQuestionID), s7)) } else { - tmp.SolutionPath = fmt.Sprintf("[Go](https://books.halfrost.com/leetcode/ChapterFour/%v/%v)", GetChpaterFourFileNum(int(row.FrontendQuestionID)), fmt.Sprintf("%04d.%v", int(row.FrontendQuestionID), s7)) + tmp.SolutionPath = fmt.Sprintf("[Go](https://books.halfrost.com/leetcode/ChapterFour/%v/%v)", util.GetChpaterFourFileNum(int(row.FrontendQuestionID)), fmt.Sprintf("%04d.%v", int(row.FrontendQuestionID), s7)) } tmp.Acceptance = row.Acceptance tmp.Difficulty = row.Difficulty diff --git a/ctl/user.go b/ctl/models/user.go similarity index 99% rename from ctl/user.go rename to ctl/models/user.go index cf9a90c59..d79dc6d5f 100644 --- a/ctl/user.go +++ b/ctl/models/user.go @@ -1,4 +1,4 @@ -package main +package models import ( "fmt" diff --git a/ctl/pdf.go b/ctl/pdf.go index 71817554d..d481df4c5 100644 --- a/ctl/pdf.go +++ b/ctl/pdf.go @@ -10,6 +10,7 @@ import ( "strconv" "strings" + "github.com/halfrost/LeetCode-Go/ctl/util" "github.com/spf13/cobra" ) @@ -60,7 +61,7 @@ func generatePDF() { // 先删除 pre-next delPreNext() - chapterFourFileOrder, _ := LoadChapterFourDir() + chapterFourFileOrder, _ := util.LoadChapterFourDir() totalSolutions = len(chapterFourFileOrder) midVersion = totalSolutions / 100 lastVersion = totalSolutions % 100 @@ -79,7 +80,7 @@ func generatePDF() { tmp, err = loadChapter(chapterThreeFileOrder, "./pdftemp", "ChapterThree") pdf = append(pdf, tmp...) // PDF 第四章 - tmp, err = LoadFile("./pdftemp/ChapterFour/_index.md") + tmp, err = util.LoadFile("./pdftemp/ChapterFour/_index.md") pdf = append(pdf, tmp...) tmp, err = loadChapter(chapterFourFileOrder, "../website/content", "ChapterFour") pdf = append(pdf, tmp...) @@ -87,10 +88,10 @@ func generatePDF() { fmt.Println(err) } // 生成 PDF - WriteFile(fmt.Sprintf("../PDF v%v.%v.%v.md", majorVersion, midVersion, lastVersion), pdf) + util.WriteFile(fmt.Sprintf("../PDF v%v.%v.%v.md", majorVersion, midVersion, lastVersion), pdf) // 还原现场 addPreNext() - DestoryDir("./pdftemp") + util.DestoryDir("./pdftemp") } func loadChapter(order []string, path, chapter string) ([]byte, error) { @@ -109,10 +110,10 @@ func loadChapter(order []string, path, chapter string) ([]byte, error) { if err != nil { fmt.Println(err) } - tmp, err = LoadFile(fmt.Sprintf("%v/%v/%v/%v.md", path, chapter, GetChpaterFourFileNum(num), v)) + tmp, err = util.LoadFile(fmt.Sprintf("%v/%v/%v/%v.md", path, chapter, util.GetChpaterFourFileNum(num), v)) } } else { - tmp, err = LoadFile(fmt.Sprintf("%v/%v/%v.md", path, chapter, v)) + tmp, err = util.LoadFile(fmt.Sprintf("%v/%v/%v.md", path, chapter, v)) } } if err != nil { @@ -146,7 +147,7 @@ func prepare(path string) { } // 生成外部链接的 ChapterTwo buildChapterTwo(false) - CopyFile("./pdftemp/ChapterTwo/_index.md", "../website/content/ChapterTwo/_index.md") + util.CopyFile("./pdftemp/ChapterTwo/_index.md", "../website/content/ChapterTwo/_index.md") for _, v := range chapterTwoFileOrder { removeHeader(fmt.Sprintf("./pdftemp/ChapterTwo/%v.md", v), fmt.Sprintf("./pdftemp/ChapterTwo/%v.md", v), 5) diff --git a/ctl/render.go b/ctl/render.go index 26623994b..3e62a36eb 100644 --- a/ctl/render.go +++ b/ctl/render.go @@ -11,6 +11,8 @@ import ( "strconv" "strings" + m "github.com/halfrost/LeetCode-Go/ctl/models" + "github.com/halfrost/LeetCode-Go/ctl/util" "github.com/spf13/cobra" ) @@ -78,13 +80,13 @@ func newBuildMenu() *cobra.Command { func buildREADME() { var ( - problems []StatStatusPairs - lpa LeetCodeProblemAll - info UserInfo + problems []m.StatStatusPairs + lpa m.LeetCodeProblemAll + info m.UserInfo ) // 请求所有题目信息 body := getProblemAllList() - problemsMap, optimizingIds := map[int]StatStatusPairs{}, []int{} + problemsMap, optimizingIds := map[int]m.StatStatusPairs{}, []int{} err := json.Unmarshal(body, &lpa) if err != nil { fmt.Println(err) @@ -94,30 +96,30 @@ func buildREADME() { // 拼凑 README 需要渲染的数据 problems = lpa.StatStatusPairs - info = ConvertUserInfoModel(lpa) + info = m.ConvertUserInfoModel(lpa) for _, v := range problems { problemsMap[int(v.Stat.FrontendQuestionID)] = v } - mdrows := ConvertMdModelFromSsp(problems) - sort.Sort(SortByQuestionID(mdrows)) - solutionIds, _, try := LoadSolutionsDir() - GenerateMdRows(solutionIds, mdrows) + mdrows := m.ConvertMdModelFromSsp(problems) + sort.Sort(m.SortByQuestionID(mdrows)) + solutionIds, _, try := util.LoadSolutionsDir() + m.GenerateMdRows(solutionIds, mdrows) info.EasyTotal, info.MediumTotal, info.HardTotal, info.OptimizingEasy, info.OptimizingMedium, info.OptimizingHard, optimizingIds = statisticalData(problemsMap, solutionIds) - omdrows := ConvertMdModelFromIds(problemsMap, optimizingIds) - sort.Sort(SortByQuestionID(omdrows)) + omdrows := m.ConvertMdModelFromIds(problemsMap, optimizingIds) + sort.Sort(m.SortByQuestionID(omdrows)) // 按照模板渲染 README - res, err := renderReadme("./template/template.markdown", len(solutionIds), try, Mdrows{Mdrows: mdrows}, Mdrows{Mdrows: omdrows}, info) + res, err := renderReadme("./template/template.markdown", len(solutionIds), try, m.Mdrows{Mdrows: mdrows}, m.Mdrows{Mdrows: omdrows}, info) if err != nil { fmt.Println(err) return } - WriteFile("../README.md", res) + util.WriteFile("../README.md", res) fmt.Println("write file successful") //makeReadmeFile(mds) } -func renderReadme(filePath string, total, try int, mdrows, omdrows Mdrows, user UserInfo) ([]byte, error) { +func renderReadme(filePath string, total, try int, mdrows, omdrows m.Mdrows, user m.UserInfo) ([]byte, error) { f, err := os.OpenFile(filePath, os.O_RDONLY, 0644) if err != nil { return nil, err @@ -165,8 +167,8 @@ func renderReadme(filePath string, total, try int, mdrows, omdrows Mdrows, user // false 渲染的链接是外部 HTTPS 链接,用于生成 PDF func buildChapterTwo(internal bool) { var ( - gr GraphQLResp - questions []Question + gr m.GraphQLResp + questions []m.Question count int ) for index, tag := range chapterTwoSlug { @@ -178,25 +180,25 @@ func buildChapterTwo(internal bool) { return } questions = gr.Data.TopicTag.Questions - mdrows := ConvertMdModelFromQuestions(questions) - sort.Sort(SortByQuestionID(mdrows)) - solutionIds, _, _ := LoadSolutionsDir() + mdrows := m.ConvertMdModelFromQuestions(questions) + sort.Sort(m.SortByQuestionID(mdrows)) + solutionIds, _, _ := util.LoadSolutionsDir() tl, err := loadMetaData(fmt.Sprintf("./meta/%v", chapterTwoFileName[index])) if err != nil { fmt.Printf("err = %v\n", err) } - tls := GenerateTagMdRows(solutionIds, tl, mdrows, internal) + tls := m.GenerateTagMdRows(solutionIds, tl, mdrows, internal) //fmt.Printf("tls = %v\n", tls) // 按照模板渲染 README - res, err := renderChapterTwo(fmt.Sprintf("./template/%v.md", chapterTwoFileName[index]), TagLists{TagLists: tls}) + res, err := renderChapterTwo(fmt.Sprintf("./template/%v.md", chapterTwoFileName[index]), m.TagLists{TagLists: tls}) if err != nil { fmt.Println(err) return } if internal { - WriteFile(fmt.Sprintf("../website/content/ChapterTwo/%v.md", chapterTwoFileName[index]), res) + util.WriteFile(fmt.Sprintf("../website/content/ChapterTwo/%v.md", chapterTwoFileName[index]), res) } else { - WriteFile(fmt.Sprintf("./pdftemp/ChapterTwo/%v.md", chapterTwoFileName[index]), res) + util.WriteFile(fmt.Sprintf("./pdftemp/ChapterTwo/%v.md", chapterTwoFileName[index]), res) } count++ @@ -204,13 +206,13 @@ func buildChapterTwo(internal bool) { fmt.Printf("write %v files successful", count) } -func loadMetaData(filePath string) (map[int]TagList, error) { +func loadMetaData(filePath string) (map[int]m.TagList, error) { f, err := os.OpenFile(filePath, os.O_RDONLY, 0644) if err != nil { return nil, err } defer f.Close() - reader, metaMap := bufio.NewReader(f), map[int]TagList{} + reader, metaMap := bufio.NewReader(f), map[int]m.TagList{} for { line, _, err := reader.ReadLine() @@ -223,7 +225,7 @@ func loadMetaData(filePath string) (map[int]TagList, error) { s := strings.Split(string(line), "|") v, _ := strconv.Atoi(strings.Split(s[1], ".")[0]) // v[0] 是题号,s[4] time, s[5] space, s[6] favorite - metaMap[v] = TagList{ + metaMap[v] = m.TagList{ FrontendQuestionID: int32(v), Acceptance: "", Difficulty: "", @@ -234,7 +236,7 @@ func loadMetaData(filePath string) (map[int]TagList, error) { } } -func renderChapterTwo(filePath string, tls TagLists) ([]byte, error) { +func renderChapterTwo(filePath string, tls m.TagLists) ([]byte, error) { f, err := os.OpenFile(filePath, os.O_RDONLY, 0644) if err != nil { return nil, err @@ -270,18 +272,18 @@ func buildBookMenu() { fmt.Println(err) return } - WriteFile("../website/content/menu/index.md", res) + util.WriteFile("../website/content/menu/index.md", res) fmt.Println("generate Menu successful") } // 拷贝 leetcode 目录下的题解 README 文件至第四章对应文件夹中 func copyLackFile() { - solutionIds, soName, _ := LoadSolutionsDir() - _, ch4Ids := LoadChapterFourDir() + solutionIds, soName, _ := util.LoadSolutionsDir() + _, ch4Ids := util.LoadChapterFourDir() needCopy := []string{} for i := 0; i < len(solutionIds); i++ { - if BinarySearch(ch4Ids, solutionIds[i]) == -1 { + if util.BinarySearch(ch4Ids, solutionIds[i]) == -1 { needCopy = append(needCopy, soName[i]) } } @@ -293,12 +295,12 @@ func copyLackFile() { if err != nil { fmt.Println(err) } - err = os.MkdirAll(fmt.Sprintf("../website/content/ChapterFour/%v", GetChpaterFourFileNum(tmp)), os.ModePerm) + err = os.MkdirAll(fmt.Sprintf("../website/content/ChapterFour/%v", util.GetChpaterFourFileNum(tmp)), os.ModePerm) if err != nil { fmt.Println(err) } - CopyFile(fmt.Sprintf("../website/content/ChapterFour/%v/%v.md", GetChpaterFourFileNum(tmp), needCopy[i]), fmt.Sprintf("../leetcode/%v/README.md", needCopy[i])) - CopyFile(fmt.Sprintf("../website/content/ChapterFour/%v/_index.md", GetChpaterFourFileNum(tmp)), "./template/collapseSection.md") + util.CopyFile(fmt.Sprintf("../website/content/ChapterFour/%v/%v.md", util.GetChpaterFourFileNum(tmp), needCopy[i]), fmt.Sprintf("../leetcode/%v/README.md", needCopy[i])) + util.CopyFile(fmt.Sprintf("../website/content/ChapterFour/%v/_index.md", util.GetChpaterFourFileNum(tmp)), "./template/collapseSection.md") } } } else { diff --git a/ctl/statistic.go b/ctl/statistic.go index 1541a842a..20b84ccb9 100644 --- a/ctl/statistic.go +++ b/ctl/statistic.go @@ -2,16 +2,19 @@ package main import ( "sort" + + m "github.com/halfrost/LeetCode-Go/ctl/models" + "github.com/halfrost/LeetCode-Go/ctl/util" ) -func statisticalData(problemsMap map[int]StatStatusPairs, solutionIds []int) (easyTotal, mediumTotal, hardTotal, optimizingEasy, optimizingMedium, optimizingHard int32, optimizingIds []int) { +func statisticalData(problemsMap map[int]m.StatStatusPairs, solutionIds []int) (easyTotal, mediumTotal, hardTotal, optimizingEasy, optimizingMedium, optimizingHard int32, optimizingIds []int) { easyTotal, mediumTotal, hardTotal, optimizingEasy, optimizingMedium, optimizingHard, optimizingIds = 0, 0, 0, 0, 0, 0, []int{} for _, v := range problemsMap { - switch DifficultyMap[v.Difficulty.Level] { + switch m.DifficultyMap[v.Difficulty.Level] { case "Easy": { easyTotal++ - if v.Status == "ac" && BinarySearch(solutionIds, int(v.Stat.FrontendQuestionID)) == -1 { + if v.Status == "ac" && util.BinarySearch(solutionIds, int(v.Stat.FrontendQuestionID)) == -1 { optimizingEasy++ optimizingIds = append(optimizingIds, int(v.Stat.FrontendQuestionID)) } @@ -19,7 +22,7 @@ func statisticalData(problemsMap map[int]StatStatusPairs, solutionIds []int) (ea case "Medium": { mediumTotal++ - if v.Status == "ac" && BinarySearch(solutionIds, int(v.Stat.FrontendQuestionID)) == -1 { + if v.Status == "ac" && util.BinarySearch(solutionIds, int(v.Stat.FrontendQuestionID)) == -1 { optimizingMedium++ optimizingIds = append(optimizingIds, int(v.Stat.FrontendQuestionID)) } @@ -27,7 +30,7 @@ func statisticalData(problemsMap map[int]StatStatusPairs, solutionIds []int) (ea case "Hard": { hardTotal++ - if v.Status == "ac" && BinarySearch(solutionIds, int(v.Stat.FrontendQuestionID)) == -1 { + if v.Status == "ac" && util.BinarySearch(solutionIds, int(v.Stat.FrontendQuestionID)) == -1 { optimizingHard++ optimizingIds = append(optimizingIds, int(v.Stat.FrontendQuestionID)) } diff --git a/ctl/template_render.go b/ctl/template_render.go index ce6875b17..01c65f28f 100644 --- a/ctl/template_render.go +++ b/ctl/template_render.go @@ -6,9 +6,12 @@ import ( "html/template" "io/ioutil" "os" + + m "github.com/halfrost/LeetCode-Go/ctl/models" + "github.com/halfrost/LeetCode-Go/ctl/util" ) -func makeReadmeFile(mdrows Mdrows) { +func makeReadmeFile(mdrows m.Mdrows) { file := "./README.md" os.Remove(file) var b bytes.Buffer @@ -18,7 +21,7 @@ func makeReadmeFile(mdrows Mdrows) { fmt.Println(err) } // 保存 README.md 文件 - WriteFile(file, b.Bytes()) + util.WriteFile(file, b.Bytes()) } func readTMPL(path string) string { diff --git a/ctl/util/go.mod b/ctl/util/go.mod new file mode 100644 index 000000000..6127aeea8 --- /dev/null +++ b/ctl/util/go.mod @@ -0,0 +1,3 @@ +module github.com/halfrost/LeetCode-Go/ctl/util + +go 1.19 diff --git a/ctl/util.go b/ctl/util/util.go similarity index 99% rename from ctl/util.go rename to ctl/util/util.go index e0efef9be..4fcf5b025 100644 --- a/ctl/util.go +++ b/ctl/util/util.go @@ -1,4 +1,4 @@ -package main +package util import ( "bufio" diff --git a/go.mod b/go.mod index 7ca2e4f7a..153b8e0df 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,14 @@ replace github.com/halfrost/LeetCode-Go/structures => ./structures replace github.com/halfrost/LeetCode-Go/template => ./template +replace github.com/halfrost/LeetCode-Go/ctl/util => ./ctl/util + +replace github.com/halfrost/LeetCode-Go/ctl/models => ./ctl/models + require ( github.com/BurntSushi/toml v1.2.0 + github.com/halfrost/LeetCode-Go/ctl/models v0.0.0-20220910225043-e3bb5aff34d0 + github.com/halfrost/LeetCode-Go/ctl/util v0.0.0-20220910225043-e3bb5aff34d0 github.com/halfrost/LeetCode-Go/structures v0.0.0-20220910233101-aa0e2c897b18 github.com/halfrost/LeetCode-Go/template v0.0.0-20220910233504-e2a72e6212ce github.com/mozillazg/request v0.8.0 diff --git a/template/CLRUCache.go b/template/CLRUCache.go index 03b5115c6..9738fb86e 100644 --- a/template/CLRUCache.go +++ b/template/CLRUCache.go @@ -132,7 +132,7 @@ func (c *CLRUCache) worker() { for { select { case el, ok := <-c.movePairs: - if ok == false { + if !ok { goto clean } if c.doMove(el) && c.list.Len() > c.cap {