(handlerFunc interface{}, options ...Option)
| 161 | } |
| 162 | |
| 163 | func newHandler(handlerFunc interface{}, options ...Option) *handlerOptions { |
| 164 | if h, ok := handlerFunc.(*handlerOptions); ok { |
| 165 | return h |
| 166 | } |
| 167 | pool := &sync.Pool{} |
| 168 | pool.New = func() interface{} { |
| 169 | return &jsonOutBuffer{pool, bytes.NewBuffer(nil)} |
| 170 | } |
| 171 | h := &handlerOptions{ |
| 172 | baseContext: context.Background(), |
| 173 | contextValues: map[interface{}]interface{}{}, |
| 174 | jsonResponseEscapeHTML: false, |
| 175 | jsonResponseIndentPrefix: "", |
| 176 | jsonResponseIndentValue: "", |
| 177 | jsonOutBufferPool: pool, |
| 178 | } |
| 179 | for _, option := range options { |
| 180 | option(h) |
| 181 | } |
| 182 | for k, v := range h.contextValues { |
| 183 | h.baseContext = context.WithValue(h.baseContext, k, v) |
| 184 | } |
| 185 | if h.enableSIGTERM { |
| 186 | enableSIGTERM(h.sigtermCallbacks) |
| 187 | } |
| 188 | h.handlerFunc = reflectHandler(handlerFunc, h) |
| 189 | return h |
| 190 | } |
| 191 | |
| 192 | type handlerFunc func(context.Context, []byte) (io.Reader, error) |
| 193 |
searching dependent graphs…