55 "fmt"
66 "log"
77 "os"
8- "path"
8+ "path/filepath "
99 "regexp"
1010 "strconv"
1111 "strings"
@@ -102,14 +102,14 @@ func (d difficultyStrType) Str() (s string) {
102102 return
103103}
104104
105- func (question questionType ) SaveContent () {
105+ func (question * questionType ) SaveContent () {
106106 if question .TitleSlug != "" {
107107 filePutContents (question .getFilePath ("README.md" ), question .getDescContent ())
108108 question .saveMysqlSchemas ()
109109 }
110110}
111111
112- func (question questionType ) getDescContent () []byte {
112+ func (question * questionType ) getDescContent () []byte {
113113 var buf bytes.Buffer
114114 buf .WriteString (authInfo ("description" ))
115115 buf .WriteString (question .getNavigation ())
@@ -127,7 +127,7 @@ func (question questionType) getDescContent() []byte {
127127 return buf .Bytes ()
128128}
129129
130- func (question questionType ) getNavigation () string {
130+ func (question * questionType ) getNavigation () string {
131131 nav , pre , next := "\n %s\n %s\n %s\n " , "< Previous" , "Next >"
132132 problems := ProblemsAll ().StatStatusPairs
133133 if questionId , err := strconv .Atoi (question .QuestionId ); err == nil {
@@ -147,7 +147,7 @@ func (question questionType) getNavigation() string {
147147 return fmt .Sprintf (nav , pre , strings .Repeat (" " , 16 ), next )
148148}
149149
150- func (question questionType ) getTopicTags () []byte {
150+ func (question * questionType ) getTopicTags () []byte {
151151 tags := question .TopicTags
152152 var buf bytes.Buffer
153153 if len (tags ) > 0 {
@@ -160,12 +160,12 @@ func (question questionType) getTopicTags() []byte {
160160 return buf .Bytes ()
161161}
162162
163- func (question questionType ) GetSimilarQuestion () (sq []similarQuestionType ) {
163+ func (question * questionType ) GetSimilarQuestion () (sq []similarQuestionType ) {
164164 jsonDecode ([]byte (question .SimilarQuestions ), & sq )
165165 return
166166}
167167
168- func (question questionType ) getSimilarQuestion () []byte {
168+ func (question * questionType ) getSimilarQuestion () []byte {
169169 sq := question .GetSimilarQuestion ()
170170 var buf bytes.Buffer
171171 if len (sq ) > 0 {
@@ -178,7 +178,7 @@ func (question questionType) getSimilarQuestion() []byte {
178178 return buf .Bytes ()
179179}
180180
181- func (question questionType ) getHints () []byte {
181+ func (question * questionType ) getHints () []byte {
182182 hints := question .Hints
183183 var buf bytes.Buffer
184184 if len (hints ) > 0 {
@@ -190,29 +190,29 @@ func (question questionType) getHints() []byte {
190190 return buf .Bytes ()
191191}
192192
193- func (question questionType ) getFilePath (filename string ) string {
194- return path .Join ("problems" , question .TitleSlug , filename )
193+ func (question * questionType ) getFilePath (filename string ) string {
194+ return filepath .Join ("problems" , question .TitleSlug , filename )
195195}
196196
197- func (question questionType ) TitleSnake () string {
197+ func (question * questionType ) TitleSnake () string {
198198 return slugToSnake (question .TitleSlug )
199199}
200200
201- func (question questionType ) PackageName () string {
201+ func (question * questionType ) PackageName () string {
202202 snake := question .TitleSnake ()
203203 if snake != "" && unicode .IsNumber (rune (snake [0 ])) {
204204 snake = "p_" + snake
205205 }
206206 return snake
207207}
208208
209- func (question questionType ) SaveCodeSnippet () {
209+ func (question * questionType ) SaveCodeSnippet () {
210210 if isLangMySQL (question .TitleSlug ) {
211211 filePutContents (question .getFilePath (question .TitleSnake ()+ ".sql" ), []byte ("# Write your MySQL query statement below\n " ))
212212 }
213213 langSupport := [... ]struct {
214214 slug string
215- handle func (questionType , codeSnippetsType )
215+ handle func (* questionType , codeSnippetsType )
216216 }{
217217 {"golang" , handleCodeGolang },
218218 {"python3" , handleCodePython },
@@ -234,23 +234,23 @@ func (question questionType) SaveCodeSnippet() {
234234 }
235235}
236236
237- func (question questionType ) saveCodeContent (content , ext string , permX ... bool ) {
237+ func (question * questionType ) saveCodeContent (content , ext string , permX ... bool ) {
238238 filePath := question .getFilePath (question .TitleSnake () + ext )
239239 filePutContents (filePath , []byte (content ))
240240 if len (permX ) > 0 && permX [0 ] == true {
241241 _ = os .Chmod (filePath , 0755 )
242242 }
243243}
244244
245- func (question questionType ) saveMysqlSchemas () {
245+ func (question * questionType ) saveMysqlSchemas () {
246246 var buf bytes.Buffer
247247 for _ , s := range question .MysqlSchemas {
248248 buf .WriteString (s + ";\n " )
249249 }
250250 filePutContents (question .getFilePath ("mysql_schemas.sql" ), buf .Bytes ())
251251}
252252
253- func handleCodeGolang (question questionType , code codeSnippetsType ) {
253+ func handleCodeGolang (question * questionType , code codeSnippetsType ) {
254254 content := fmt .Sprintf ("package %s\n \n " , question .PackageName ())
255255 content += code .Code + "\n "
256256 question .saveCodeContent (content , ".go" )
@@ -272,15 +272,15 @@ func handleCodeGolang(question questionType, code codeSnippetsType) {
272272 }
273273}
274274
275- func handleCodeBash (question questionType , code codeSnippetsType ) {
275+ func handleCodeBash (question * questionType , code codeSnippetsType ) {
276276 question .saveCodeContent ("#!/usr/bin/env bash\n \n " + code .Code , ".bash" , true )
277277}
278278
279- func handleCodePython (question questionType , code codeSnippetsType ) {
279+ func handleCodePython (question * questionType , code codeSnippetsType ) {
280280 question .saveCodeContent ("#!/usr/bin/env python\n \n " + code .Code , ".py" , true )
281281}
282282
283- func handleCodeSQL (question questionType , code codeSnippetsType ) {
283+ func handleCodeSQL (question * questionType , code codeSnippetsType ) {
284284 question .saveCodeContent (code .Code , ".sql" )
285285 question .saveMysqlSchemas ()
286286}
0 commit comments