MCPcopy
hub / github.com/micro/go-micro / extractHandlerDocs

Function extractHandlerDocs

server/comments.go:126–164  ·  view source on GitHub ↗

extractHandlerDocs extracts documentation for all methods of a handler

(handler interface{})

Source from the content-addressed store, hash-verified

124
125// extractHandlerDocs extracts documentation for all methods of a handler
126func extractHandlerDocs(handler interface{}) map[string]map[string]string {
127 metadata := make(map[string]map[string]string)
128
129 typ := reflect.TypeOf(handler)
130 if typ == nil {
131 return metadata
132 }
133
134 // Get the receiver type for methods
135 rcvrType := typ
136 if rcvrType.Kind() == reflect.Ptr {
137 rcvrType = rcvrType.Elem()
138 }
139
140 // Iterate through methods
141 for i := 0; i < typ.NumMethod(); i++ {
142 method := typ.Method(i)
143
144 // Skip non-exported methods
145 if method.PkgPath != "" {
146 continue
147 }
148
149 // Extract documentation from source
150 description, example := extractMethodDoc(method, rcvrType)
151
152 if description != "" || example != "" {
153 metadata[method.Name] = make(map[string]string)
154 if description != "" {
155 metadata[method.Name]["description"] = description
156 }
157 if example != "" {
158 metadata[method.Name]["example"] = example
159 }
160 }
161 }
162
163 return metadata
164}

Callers 2

NewRpcHandlerFunction · 0.85
TestExtractHandlerDocsFunction · 0.85

Calls 2

extractMethodDocFunction · 0.85
MethodMethod · 0.65

Tested by 1

TestExtractHandlerDocsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…