5
5
"fmt"
6
6
"log"
7
7
"os"
8
- "path"
8
+ "path/filepath "
9
9
"regexp"
10
10
"strconv"
11
11
"strings"
@@ -102,14 +102,14 @@ func (d difficultyStrType) Str() (s string) {
102
102
return
103
103
}
104
104
105
- func (question questionType ) SaveContent () {
105
+ func (question * questionType ) SaveContent () {
106
106
if question .TitleSlug != "" {
107
107
filePutContents (question .getFilePath ("README.md" ), question .getDescContent ())
108
108
question .saveMysqlSchemas ()
109
109
}
110
110
}
111
111
112
- func (question questionType ) getDescContent () []byte {
112
+ func (question * questionType ) getDescContent () []byte {
113
113
var buf bytes.Buffer
114
114
buf .WriteString (authInfo ("description" ))
115
115
buf .WriteString (question .getNavigation ())
@@ -127,7 +127,7 @@ func (question questionType) getDescContent() []byte {
127
127
return buf .Bytes ()
128
128
}
129
129
130
- func (question questionType ) getNavigation () string {
130
+ func (question * questionType ) getNavigation () string {
131
131
nav , pre , next := "\n %s\n %s\n %s\n " , "< Previous" , "Next >"
132
132
problems := ProblemsAll ().StatStatusPairs
133
133
if questionId , err := strconv .Atoi (question .QuestionId ); err == nil {
@@ -147,7 +147,7 @@ func (question questionType) getNavigation() string {
147
147
return fmt .Sprintf (nav , pre , strings .Repeat (" " , 16 ), next )
148
148
}
149
149
150
- func (question questionType ) getTopicTags () []byte {
150
+ func (question * questionType ) getTopicTags () []byte {
151
151
tags := question .TopicTags
152
152
var buf bytes.Buffer
153
153
if len (tags ) > 0 {
@@ -160,12 +160,12 @@ func (question questionType) getTopicTags() []byte {
160
160
return buf .Bytes ()
161
161
}
162
162
163
- func (question questionType ) GetSimilarQuestion () (sq []similarQuestionType ) {
163
+ func (question * questionType ) GetSimilarQuestion () (sq []similarQuestionType ) {
164
164
jsonDecode ([]byte (question .SimilarQuestions ), & sq )
165
165
return
166
166
}
167
167
168
- func (question questionType ) getSimilarQuestion () []byte {
168
+ func (question * questionType ) getSimilarQuestion () []byte {
169
169
sq := question .GetSimilarQuestion ()
170
170
var buf bytes.Buffer
171
171
if len (sq ) > 0 {
@@ -178,7 +178,7 @@ func (question questionType) getSimilarQuestion() []byte {
178
178
return buf .Bytes ()
179
179
}
180
180
181
- func (question questionType ) getHints () []byte {
181
+ func (question * questionType ) getHints () []byte {
182
182
hints := question .Hints
183
183
var buf bytes.Buffer
184
184
if len (hints ) > 0 {
@@ -190,29 +190,29 @@ func (question questionType) getHints() []byte {
190
190
return buf .Bytes ()
191
191
}
192
192
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 )
195
195
}
196
196
197
- func (question questionType ) TitleSnake () string {
197
+ func (question * questionType ) TitleSnake () string {
198
198
return slugToSnake (question .TitleSlug )
199
199
}
200
200
201
- func (question questionType ) PackageName () string {
201
+ func (question * questionType ) PackageName () string {
202
202
snake := question .TitleSnake ()
203
203
if snake != "" && unicode .IsNumber (rune (snake [0 ])) {
204
204
snake = "p_" + snake
205
205
}
206
206
return snake
207
207
}
208
208
209
- func (question questionType ) SaveCodeSnippet () {
209
+ func (question * questionType ) SaveCodeSnippet () {
210
210
if isLangMySQL (question .TitleSlug ) {
211
211
filePutContents (question .getFilePath (question .TitleSnake ()+ ".sql" ), []byte ("# Write your MySQL query statement below\n " ))
212
212
}
213
213
langSupport := [... ]struct {
214
214
slug string
215
- handle func (questionType , codeSnippetsType )
215
+ handle func (* questionType , codeSnippetsType )
216
216
}{
217
217
{"golang" , handleCodeGolang },
218
218
{"python3" , handleCodePython },
@@ -234,23 +234,23 @@ func (question questionType) SaveCodeSnippet() {
234
234
}
235
235
}
236
236
237
- func (question questionType ) saveCodeContent (content , ext string , permX ... bool ) {
237
+ func (question * questionType ) saveCodeContent (content , ext string , permX ... bool ) {
238
238
filePath := question .getFilePath (question .TitleSnake () + ext )
239
239
filePutContents (filePath , []byte (content ))
240
240
if len (permX ) > 0 && permX [0 ] == true {
241
241
_ = os .Chmod (filePath , 0755 )
242
242
}
243
243
}
244
244
245
- func (question questionType ) saveMysqlSchemas () {
245
+ func (question * questionType ) saveMysqlSchemas () {
246
246
var buf bytes.Buffer
247
247
for _ , s := range question .MysqlSchemas {
248
248
buf .WriteString (s + ";\n " )
249
249
}
250
250
filePutContents (question .getFilePath ("mysql_schemas.sql" ), buf .Bytes ())
251
251
}
252
252
253
- func handleCodeGolang (question questionType , code codeSnippetsType ) {
253
+ func handleCodeGolang (question * questionType , code codeSnippetsType ) {
254
254
content := fmt .Sprintf ("package %s\n \n " , question .PackageName ())
255
255
content += code .Code + "\n "
256
256
question .saveCodeContent (content , ".go" )
@@ -272,15 +272,15 @@ func handleCodeGolang(question questionType, code codeSnippetsType) {
272
272
}
273
273
}
274
274
275
- func handleCodeBash (question questionType , code codeSnippetsType ) {
275
+ func handleCodeBash (question * questionType , code codeSnippetsType ) {
276
276
question .saveCodeContent ("#!/usr/bin/env bash\n \n " + code .Code , ".bash" , true )
277
277
}
278
278
279
- func handleCodePython (question questionType , code codeSnippetsType ) {
279
+ func handleCodePython (question * questionType , code codeSnippetsType ) {
280
280
question .saveCodeContent ("#!/usr/bin/env python\n \n " + code .Code , ".py" , true )
281
281
}
282
282
283
- func handleCodeSQL (question questionType , code codeSnippetsType ) {
283
+ func handleCodeSQL (question * questionType , code codeSnippetsType ) {
284
284
question .saveCodeContent (code .Code , ".sql" )
285
285
question .saveMysqlSchemas ()
286
286
}
0 commit comments