// newAPI is now an internal method that can be changed if params are changing
newAPI is now an internal method that can be changed if params are changing
// newAPI is now an internal method that can be changed if params are changing
func newAPI(prefix string, resolver URLResolver, marshalers map[string]ContentMarshaler, router routing.Routeable, ctx context.Context) *API {
	if len(marshalers) == 0 {
		panic("marshaler map must not be empty")
	}
	prefixSlashes := strings.Trim(prefix, "/")
	if len(prefixSlashes) > 0 {
		prefixSlashes = "/" + prefixSlashes + "/"
	} else {
		prefixSlashes = "/"
	}
	info := Information{prefix: prefix, resolver: resolver}
	api := &API{
		router:     router,
		info:       info,
		marshalers: marshalers,
		Context:    ctx,
	}
	requestInfo := func(r *http.Request, api *API) Information {
		var info Information
		if resolver, ok := api.info.resolver.(RequestAwareURLResolver); ok {
			resolver.SetRequest(*r)
			info = Information{prefix: api.info.prefix, resolver: resolver}
		} else {
			info = api.info
		}
		return info
	}
	api.middlewares = append(api.middlewares, func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			var c context.Context
			if api.Context != nil {
				c = api.Context
			} else {
				c = r.Context()
			}
			c = context.WithValue(c, api_info, requestInfo(r, api))
			c = context.WithValue(c, api_prefix, strings.Trim(api.info.prefix, "/"))
			c = context.WithValue(c, api_api, api)
			next.ServeHTTP(w, r.WithContext(c))
		})
	})
	return api
}
func newAPI ( prefix string , resolver URLResolver , marshalers map [ string ] ContentMarshaler , router routing . Routeable , ctx context . Context ) * API { if len ( marshalers ) == 0 { panic ( " " ) } prefixSlashes := strings . Trim ( prefix , " " ) if len ( prefixSlashes ) > 0 { prefixSlashes = " " + prefixSlashes + " " } else { prefixSlashes = " " } info := Information { prefix : prefix , resolver : resolver } api := & API { router : router , info : info , marshalers : marshalers , Context : ctx , } requestInfo := func ( r * http . Request , api * API ) Information { var info Information if resolver , ok := api . info . resolver . ( RequestAwareURLResolver ) ; ok { resolver . SetRequest ( * r ) info = Information { prefix : api . info . prefix , resolver : resolver } } else { info = api . info } return info } api . middlewares = append ( api . middlewares , func ( next http . Handler ) http . Handler { return http . HandlerFunc ( func ( w http . ResponseWriter , r * http . Request ) { var c context . Context if api . Context != nil { c = api . Context } else { c = r . Context ( ) } c = context . WithValue ( c , api_info , requestInfo ( r , api ) ) c = context . WithValue ( c , api_prefix , strings . Trim ( api . info . prefix , " " ) ) c = context . WithValue ( c , api_api , api ) next . ServeHTTP ( w , r . WithContext ( c ) ) } ) } ) return api }
newAPI is now an internal method that can be changed if params are changing
newAPI is now an internal method that can be changed if params are changing
// Add initial and trailing slash to prefix