ExtractHandler extract the set of methods from the receiver value which satisfy the following conditions: - exported method of exported type - two arguments, both of exported type - the first argument is *session.Session - the second argument is []byte or a pointer
()
| 96 | // - the first argument is *session.Session |
| 97 | // - the second argument is []byte or a pointer |
| 98 | func (s *Service) ExtractHandler() error { |
| 99 | typeName := reflect.Indirect(s.Receiver).Type().Name() |
| 100 | if typeName == "" { |
| 101 | return errors.New("no service name for type " + s.Type.String()) |
| 102 | } |
| 103 | if !isExported(typeName) { |
| 104 | return errors.New("type " + typeName + " is not exported") |
| 105 | } |
| 106 | |
| 107 | // Install the methods |
| 108 | s.Handlers = s.suitableHandlerMethods(s.Type) |
| 109 | |
| 110 | if len(s.Handlers) == 0 { |
| 111 | str := "" |
| 112 | // To help the user, see if a pointer receiver would work. |
| 113 | method := s.suitableHandlerMethods(reflect.PtrTo(s.Type)) |
| 114 | if len(method) != 0 { |
| 115 | str = "type " + s.Name + " has no exported methods of suitable type (hint: pass a pointer to value of that type)" |
| 116 | } else { |
| 117 | str = "type " + s.Name + " has no exported methods of suitable type" |
| 118 | } |
| 119 | return errors.New(str) |
| 120 | } |
| 121 | |
| 122 | for i := range s.Handlers { |
| 123 | s.Handlers[i].Receiver = s.Receiver |
| 124 | } |
| 125 | |
| 126 | return nil |
| 127 | } |
no test coverage detected