Skip to content

Commit c81e869

Browse files
committed
✨ ⚡ Introducing RouteFn as a signature for documentation handlers to be defined by.
1 parent c90cefa commit c81e869

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

examples/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func main() {
1313
apiSetExternalDocs(&apiDoc)
1414
apiSetComponents(&apiDoc)
1515

16-
apiDoc.AttachRoutes([]interface{}{
16+
apiDoc.AttachRoutes([]docs.RouteFn{
1717
handleCreateUserRoute,
1818
handleGetUserRoute,
1919
})

routing.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ import (
66
"strings"
77
)
88

9-
type RegRoutes map[string]interface{}
9+
type (
10+
// RouteFn represents a typeFunc which needs to be satisfied in order to use default routes attaching method.
11+
RouteFn func(index int, oas *OAS)
1012

11-
func (o *OAS) AttachRoutes(fns []interface{}) {
13+
// RegRoutes represent a map of RouteFn's.
14+
// TODO: Will this get Deprecated?
15+
RegRoutes map[string]RouteFn
16+
)
17+
18+
func (o *OAS) AttachRoutes(fns []RouteFn) {
1219
for _, fn := range fns {
1320
fnDeclaration := runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name()
1421
fields := strings.SplitAfter(fnDeclaration, ".")

0 commit comments

Comments
 (0)