// NewAPIContext returns a new polly context
422801
func (context *APIContext) NewAPIContext() smolder.APIContext {
	ctx := &APIContext{
		Config: context.Config,
	}
	return ctx
}
381818
func NewContext(req *http.Request) *Context {
	if ae != nil {
		ctxt := ae.NewContext(req)
		return &Context{ae: ctxt}
	}
	return newContext(req)
}
758466
func (e *Echo) NewContext(r *http.Request, w http.ResponseWriter) Context {
	return &context{
		request:  r,
		response: NewResponse(w, e),
		store:    make(Map),
		echo:     e,
		pvalues:  make([]string, *e.maxParam),
		handler:  NotFoundHandler,
	}
}
859519
func NewContext(canvas *js.Object, ca *ContextAttributes) (*Context, error) {
	if js.Global.Get("WebGLRenderingContext") == js.Undefined {
		return nil, errors.New("Your browser doesn't appear to support webgl.")
	}

	if ca == nil {
		ca = DefaultAttributes()
	}

	attrs := map[string]bool{
		"alpha":                 ca.Alpha,
		"depth":                 ca.Depth,
		"stencil":               ca.Stencil,
		"antialias":             ca.Antialias,
		"premultipliedAlpha":    ca.PremultipliedAlpha,
		"preserveDrawingBuffer": ca.PreserveDrawingBuffer,
	}
	gl := canvas.Call("getContext", "webgl", attrs)
	if gl == nil {
		gl = canvas.Call("getContext", "experimental-webgl", attrs)
		if gl == nil {
			return nil, errors.New("Creating a webgl context has failed.")
		}
	}
	ctx := new(Context)
	ctx.Object = gl
	return ctx, nil
}
764289
func NewAPI(spec *loads.Document) *API {
	var an *analysis.Spec
	if spec != nil && spec.Spec() != nil {
		an = analysis.New(spec.Spec())
	}
	api := &API{
		spec:           spec,
		analyzer:       an,
		consumers:      make(map[string]runtime.Consumer, 10),
		producers:      make(map[string]runtime.Producer, 10),
		authenticators: make(map[string]runtime.Authenticator),
		operations:     make(map[string]map[string]runtime.OperationHandler),
		ServeError:     errors.ServeError,
		Models:         make(map[string]func() interface{}),
		formats:        strfmt.NewFormats(),
	}
	return api.WithJSONDefaults()
}
99599
func (widgets *Widgets) NewContext(context *Context) *Context {
	if context == nil {
		context = &Context{}
	}

	if context.DB == nil {
		context.DB = widgets.Config.DB
	}

	if context.Options == nil {
		context.Options = map[string]interface{}{}
	}

	if context.FuncMaps == nil {
		context.FuncMaps = template.FuncMap{}
	}

	for key, fc := range widgets.funcMaps {
		if _, ok := context.FuncMaps[key]; !ok {
			context.FuncMaps[key] = fc
		}
	}

	context.Widgets = widgets
	return context
}
192211
func NewActionAPIV3(ctx facade.Context) (*APIv3, error) {
	api, err := newActionAPI(ctx.State(), ctx.Resources(), ctx.Auth())
	if err != nil {
		return nil, errors.Trace(err)
	}
	return &APIv3{api}, nil
}
139829
func (api *Client) GetEmojiContext(ctx context.Context) (map[string]string, error) {
	values := url.Values{
		"token": {api.token},
	}
	response := &emojiResponseFull{}

	err := api.postMethod(ctx, "emoji.list", values, response)
	if err != nil {
		return nil, err
	}

	if response.Err() != nil {
		return nil, response.Err()
	}

	return response.Emoji, nil
}
922889
func (c *CommandBase) getAPIContext(store jujuclient.CookieStore, controllerName string) (*apiContext, error) {
	c.assertRunStarted()
	if ctx := c.apiContexts[controllerName]; ctx != nil {
		return ctx, nil
	}
	if controllerName == "" {
		return nil, errors.New("cannot get API context from empty controller name")
	}
	ctx, err := newAPIContext(c.cmdContext, &c.authOpts, store, controllerName)
	if err != nil {
		return nil, errors.Trace(err)
	}
	c.apiContexts[controllerName] = ctx
	return ctx, nil
}
675555
func NewAPI(ctx facade.Context) (*API, error) {
	if !ctx.Auth().AuthController() {
		return nil, common.ErrPerm
	}

	return &API{}, nil
}
480218
func NewContext(p Project, opts ...func(*Context) error) (*Context, error) {
	envOr := func(key, def string) string {
		if v := os.Getenv(key); v != "" {
			return v
		}
		return def
	}

	defaults := []func(*Context) error{
		// must come before GcToolchain()
		func(c *Context) error {
			c.gohostos = runtime.GOOS
			c.gohostarch = runtime.GOARCH
			c.gotargetos = envOr("GOOS", runtime.GOOS)
			c.gotargetarch = envOr("GOARCH", runtime.GOARCH)
			c.debug = func(string, ...interface{}) {} // null logger
			return nil
		},
		GcToolchain(),
	}
	workdir, err := ioutil.TempDir("", "gb")
	if err != nil {
		return nil, err
	}

	ctx := Context{
		Project:   p,
		workdir:   workdir,
		buildmode: "exe",
		pkgs:      make(map[string]*Package),
	}

	for _, opt := range append(defaults, opts...) {
		err := opt(&ctx)
		if err != nil {
			return nil, err
		}
	}

	// sort build tags to ensure the ctxSring and Suffix is stable
	sort.Strings(ctx.buildtags)

	bc := build.Default
	bc.GOOS = ctx.gotargetos
	bc.GOARCH = ctx.gotargetarch
	bc.CgoEnabled = cgoEnabled(ctx.gohostos, ctx.gohostarch, ctx.gotargetos, ctx.gotargetarch)
	bc.ReleaseTags = releaseTags
	bc.BuildTags = ctx.buildtags

	i, err := buildImporter(&bc, &ctx)
	if err != nil {
		return nil, err
	}

	ctx.importer = i

	// C and unsafe are fake packages synthesised by the compiler.
	// Insert fake packages into the package cache.
	for _, name := range []string{"C", "unsafe"} {
		pkg, err := ctx.newPackage(&build.Package{
			Name:       name,
			ImportPath: name,
			Dir:        name, // fake, but helps diagnostics
			Goroot:     true,
		})
		if err != nil {
			return nil, err
		}
		pkg.NotStale = true
		ctx.pkgs[pkg.ImportPath] = pkg
	}

	return &ctx, err
}
1241751
func NewContext(width, height int) *Context {
	return NewContextForRGBA(image.NewRGBA(image.Rect(0, 0, width, height)))
}
1359597
func NewAPIClient(cfg *Configuration) *APIClient {
	if cfg.HTTPClient == nil {
		cfg.HTTPClient = http.DefaultClient
	}

	c := &APIClient{}
	c.cfg = cfg
	c.common.client = c

	// API Services
	c.ConfigApi = (*ConfigApiService)(&c.common)
	c.SearchApi = (*SearchApiService)(&c.common)
	c.ServersApi = (*ServersApiService)(&c.common)
	c.StatsApi = (*StatsApiService)(&c.common)
	c.ZonecryptokeyApi = (*ZonecryptokeyApiService)(&c.common)
	c.ZonemetadataApi = (*ZonemetadataApiService)(&c.common)
	c.ZonesApi = (*ZonesApiService)(&c.common)

	return c
}
411738
func NewListBottleContext(ctx context.Context, r *http.Request, service *goa.Service) (*ListBottleContext, error) {
	var err error
	resp := goa.ContextResponse(ctx)
	resp.Service = service
	req := goa.ContextRequest(ctx)
	req.Request = r
	rctx := ListBottleContext{Context: ctx, ResponseData: resp, RequestData: req}
	paramAccountID := req.Params["accountID"]
	if len(paramAccountID) > 0 {
		rawAccountID := paramAccountID[0]
		if accountID, err2 := strconv.Atoi(rawAccountID); err2 == nil {
			rctx.AccountID = accountID
		} else {
			err = goa.MergeErrors(err, goa.InvalidParamTypeError("accountID", rawAccountID, "integer"))
		}
		if rctx.AccountID < 1 {
			err = goa.MergeErrors(err, goa.InvalidRangeError(`accountID`, rctx.AccountID, 1, true))
		}
	}
	paramYears := req.Params["years"]
	if len(paramYears) > 0 {
		params := make([]int, len(paramYears))
		for i, rawYears := range paramYears {
			if years, err2 := strconv.Atoi(rawYears); err2 == nil {
				params[i] = years
			} else {
				err = goa.MergeErrors(err, goa.InvalidParamTypeError("years", rawYears, "integer"))
			}
		}
		rctx.Years = params
	}
	return &rctx, err
}
601305
func NewContext(ctx context.Context, rw http.ResponseWriter, req *http.Request, params url.Values) context.Context {
	if ctx == nil {
		ctx = context.Background()
	}
	request := &RequestData{Request: req, Params: params}
	response := &ResponseData{ResponseWriter: rw}
	ctx = context.WithValue(ctx, respKey, response)
	ctx = context.WithValue(ctx, reqKey, request)

	return ctx
}
256907
func NewAPIBuilder() *APIBuilder {
	api := &APIBuilder{
		macros:            macro.Defaults,
		errorCodeHandlers: defaultErrorCodeHandlers(),
		reporter:          errors.NewReporter(),
		relativePath:      "/",
		routes:            new(repository),
	}

	return api
}
1270329
func NewContext(label string) (Context, error) {
	c := make(Context)

	if len(label) != 0 {
		con := strings.SplitN(label, ":", 4)
		if len(con) < 3 {
			return c, InvalidLabel
		}
		c["user"] = con[0]
		c["role"] = con[1]
		c["type"] = con[2]
		if len(con) > 3 {
			c["level"] = con[3]
		}
	}
	return c, nil
}