@@ -9,9 +9,10 @@ import (
9
9
"io/ioutil"
10
10
"os"
11
11
"path/filepath"
12
- "reflect"
13
12
"regexp"
14
13
"strings"
14
+
15
+ "github.com/astaxie/beego/utils"
15
16
)
16
17
17
18
var (
@@ -144,7 +145,7 @@ func getTplDeep(root, file, parent string, t *template.Template) (*template.Temp
144
145
} else {
145
146
fileabspath = filepath .Join (root , file )
146
147
}
147
- if e , _ := FileExists (fileabspath ); ! e {
148
+ if e := utils . FileExists (fileabspath ); ! e {
148
149
panic ("can't find template file" + file )
149
150
}
150
151
data , err := ioutil .ReadFile (fileabspath )
@@ -238,156 +239,3 @@ func _getTemplate(t0 *template.Template, root string, submods [][]string, others
238
239
}
239
240
return
240
241
}
241
-
242
- // go1.2 added template funcs. begin
243
- var (
244
- errBadComparisonType = errors .New ("invalid type for comparison" )
245
- errBadComparison = errors .New ("incompatible types for comparison" )
246
- errNoComparison = errors .New ("missing argument for comparison" )
247
- )
248
-
249
- type kind int
250
-
251
- const (
252
- invalidKind kind = iota
253
- boolKind
254
- complexKind
255
- intKind
256
- floatKind
257
- integerKind
258
- stringKind
259
- uintKind
260
- )
261
-
262
- func basicKind (v reflect.Value ) (kind , error ) {
263
- switch v .Kind () {
264
- case reflect .Bool :
265
- return boolKind , nil
266
- case reflect .Int , reflect .Int8 , reflect .Int16 , reflect .Int32 , reflect .Int64 :
267
- return intKind , nil
268
- case reflect .Uint , reflect .Uint8 , reflect .Uint16 , reflect .Uint32 , reflect .Uint64 , reflect .Uintptr :
269
- return uintKind , nil
270
- case reflect .Float32 , reflect .Float64 :
271
- return floatKind , nil
272
- case reflect .Complex64 , reflect .Complex128 :
273
- return complexKind , nil
274
- case reflect .String :
275
- return stringKind , nil
276
- }
277
- return invalidKind , errBadComparisonType
278
- }
279
-
280
- // eq evaluates the comparison a == b || a == c || ...
281
- func eq (arg1 interface {}, arg2 ... interface {}) (bool , error ) {
282
- v1 := reflect .ValueOf (arg1 )
283
- k1 , err := basicKind (v1 )
284
- if err != nil {
285
- return false , err
286
- }
287
- if len (arg2 ) == 0 {
288
- return false , errNoComparison
289
- }
290
- for _ , arg := range arg2 {
291
- v2 := reflect .ValueOf (arg )
292
- k2 , err := basicKind (v2 )
293
- if err != nil {
294
- return false , err
295
- }
296
- if k1 != k2 {
297
- return false , errBadComparison
298
- }
299
- truth := false
300
- switch k1 {
301
- case boolKind :
302
- truth = v1 .Bool () == v2 .Bool ()
303
- case complexKind :
304
- truth = v1 .Complex () == v2 .Complex ()
305
- case floatKind :
306
- truth = v1 .Float () == v2 .Float ()
307
- case intKind :
308
- truth = v1 .Int () == v2 .Int ()
309
- case stringKind :
310
- truth = v1 .String () == v2 .String ()
311
- case uintKind :
312
- truth = v1 .Uint () == v2 .Uint ()
313
- default :
314
- panic ("invalid kind" )
315
- }
316
- if truth {
317
- return true , nil
318
- }
319
- }
320
- return false , nil
321
- }
322
-
323
- // ne evaluates the comparison a != b.
324
- func ne (arg1 , arg2 interface {}) (bool , error ) {
325
- // != is the inverse of ==.
326
- equal , err := eq (arg1 , arg2 )
327
- return ! equal , err
328
- }
329
-
330
- // lt evaluates the comparison a < b.
331
- func lt (arg1 , arg2 interface {}) (bool , error ) {
332
- v1 := reflect .ValueOf (arg1 )
333
- k1 , err := basicKind (v1 )
334
- if err != nil {
335
- return false , err
336
- }
337
- v2 := reflect .ValueOf (arg2 )
338
- k2 , err := basicKind (v2 )
339
- if err != nil {
340
- return false , err
341
- }
342
- if k1 != k2 {
343
- return false , errBadComparison
344
- }
345
- truth := false
346
- switch k1 {
347
- case boolKind , complexKind :
348
- return false , errBadComparisonType
349
- case floatKind :
350
- truth = v1 .Float () < v2 .Float ()
351
- case intKind :
352
- truth = v1 .Int () < v2 .Int ()
353
- case stringKind :
354
- truth = v1 .String () < v2 .String ()
355
- case uintKind :
356
- truth = v1 .Uint () < v2 .Uint ()
357
- default :
358
- panic ("invalid kind" )
359
- }
360
- return truth , nil
361
- }
362
-
363
- // le evaluates the comparison <= b.
364
- func le (arg1 , arg2 interface {}) (bool , error ) {
365
- // <= is < or ==.
366
- lessThan , err := lt (arg1 , arg2 )
367
- if lessThan || err != nil {
368
- return lessThan , err
369
- }
370
- return eq (arg1 , arg2 )
371
- }
372
-
373
- // gt evaluates the comparison a > b.
374
- func gt (arg1 , arg2 interface {}) (bool , error ) {
375
- // > is the inverse of <=.
376
- lessOrEqual , err := le (arg1 , arg2 )
377
- if err != nil {
378
- return false , err
379
- }
380
- return ! lessOrEqual , nil
381
- }
382
-
383
- // ge evaluates the comparison a >= b.
384
- func ge (arg1 , arg2 interface {}) (bool , error ) {
385
- // >= is the inverse of <.
386
- lessThan , err := lt (arg1 , arg2 )
387
- if err != nil {
388
- return false , err
389
- }
390
- return ! lessThan , nil
391
- }
392
-
393
- // go1.2 added template funcs. end
0 commit comments