extractHandlerDocs extracts documentation for all methods of a handler
(handler interface{})
| 124 | |
| 125 | // extractHandlerDocs extracts documentation for all methods of a handler |
| 126 | func 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 | } |
searching dependent graphs…