-
Notifications
You must be signed in to change notification settings - Fork 0
/
New.go
740 lines (644 loc) · 28.1 KB
/
New.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
package stonelizard
import (
"os"
"fmt"
"regexp"
"errors"
"strings"
"reflect"
"strconv"
)
func New(svcs ...EndPointHandler) (*Service, error) {
var resp *Service
var svc EndPointHandler
var svcElem EndPointHandler
// var svcRecv reflect.Value
var consumes string
var svcConsumes string
var produces string
var svcProduces string
var allowGzip string
var enableCORS string
var proto []string
var svcProto []string
var svcRoot string
var i, j, k int
var typ reflect.Type
var typPtr reflect.Type
var pt []reflect.Type
var fld reflect.StructField
var method reflect.Method
var parmcount int
var httpmethod, path string
var methodName string
var tk string
var ok bool
var re string
var reAllOps string
var reComp *regexp.Regexp
var c rune
var err error
var stmp string
var SwaggerParameter *SwaggerParameterT
var swaggerParameters []SwaggerParameterT
var swaggerInfo SwaggerInfoT
var swaggerLicense SwaggerLicenseT
var swaggerContact SwaggerContactT
var globalDataCount int
var responses map[string]SwaggerResponseT
var fldType reflect.Type
var doc string
var description *string
var headers []string
var query []string
var optIndex map[string]int
var HdrNew, HdrOld string
var MatchedOpsIndex int
var postFields []string
var postField string
var postdata string
// var accesstype uint8
var parmnames []string
var callByRef bool
var mixedProto bool
var mixedEnc bool
var pos int
// var webSocketOps map[string]*SwaggerWSOperationT
// var webSocketSpec *SwaggerWSOperationT
var static string
var exported string
var exportedValue []reflect.Value
var this reflect.Value
var num int
var mod, out, outvar string
var extAuth ExtAuthT
var tags [][]string
var tag []string
var propParm *SwaggerParameterT
var propField reflect.StructField
Goose.New.Logf(6,"Initializing services: %#v", svcs)
for _, svc = range svcs {
// Goose.New.Logf(0,"-----------")
// Goose.New.Logf(6,"Elem: %#v (Kind: %#v)", reflect.ValueOf(svc), reflect.ValueOf(svc).Kind())
// Goose.New.Logf(0,"-----------")
if reflect.ValueOf(svc).Kind() == reflect.Ptr {
// Goose.New.Logf(6,"Elem: %#v", reflect.ValueOf(svc).Elem())
svcElem = reflect.ValueOf(svc).Elem().Interface().(EndPointHandler)
// Goose.New.Logf(6,"Elem type: %s, ptr type: %s", reflect.TypeOf(svcElem), reflect.TypeOf(svc))
} else {
svcElem = svc
// Goose.New.Logf(6,"Elem type: %s", reflect.TypeOf(svcElem))
}
// The first endpoint handler MUST have a config defined, otherwise we'll ignore endpoint handlers until we find one which provides a configuration
if resp == nil {
resp, err = initSvc(svcElem)
if err != nil {
return nil, err
}
if resp == nil {
continue // If we still don't have a config defined and the endpoint handler has no config defined it WILL BE IGNORED!!!
}
resp.SecureStatic = map[string]string{}
resp.PlainStatic = map[string]string{}
}
typ = reflect.ValueOf(svcElem).Type()
if typ.Kind()==reflect.Ptr {
typPtr = typ
typ = typ.Elem()
} else {
typPtr = reflect.PtrTo(typ)
}
if resp.Swagger == nil {
// for i=0; (i<typ.NumField()) && (globalDataCount<4); i++ {
for i=0; i < typ.NumField(); i++ {
if stnlzrd, ok := fld.Tag.Lookup("stonelizard") ; ok && stnlzrd == "ignore" {
continue
}
fld = typ.Field(i)
if svcRoot == "" {
svcRoot = fld.Tag.Get("root")
if svcRoot != "" {
svcConsumes = fld.Tag.Get("consumes")
svcProduces = fld.Tag.Get("produces")
allowGzip = fld.Tag.Get("allowGzip")
enableCORS = fld.Tag.Get("enableCORS")
resp.SwaggerPath = fld.Tag.Get("swagger")
if resp.SwaggerPath == "root" {
resp.SwaggerPath = svcRoot
}
if fld.Tag.Get("proto") != "" {
svcProto = strings.Split(strings.ToLower(strings.Trim(fld.Tag.Get("proto")," ")),",")
_, _, err = validateProtoList(svcProto)
if err != nil {
Goose.New.Logf(1,"Error validating global protocol list: %s", err)
return nil, err
}
} else {
svcProto = []string{"https"}
}
Goose.New.Logf(3,"Access tag: %s", fld.Tag.Get("access"))
if fld.Tag.Get("access") != "" {
switch strings.ToLower(strings.Trim(fld.Tag.Get("access")," ")) {
case "none":
resp.Access = AccessNone
case "auth":
resp.Access = AccessAuth
case "authinfo":
resp.Access = AccessAuthInfo
case "verifyauth":
resp.Access = AccessVerifyAuth
case "verifyauthinfo":
resp.Access = AccessVerifyAuthInfo
case "info":
resp.Access = AccessInfo
}
Goose.New.Logf(3,"Custom access type: %d", resp.Access)
} else {
resp.Access = AccessAuthInfo
Goose.New.Logf(3,"Default access type: %d", resp.Access)
}
globalDataCount++
}
}
if swaggerInfo.Title == "" {
stmp = fld.Tag.Get("title")
if stmp != "" {
swaggerInfo.Title = stmp
swaggerInfo.Description = fld.Tag.Get("description")
swaggerInfo.TermsOfService = fld.Tag.Get("tos")
swaggerInfo.Version = fld.Tag.Get("version")
globalDataCount++
}
}
if swaggerContact.Name == "" {
stmp = fld.Tag.Get("contact")
if stmp != "" {
swaggerContact.Name = stmp
swaggerContact.Url = fld.Tag.Get("url")
swaggerContact.Email = fld.Tag.Get("email")
globalDataCount++
}
}
if swaggerLicense.Name == "" {
stmp = fld.Tag.Get("license")
if stmp != "" {
swaggerLicense.Name = stmp
swaggerLicense.Url = fld.Tag.Get("url")
globalDataCount++
}
}
Goose.New.Logf(2,"Is %s a module?", fld.Name)
if fld.Type == ModType {
Goose.New.Logf(2,"Module %s found", fld.Name)
if swaggerInfo.XModules == nil {
Goose.New.Logf(2,"Module %s Init", fld.Name)
swaggerInfo.XModules = map[string]map[string]*SwaggerSchemaT{}
}
swaggerInfo.XModules[fld.Name] = map[string]*SwaggerSchemaT{}
tags = tagRE.FindAllStringSubmatch(string(fld.Tag),-1)
for _, tag = range tags {
Goose.New.Logf(2,"Prop %s: %s", tag[1], tag[2])
propField, ok = typ.FieldByName(tag[2])
if !ok {
Goose.New.Logf(1,"Error: %s", ErrorUndefPropType)
return nil, ErrorUndefPropType
}
propParm, err = GetSwaggerType(propField.Type)
if err != nil {
Goose.New.Logf(1,"Error checking type of module: %s",err)
return nil, err
}
swaggerInfo.XModules[fld.Name][tag[1]] = propParm.Schema
}
}
}
swaggerInfo.Contact = swaggerContact
swaggerInfo.License = swaggerLicense
svcRoot = strings.Trim(strings.Trim(svcRoot," "),"/") + "/"
svcConsumes = strings.Trim(svcConsumes," ")
svcProduces = strings.Trim(svcProduces," ")
if (svcRoot=="") || (svcConsumes=="") || (svcProduces=="") {
Goose.New.Logf(1,"Err: %s",ErrorNoRoot)
return nil, ErrorNoRoot
}
hostport := strings.Split(resp.Config.ListenAddress(),":")
if hostport[0] == "" {
// Goose.New.Logf(0,"Stonelizard hostport %s", hostport[0])
if resp.Authorizer == nil || isPlain(svcProto) {
hostport[0] = "0.0.0.0"
} else {
authdns := resp.Authorizer.GetDNSNames()
if len(authdns) > 0 {
if len(strings.Split(authdns[0],".")) == 1 {
hostport[0] = resp.Authorizer.GetServerCert().IPAddresses[0].String()
} else {
hostport[0] = authdns[0]
}
} else {
hostport[0] = "0.0.0.0"
}
}
}
resp.Swagger = &SwaggerT{
Version: "2.0",
Info: swaggerInfo,
Host: strings.Join(hostport,":"),
BasePath: "/" + svcRoot[:len(svcRoot)-1],
Schemes: svcProto,
Consumes: []string{svcConsumes},
Produces: []string{svcProduces},
Paths: map[string]SwaggerPathT{},
Definitions: map[string]SwaggerSchemaT{},
}
resp.Proto = svcProto
Goose.New.Logf(6,"enableCORS: [%s]",enableCORS)
if enableCORS != "" {
resp.EnableCORS, err = strconv.ParseBool(enableCORS)
Goose.New.Logf(6,"resp.EnableCORS: %#v",resp.EnableCORS)
if err != nil {
Goose.New.Logf(1,"Err: %s",ErrorServiceSyntax)
return nil, ErrorServiceSyntax
}
}
Goose.New.Logf(6,"allowGzip: [%s]",allowGzip)
if allowGzip != "" {
resp.AllowGzip, err = strconv.ParseBool(allowGzip)
Goose.New.Logf(6,"resp.AllowGzip: %#v",resp.AllowGzip)
if err != nil {
Goose.New.Logf(1,"Err: %s",ErrorServiceSyntax)
return nil, ErrorServiceSyntax
}
}
}
for i=0; i<typ.NumField(); i++ {
fld = typ.Field(i)
httpmethod = fld.Tag.Get("method")
if httpmethod != "" {
methodName = strings.ToUpper(fld.Name[:1]) + fld.Name[1:]
callByRef = false
if method, ok = typ.MethodByName(methodName); !ok {
if method, ok = typPtr.MethodByName(methodName); !ok {
Goose.New.Logf(5,"|methods|=%d",typ.NumMethod())
Goose.New.Logf(5,"type=%s.%s",typ.PkgPath(),typ.Name())
for j=0; j<typ.NumMethod(); j++ {
mt := typ.Method(j)
Goose.New.Logf(5,"%d: %s",j,mt.Name)
}
Goose.New.Logf(5,"*|methods|=%d",typPtr.NumMethod())
Goose.New.Logf(5,"*type=%s.%s",typPtr.PkgPath(),typPtr.Name())
for j=0; j<typPtr.NumMethod(); j++ {
mt := typPtr.Method(j)
Goose.New.Logf(5,"%d: *%s",j,mt.Name)
}
Goose.New.Logf(1,"Method not found: %s, Data: %#v",methodName,typ)
return nil, errors.New(fmt.Sprintf("Method not found: %s",methodName))
} else {
Goose.New.Logf(2,"Pointer method found, type of svcElem: %s",reflect.TypeOf(svcElem))
callByRef = true
Goose.New.Logf(5,"Pointer method found: %s",methodName)
}
}
path = fld.Tag.Get("path")
if _, ok := resp.Swagger.Paths[path]; !ok {
resp.Swagger.Paths[path] = SwaggerPathT{}
// } else if _, ok := resp.Swagger.Paths[path][httpmethod]; !ok {
// resp.Swagger.Paths[path][httpmethod] = SwaggerOperationT{}
}
swaggerParameters = []SwaggerParameterT{}
// re = "^" + strings.ToUpper(httpmethod) + ":/" + svcRoot
re = svcRoot
parmcount = 0
parmnames = []string{}
for _, tk = range strings.Split(strings.Trim(path,"/"),"/") {
if tk!="" {
if (tk[0]=='{') && (tk[len(tk)-1]=='}') {
re += "([^/]+)/"
parmcount++
SwaggerParameter, err = GetSwaggerType(method.Type.In(parmcount))
if err != nil {
return nil, err
}
if SwaggerParameter == nil {
return nil, ErrorInvalidNilParam
}
// if (SwaggerParameter.Items != nil) || (SwaggerParameter.CollectionFormat!="") || (SwaggerParameter.Schema.Required != nil) {
if (SwaggerParameter.CollectionFormat!="") || (SwaggerParameter.Schema.Required != nil) {
Goose.New.Logf(1,"%s on %s: %s",ErrorInvalidParameterType,methodName,tk[1:len(tk)-1])
return nil, ErrorInvalidParameterType
}
doc = fld.Tag.Get(tk[1:len(tk)-1])
if doc != "" {
description = new(string)
(*description) = doc
} else {
description = SwaggerParameter.Schema.Description
if description == nil {
description = new(string)
}
}
xkeytype := ""
if SwaggerParameter.Schema != nil {
xkeytype = SwaggerParameter.Schema.XKeyType
}
swaggerParameters = append(
swaggerParameters,
SwaggerParameterT{
Name: tk[1:len(tk)-1],
In: "path",
Required: true,
Type: SwaggerParameter.Schema.Type,
XKeyType: xkeytype,
Description: *description,
Format: SwaggerParameter.Format,
})
parmnames = append(parmnames,tk[1:len(tk)-1])
} else if (tk[0]!='{') && (tk[len(tk)-1]!='}') {
for _, c = range tk {
re += fmt.Sprintf("\\x{%x}",c)
}
re += "/"
} else {
return nil, errors.New("syntax error at " + tk)
}
}
}
if resp.Svc == nil {
resp.Svc = []UrlNode{}
}
re += "{0,1}$"
Goose.New.Logf(4,"Service " + strings.ToUpper(httpmethod) + ":/" + svcRoot + path + ", RE=" + re )
query, parmcount, _, swaggerParameters, err = ParseFieldList("query", parmcount, fld, method, methodName, swaggerParameters)
if err != nil {
return nil, err
}
headers, parmcount, _, swaggerParameters, err = ParseFieldList("header", parmcount, fld, method, methodName, swaggerParameters)
if err != nil {
return nil, err
}
parmnames = append(parmnames, query...)
parmnames = append(parmnames, headers...)
postdata = fld.Tag.Get("postdata")
if postdata != "" {
// Body fields definitions
postFields = strings.Split(postdata,",")
pt = make([]reflect.Type,len(postFields))
for k, postField = range postFields {
parmcount++
pt[k] = method.Type.In(parmcount)
SwaggerParameter, err = GetSwaggerType(pt[k])
if err != nil {
return nil, err
}
if SwaggerParameter == nil {
return nil, ErrorInvalidNilParam
}
doc = fld.Tag.Get(postField)
if doc != "" {
SwaggerParameter.Schema.Description = new(string)
(*SwaggerParameter.Schema.Description) = doc
}
parmnames = append(parmnames, postField)
SwaggerParameter.Name = postField
SwaggerParameter.In = "body"
SwaggerParameter.Required = true
swaggerParameters = append(swaggerParameters,*SwaggerParameter)
}
/*
if resp.Access == AccessAuthInfo || resp.Access == AccessVerifyAuthInfo {
parmcount++
}
if (parmcount+len(postFields)+1) != method.Type.NumIn() {
return nil, errors.New("Wrong parameter count (with post) at method " + methodName)
}
*/
} else {
pt = nil
}
num = method.Type.NumIn()
if resp.Access == AccessAuthInfo || resp.Access == AccessVerifyAuthInfo || resp.Access == AccessInfo {
if (parmcount+1) != num {
parmcount++
if (parmcount != (num-3)) || (num<2) || (method.Type.In(num-2).Kind()!=reflect.String) || (method.Type.In(num-1).Kind()!=reflect.String) {
return nil, errors.New(fmt.Sprintf("Wrong parameter (with info) count at method %s, got %d want %d",methodName,parmcount,num))
}
}
} else {
if (parmcount+1) != num {
return nil, errors.New(fmt.Sprintf("Wrong parameter count at method %s, got %d want %d",methodName,parmcount,num))
}
}
Goose.New.Logf(5,"Registering: %s",re)
consumes = fld.Tag.Get("consumes")
Goose.New.Logf(2,"op:%s consumes: %s tag:%#v",methodName,consumes,fld.Tag)
if consumes == "" {
consumes = svcConsumes
}
produces = fld.Tag.Get("produces")
if produces == "" {
produces = svcProduces
}
if fld.Tag.Get("proto") != "" {
proto = strings.Split(strings.ToLower(strings.Trim(typ.Field(i).Tag.Get("proto")," ")),",")
mixedProto, mixedEnc, err = validateProtoList(proto)
if err != nil {
Goose.New.Logf(1,"Error validating global protocol list: %s", err)
return nil, err
}
if mixedProto {
Goose.New.Logf(1,"Error validating global protocol list: %s", ErrorMixedProtocol)
return nil, ErrorMixedProtocol
}
if mixedEnc {
Goose.New.Logf(2,"Warning validating global protocol list on operation %s: both plain and encrypted protocols selected", methodName)
}
} else {
mixedProto, _, _ = validateProtoList(svcProto)
if mixedProto {
Goose.New.Logf(2,"Warning using just the first global protocol on operation %s to prevent mixed use of http/https with ws/wss", methodName)
proto = []string{svcProto[0]}
} else {
proto = svcProto
}
}
responses, fldType, err = getResponses(fld, typ)
if err != nil {
return nil, err
}
mod = fld.Tag.Get("mod")
out = fld.Tag.Get("out")
outvar = fld.Tag.Get("outvar")
resp.Swagger.Paths[path][strings.ToLower(httpmethod)] = &SwaggerOperationT{
Schemes: proto,
OperationId: methodName,
Parameters: swaggerParameters,
Responses: responses,
Consumes: []string{consumes},
Produces: []string{produces},
XModule: mod,
XOutput: out,
XOutputVar: outvar,
}
/*
for _, prt := range proto {
if prt[0:2] == "ws" {
if fld.Tag.Get("in") == "" {
Goose.New.Logf(1,"Error %s getting operations of %s",ErrorMissingWebsocketInTagSyntax,methodName)
return nil, ErrorMissingWebsocketInTagSyntax
}
webSocketOps, err = getWebSocketOps(fld)
if err != nil {
return nil, err
}
// webSocketSpec, err = GetWebSocketSpec(fld, methodName, method)
// if err != nil {
// return nil, err
// }
}
}
*/
for _, prt := range proto {
rePrtMethod := strings.ToUpper("^" + prt + "\\+" + httpmethod + ":/")
Goose.New.Logf(2,"Registering marshalers: %s, %s",consumes,produces)
resp.MatchedOps[MatchedOpsIndex] = len(resp.Svc)
if re[0] == '/' {
re = re[1:]
}
reComp = regexp.MustCompile(rePrtMethod + re)
MatchedOpsIndex += reComp.NumSubexp() + 1
/*
switch strings.ToLower(fld.Tag.Get("access")) {
case "none": accesstype = AccessNone
case "auth": accesstype = AccessAuth
case "authinfo": accesstype = AccessAuthInfo
default: accesstype = AccessAuth
}
*/
pos = len(resp.Svc)
resp.Svc = append(resp.Svc,UrlNode{
Proto: []string{prt},
Path: path,
consumes: consumes,
produces: produces,
Headers: headers,
Query: query,
Body: postFields,
ParmNames: parmnames,
Handle: buildHandle(reflect.ValueOf(svc),callByRef,method,pt,resp.Access,proto[0][0] == 'w'),
// Access: resp.Access,
})
if prt[0:2] == "ws" { // if this is a web service handler
resp.Svc[pos].WSocketOperations, resp.Swagger.Paths[path][strings.ToLower(httpmethod)].XWSOperations, err = buildSubHandles(fldType,strings.Split(produces,","),strings.Split(consumes,","))
if err != nil {
return nil, err
}
resp.Swagger.Paths[path][strings.ToLower(httpmethod)].XWSEvents, err = GetWebSocketEventSpec(fld, methodName, method)
if err != nil {
return nil, err
}
}
reAllOps += "|(" + rePrtMethod + re + ")"
Goose.New.Logf(6,"Partial Matcher for %s is %s",path,reAllOps)
if resp.EnableCORS {
index := len(resp.Svc)
if optIndex == nil {
optIndex = map[string]int{path:index}
} else if index, ok = optIndex[path]; ok {
for _, HdrNew = range headers {
for _, HdrOld = range resp.Svc[index].Headers {
if HdrOld == HdrNew {
break
}
}
if HdrOld != HdrNew {
resp.Svc[index].Headers = append(resp.Svc[index].Headers, HdrNew)
}
}
continue
} else {
optIndex[path] = len(resp.Svc)
}
reCORS := "^" + strings.ToUpper(prt) + "\\+OPTIONS:/" + re
resp.MatchedOps[MatchedOpsIndex] = len(resp.Svc)
reComp = regexp.MustCompile(reCORS)
MatchedOpsIndex += reComp.NumSubexp() + 1
resp.Svc = append(resp.Svc,UrlNode{
Path: path,
Headers: headers,
})
reAllOps += "|(" + reCORS + ")"
}
Goose.New.Logf(6,"Partial Matcher with options for %s is %s",path,reAllOps)
}
} else {
Goose.New.Logf(2,"Checking %s for static handlers",fld.Name)
static = fld.Tag.Get("path")
if static == "" {
continue
}
Goose.New.Logf(2,"Checking %s for static handlers has path %s", fld.Name, static)
exported = fld.Tag.Get("export")
if exported =="" {
continue
}
Goose.New.Logf(2,"Checking %s for static handlers exports %s", fld.Name, exported)
methodName = strings.ToUpper(fld.Name[:1]) + fld.Name[1:]
if method, ok = typ.MethodByName(methodName); !ok {
Goose.New.Logf(1,"Checking %s for static handlers for method %s not found", fld.Name, methodName)
continue
}
Goose.New.Logf(2,"Checking %s for static handlers has defined method", fld.Name)
this = reflect.ValueOf(svc)
if this.Kind() == reflect.Ptr {
this = this.Elem()
}
exportedValue = method.Func.Call([]reflect.Value{this})
if len(exportedValue) != 1 {
Goose.New.Logf(2,"Checking %s for static handlers has exportedValue %#v", fld.Name, exportedValue)
continue
}
switch e := exportedValue[0].Interface().(type) {
case string:
exported = strings.Replace(fmt.Sprintf("%s%s",e,exported),"/",string([]byte{os.PathSeparator}),-1)
Goose.New.Logf(2,"Checking %s for static handlers has full exported %s", fld.Name, exported)
default:
continue
}
proto = strings.Split(fld.Tag.Get("proto"),",")
if len(proto) == 0 || proto[0]=="" {
proto = svcProto
}
for _, p := range proto {
if p == "https" {
resp.SecureStatic[static] = exported
} else if p == "http" {
resp.PlainStatic[static] = exported
}
}
}
}
}
// Goose.New.Logf(6,"Operations matcher: %s\n",reAllOps[1:])
Goose.New.Logf(6,"Operations %#v\n",resp.Svc)
if len(reAllOps) > 0 {
resp.Matcher = regexp.MustCompile(reAllOps[1:]) // Cutting the leading '|'
} else {
resp.Matcher = regexp.MustCompile(reAllOps)
}
if extAuth, ok = resp.Authorizer.(ExtAuthT); ok {
resp.ch = make(chan ExtAuthorizeIn)
go extAuth.StartExtAuthorizer(resp.ch)
}
Goose.New.Logf(1,"Stonelizard service started...")
return resp, nil
}
func isPlain(proto []string) bool {
var p string
// Goose.New.Logf(0,"Stonelizard isPlain %#v", proto)
for _, p = range proto {
if p=="https" || p=="wss" {
// Goose.New.Logf(0,"Stonelizard isPlain -------> %#v", proto)
return false
}
}
return true
}