/ / General setup--resource locations. / Solr server, GOlr config, etc. /
764985
function jumper(doc){

	// Extract data.
	var term_to_draw = doc['annotation_class'];
	var graph_json = doc['topology_graph_json'];

	// Add to global graph.
	var new_graph = new model.graph();
	new_graph.load_base_json(JSON.parse(graph_json));
	add_to_graph(new_graph, term_to_draw);

	// Figure out layout.
	var lchoice = jQuery('#layout_input').val();

	// Render.
	CytoDraw(graph, us.keys(focus_nodes),
		 lchoice, amigo, 'grcon',
		 _start_wait, _stop_wait, _data_call);

	// Update color explanations to the newest.
	var color_clust = [];
	var erels = graph.all_predicates();
	each(erels, function(erel){
	    color_clust.push({
		'label': amigo.readable(erel),
		'color': amigo.color(erel),
		'priority': amigo.priority(erel)
	    });
	});
	color_clust.sort(function(a, b){ return b.priority - a.priority; });
	// Assemble HTML for label display.
	var fc = [];
	fc.push('<ul class="list-unstyled">');
	each(color_clust, function(c){
	    fc.push('<li>');
	    fc.push('<span class="label" style="background-color:' +
		    c.color + ';">' + c.label + '</span>');
	    fc.push('</li>');
	});
	fc.push('</ul>');
	// Add to DOM.
	jQuery('#color_exp').empty();
	jQuery('#color_exp').append(fc.join(''));
    }
698018
func setup(c *caddy.Controller) error {
	mdconfigs, err := markdownParse(c)
	if err != nil {
		return err
	}

	cfg := httpserver.GetConfig(c)

	md := Markdown{
		Root:       cfg.Root,
		FileSys:    http.Dir(cfg.Root),
		Configs:    mdconfigs,
		IndexFiles: []string{"index.md"},
	}

	cfg.AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
		md.Next = next
		return md
	})

	return nil
}
551936
func Setup(conf config.Config) error {
	nsConfig := conf.NetworkServer
	schedulerInterval = nsConfig.Scheduler.SchedulerInterval

	if err := data.Setup(conf); err != nil {
		return errors.Wrap(err, "setup downlink/data error")
	}

	if err := join.Setup(conf); err != nil {
		return errors.Wrap(err, "setup downlink/join error")
	}

	if err := multicast.Setup(conf); err != nil {
		return errors.Wrap(err, "setup downlink/multicast error")
	}

	if err := proprietary.Setup(conf); err != nil {
		return errors.Wrap(err, "setup downlink/proprietary error")
	}

	return nil
}
148621
func (*DefaultScene) Setup(u engo.Updater) {
	w, _ := u.(*ecs.World)

	common.SetBackground(color.White)
	w.AddSystem(&common.RenderSystem{})
	w.AddSystem(&common.MouseRotator{RotationSpeed: rotationSpeed})

	// Create a background; this way we'll see when we actually rotate
	demoutils.NewBackground(w, 300, worldHeight, color.RGBA{102, 153, 0, 255}, color.RGBA{102, 173, 0, 255})

	// Create a background; this way we'll see when we actually rotate
	bg2 := demoutils.NewBackground(w, 300, worldHeight, color.RGBA{102, 153, 0, 255}, color.RGBA{102, 173, 0, 255})
	bg2.SpaceComponent.Position.X = 500
}
975195
func setup(c *caddy.Controller) error {
	cfg := httpserver.GetConfig(c)
	root := cfg.Root

	exts, err := extParse(c)
	if err != nil {
		return err
	}

	httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
		return Ext{
			Next:       next,
			Extensions: exts,
			Root:       root,
		}
	})

	return nil
}
1369541
func (i18n *I18n) ConfigureQorResource(res resource.Resourcer) {
	if res, ok := res.(*admin.Resource); ok {
		i18n.Resource = res
		res.UseTheme("i18n")
		res.GetAdmin().I18n = i18n
		res.SearchAttrs("value") // generate search handler for i18n

		var getPrimaryLocale = func(context *admin.Context) string {
			if locale := context.Request.Form.Get("primary_locale"); locale != "" {
				return locale
			}
			if availableLocales := getAvailableLocales(context.Request, context.CurrentUser); len(availableLocales) > 0 {
				return availableLocales[0]
			}
			return ""
		}

		var getEditingLocale = func(context *admin.Context) string {
			if locale := context.Request.Form.Get("to_locale"); locale != "" {
				return locale
			}
			return getLocaleFromContext(context.Context)
		}

		type matchedTranslation struct {
			Key           string
			PrimaryLocale string
			PrimaryValue  string
			EditingLocale string
			EditingValue  string
		}

		res.GetAdmin().RegisterFuncMap("i18n_available_translations", func(context *admin.Context) (results []matchedTranslation) {
			var (
				translationsMap     = i18n.LoadTranslations()
				matchedTranslations = map[string]matchedTranslation{}
				keys                = []string{}
				keyword             = strings.ToLower(context.Request.URL.Query().Get("keyword"))
				primaryLocale       = getPrimaryLocale(context)
				editingLocale       = getEditingLocale(context)
			)

			var filterTranslations = func(translations map[string]*Translation, isPrimary bool) {
				if translations != nil {
					for key, translation := range translations {
						if (keyword == "") || (strings.Index(strings.ToLower(translation.Key), keyword) != -1 ||
							strings.Index(strings.ToLower(translation.Value), keyword) != -1) {
							if _, ok := matchedTranslations[key]; !ok {
								var t = matchedTranslation{
									Key:           key,
									PrimaryLocale: primaryLocale,
									EditingLocale: editingLocale,
									EditingValue:  translation.Value,
								}

								if localeTranslations, ok := translationsMap[primaryLocale]; ok {
									if v, ok := localeTranslations[key]; ok {
										t.PrimaryValue = v.Value
									}
								}

								matchedTranslations[key] = t
								keys = append(keys, key)
							}
						}
					}
				}
			}

			filterTranslations(translationsMap[getEditingLocale(context)], false)
			if primaryLocale != editingLocale {
				filterTranslations(translationsMap[getPrimaryLocale(context)], true)
			}

			sort.Strings(keys)

			pagination := context.Searcher.Pagination
			pagination.Total = len(keys)
			pagination.PerPage, _ = strconv.Atoi(context.Request.URL.Query().Get("per_page"))
			pagination.CurrentPage, _ = strconv.Atoi(context.Request.URL.Query().Get("page"))

			if pagination.CurrentPage == 0 {
				pagination.CurrentPage = 1
			}

			if pagination.PerPage == 0 {
				pagination.PerPage = 25
			}

			if pagination.CurrentPage > 0 {
				pagination.Pages = pagination.Total / pagination.PerPage
			}

			context.Searcher.Pagination = pagination

			var paginationKeys []string
			if pagination.CurrentPage == -1 {
				paginationKeys = keys
			} else {
				lastIndex := pagination.CurrentPage * pagination.PerPage
				if pagination.Total < lastIndex {
					lastIndex = pagination.Total
				}

				startIndex := (pagination.CurrentPage - 1) * pagination.PerPage
				if lastIndex >= startIndex {
					paginationKeys = keys[startIndex:lastIndex]
				}
			}

			for _, key := range paginationKeys {
				results = append(results, matchedTranslations[key])
			}
			return results
		})

		res.GetAdmin().RegisterFuncMap("i18n_primary_locale", getPrimaryLocale)

		res.GetAdmin().RegisterFuncMap("i18n_editing_locale", getEditingLocale)

		res.GetAdmin().RegisterFuncMap("i18n_viewable_locales", func(context admin.Context) []string {
			return getAvailableLocales(context.Request, context.CurrentUser)
		})

		res.GetAdmin().RegisterFuncMap("i18n_editable_locales", func(context admin.Context) []string {
			return getEditableLocales(context.Request, context.CurrentUser)
		})

		controller := i18nController{i18n}
		router := res.GetAdmin().GetRouter()
		router.Get(res.ToParam(), controller.Index, &admin.RouteConfig{Resource: res})
		router.Post(res.ToParam(), controller.Update, &admin.RouteConfig{Resource: res})
		router.Put(res.ToParam(), controller.Update, &admin.RouteConfig{Resource: res})

		res.GetAdmin().RegisterViewPath("github.com/qor/i18n/views")
	}
}
406052
func (s *Server) setupSerf(conf *serf.Config, ch chan serf.Event, path string) (*serf.Serf, error) {
	conf.Init()
	conf.NodeName = fmt.Sprintf("%s.%s", s.config.NodeName, s.config.Region)
	conf.Tags["role"] = "nomad"
	conf.Tags["region"] = s.config.Region
	conf.Tags["dc"] = s.config.Datacenter
	conf.Tags["vsn"] = fmt.Sprintf("%d", structs.ApiMajorVersion)
	conf.Tags["mvn"] = fmt.Sprintf("%d", structs.ApiMinorVersion)
	conf.Tags["build"] = s.config.Build
	conf.Tags["raft_vsn"] = fmt.Sprintf("%d", s.config.RaftConfig.ProtocolVersion)
	conf.Tags["id"] = s.config.NodeID
	conf.Tags["rpc_addr"] = s.clientRpcAdvertise.(*net.TCPAddr).IP.String()         // Address that clients will use to RPC to servers
	conf.Tags["port"] = fmt.Sprintf("%d", s.serverRpcAdvertise.(*net.TCPAddr).Port) // Port servers use to RPC to one and another
	if s.config.Bootstrap || (s.config.DevMode && !s.config.DevDisableBootstrap) {
		conf.Tags["bootstrap"] = "1"
	}
	bootstrapExpect := atomic.LoadInt32(&s.config.BootstrapExpect)
	if bootstrapExpect != 0 {
		conf.Tags["expect"] = fmt.Sprintf("%d", bootstrapExpect)
	}
	if s.config.NonVoter {
		conf.Tags["nonvoter"] = "1"
	}
	if s.config.RedundancyZone != "" {
		conf.Tags[AutopilotRZTag] = s.config.RedundancyZone
	}
	if s.config.UpgradeVersion != "" {
		conf.Tags[AutopilotVersionTag] = s.config.UpgradeVersion
	}
	logger := s.logger.StandardLogger(&log.StandardLoggerOptions{InferLevels: true})
	conf.MemberlistConfig.Logger = logger
	conf.Logger = logger
	conf.MemberlistConfig.LogOutput = nil
	conf.LogOutput = nil
	conf.EventCh = ch
	if !s.config.DevMode {
		conf.SnapshotPath = filepath.Join(s.config.DataDir, path)
		if err := ensurePath(conf.SnapshotPath, false); err != nil {
			return nil, err
		}
	}
	conf.ProtocolVersion = protocolVersionMap[s.config.ProtocolVersion]
	conf.RejoinAfterLeave = true
	// LeavePropagateDelay is used to make sure broadcasted leave intents propagate
	// This value was tuned using https://www.serf.io/docs/internals/simulator.html to
	// allow for convergence in 99.9% of nodes in a 10 node cluster
	conf.LeavePropagateDelay = 1 * time.Second
	conf.Merge = &serfMergeDelegate{}

	// Until Nomad supports this fully, we disable automatic resolution.
	// When enabled, the Serf gossip may just turn off if we are the minority
	// node which is rather unexpected.
	conf.EnableNameConflictResolution = false
	return serf.Create(conf)
}
28458
func (*DefaultScene) Setup(u engo.Updater) {
	w, _ := u.(*ecs.World)

	common.SetBackground(color.RGBA{55, 55, 55, 255})
	w.AddSystem(&common.RenderSystem{})

	// Adding camera controllers so we can verify it doesn't break when we move
	w.AddSystem(common.NewKeyboardScroller(scrollSpeed, engo.DefaultHorizontalAxis, engo.DefaultVerticalAxis))
	w.AddSystem(&common.MouseZoomer{zoomSpeed})
	w.AddSystem(&common.MouseRotator{RotationSpeed: 0.125})

	triangle1 := MyShape{BasicEntity: ecs.NewBasic()}
	triangle1.SpaceComponent = common.SpaceComponent{Width: 100, Height: 100}
	triangle1.RenderComponent = common.RenderComponent{Drawable: common.Triangle{}, Color: color.RGBA{255, 0, 0, 255}}

	for _, system := range w.Systems() {
		switch sys := system.(type) {
		case *common.RenderSystem:
			sys.Add(&triangle1.BasicEntity, &triangle1.RenderComponent, &triangle1.SpaceComponent)
		}
	}

	rectangle1 := MyShape{BasicEntity: ecs.NewBasic()}
	rectangle1.SpaceComponent = common.SpaceComponent{Position: engo.Point{100, 100}, Width: 100, Height: 100}
	rectangle1.RenderComponent = common.RenderComponent{Drawable: common.Rectangle{}, Color: color.RGBA{0, 255, 0, 255}}

	for _, system := range w.Systems() {
		switch sys := system.(type) {
		case *common.RenderSystem:
			sys.Add(&rectangle1.BasicEntity, &rectangle1.RenderComponent, &rectangle1.SpaceComponent)
		}
	}

	circle1 := MyShape{BasicEntity: ecs.NewBasic()}
	circle1.SpaceComponent = common.SpaceComponent{Position: engo.Point{200, 200}, Width: 100, Height: 100}
	circle1.RenderComponent = common.RenderComponent{Drawable: common.Circle{}, Color: color.RGBA{0, 0, 255, 255}}

	for _, system := range w.Systems() {
		switch sys := system.(type) {
		case *common.RenderSystem:
			sys.Add(&circle1.BasicEntity, &circle1.RenderComponent, &circle1.SpaceComponent)
		}
	}

	triangle2 := MyShape{BasicEntity: ecs.NewBasic()}
	triangle2.SpaceComponent = common.SpaceComponent{Position: engo.Point{300, 300}, Width: 100, Height: 100}
	triangle2.RenderComponent = common.RenderComponent{Drawable: common.Triangle{TriangleType: common.TriangleRight}, Color: color.RGBA{255, 255, 0, 255}}

	for _, system := range w.Systems() {
		switch sys := system.(type) {
		case *common.RenderSystem:
			sys.Add(&triangle2.BasicEntity, &triangle2.RenderComponent, &triangle2.SpaceComponent)
		}
	}

	line1 := MyShape{BasicEntity: ecs.NewBasic()}
	line1.SpaceComponent = common.SpaceComponent{Position: engo.Point{400, 400}, Width: 1, Height: 100}
	line1.RenderComponent = common.RenderComponent{Drawable: common.Rectangle{}, Color: color.RGBA{0, 255, 255, 255}}

	for _, system := range w.Systems() {
		switch sys := system.(type) {
		case *common.RenderSystem:
			sys.Add(&line1.BasicEntity, &line1.RenderComponent, &line1.SpaceComponent)
		}
	}

	complexTriangle1 := MyShape{BasicEntity: ecs.NewBasic()}
	complexTriangle1.SpaceComponent = common.SpaceComponent{Position: engo.Point{500, 500}, Width: 100, Height: 100}
	complexTriangle1.RenderComponent = common.RenderComponent{Drawable: common.ComplexTriangles{
		Points: []engo.Point{
			{0.0, 0.0}, {1.0, 0.25}, {0.5, 0.5},
			{0.5, 0.5}, {1.0, 0.75}, {0.0, 1.0},
			{0.0, 0.0}, {0.5, 0.50}, {0.0, 1.0},
		}}, Color: color.RGBA{255, 0, 255, 255}}

	for _, system := range w.Systems() {
		switch sys := system.(type) {
		case *common.RenderSystem:
			sys.Add(&complexTriangle1.BasicEntity, &complexTriangle1.RenderComponent, &complexTriangle1.SpaceComponent)
		}
	}

	triangle3 := MyShape{BasicEntity: ecs.NewBasic()}
	triangle3.SpaceComponent = common.SpaceComponent{Position: engo.Point{23, 123}, Width: 50, Height: 50}
	triangle3.RenderComponent = common.RenderComponent{Drawable: common.Triangle{BorderWidth: 1, BorderColor: color.White}, Color: color.RGBA{255, 0, 0, 255}}

	for _, system := range w.Systems() {
		switch sys := system.(type) {
		case *common.RenderSystem:
			sys.Add(&triangle3.BasicEntity, &triangle3.RenderComponent, &triangle3.SpaceComponent)
		}
	}

	rectangle2 := MyShape{BasicEntity: ecs.NewBasic()}
	rectangle2.SpaceComponent = common.SpaceComponent{Position: engo.Point{123, 223}, Width: 50, Height: 50}
	rectangle2.RenderComponent = common.RenderComponent{Drawable: common.Rectangle{BorderWidth: 1, BorderColor: color.White}, Color: color.RGBA{0, 255, 0, 255}}

	for _, system := range w.Systems() {
		switch sys := system.(type) {
		case *common.RenderSystem:
			sys.Add(&rectangle2.BasicEntity, &rectangle2.RenderComponent, &rectangle2.SpaceComponent)
		}
	}

	circle2 := MyShape{BasicEntity: ecs.NewBasic()}
	circle2.SpaceComponent = common.SpaceComponent{Position: engo.Point{223, 323}, Width: 50, Height: 50}
	circle2.RenderComponent = common.RenderComponent{Drawable: common.Circle{BorderWidth: 1, BorderColor: color.White}, Color: color.RGBA{0, 0, 255, 255}}

	for _, system := range w.Systems() {
		switch sys := system.(type) {
		case *common.RenderSystem:
			sys.Add(&circle2.BasicEntity, &circle2.RenderComponent, &circle2.SpaceComponent)
		}
	}

	triangle4 := MyShape{BasicEntity: ecs.NewBasic()}
	triangle4.SpaceComponent = common.SpaceComponent{Position: engo.Point{323, 423}, Width: 50, Height: 50}
	triangle4.RenderComponent = common.RenderComponent{Drawable: common.Triangle{TriangleType: common.TriangleRight, BorderWidth: 1, BorderColor: color.White}, Color: color.RGBA{255, 255, 0, 255}}

	for _, system := range w.Systems() {
		switch sys := system.(type) {
		case *common.RenderSystem:
			sys.Add(&triangle4.BasicEntity, &triangle4.RenderComponent, &triangle4.SpaceComponent)
		}
	}

	complexTriangle2 := MyShape{BasicEntity: ecs.NewBasic()}
	complexTriangle2.SpaceComponent = common.SpaceComponent{Position: engo.Point{523, 623}, Width: 50, Height: 50}
	complexTriangle2.RenderComponent = common.RenderComponent{Drawable: common.ComplexTriangles{
		BorderWidth: 1, BorderColor: color.White,
		Points: []engo.Point{
			{0.0, 0.0}, {1.0, 0.25}, {0.5, 0.5},
			{0.5, 0.5}, {1.0, 0.75}, {0.0, 1.0},
			{0.0, 0.0}, {0.5, 0.50}, {0.0, 1.0},
		}}, Color: color.RGBA{255, 0, 255, 255}}

	for _, system := range w.Systems() {
		switch sys := system.(type) {
		case *common.RenderSystem:
			sys.Add(&complexTriangle2.BasicEntity, &complexTriangle2.RenderComponent, &complexTriangle2.SpaceComponent)
		}
	}
}
477002
func setup(c *caddy.Controller) error {
	configs, err := browseParse(c)
	if err != nil {
		return err
	}

	b := Browse{
		Configs:       configs,
		IgnoreIndexes: false,
	}

	httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
		b.Next = next
		return b
	})

	return nil
}
729537
func SetResources(repo resources.Repository, resources []resources.Resource) error {
	r, ok := repo.(*resourceRepository)
	if !ok {
		return errors.New("unexpected type")
	}
	store := resourceStore{}
	for _, resource := range resources {
		store[resourceHostname(resource.Hostname)] = &resource
	}
	r.mtx.Lock()
	defer r.mtx.Unlock()
	r.resources = store
	return nil
}
1203460
func (l *Locale) ConfigureQorResource(res resource.Resourcer) {
	if res, ok := res.(*admin.Resource); ok {
		Admin := res.GetAdmin()
		res.UseTheme("l10n")

		if res.Permission == nil {
			res.Permission = roles.NewPermission()
		}
		res.Permission.Allow(roles.CRUD, "locale_admin").Allow(roles.Read, "locale_reader")

		res.Meta(&admin.Meta{Name: "Localization", Type: "localization", Valuer: func(value interface{}, ctx *qor.Context) interface{} {
			var languageCodes []string
			var db = ctx.GetDB()
			var scope = db.NewScope(value)
			db.New().Set("l10n:mode", "unscoped").Model(res.Value).Where(fmt.Sprintf("%v = ?", scope.PrimaryKey()), scope.PrimaryKeyValue()).Pluck("language_code", &languageCodes)
			return utils.SliceUniq(languageCodes)
		}})

		res.OverrideIndexAttrs(func() {
			var attrs = res.ConvertSectionToStrings(res.IndexAttrs())
			var hasLocalization bool
			for _, attr := range attrs {
				if attr == "Localization" || attr == "-Localization" {
					hasLocalization = true
					break
				}
			}

			if hasLocalization {
				res.IndexAttrs(res.IndexAttrs(), "-LanguageCode")
			} else {
				res.IndexAttrs(res.IndexAttrs(), "-LanguageCode", "Localization")
			}
		})
		res.OverrideShowAttrs(func() {
			res.ShowAttrs(res.ShowAttrs(), "-LanguageCode", "-Localization")
		})
		res.NewAttrs(res.NewAttrs(), "-LanguageCode", "-Localization")
		res.EditAttrs(res.EditAttrs(), "-LanguageCode", "-Localization")

		// Set meta permissions
		for _, field := range Admin.DB.NewScope(res.Value).Fields() {
			if isSyncField(field.StructField) {
				if meta := res.GetMeta(field.Name); meta != nil {
					permission := meta.Meta.Permission
					if permission == nil {
						permission = roles.Allow(roles.CRUD, "global_admin").Allow(roles.Read, "locale_reader")
					} else {
						permission = permission.Allow(roles.CRUD, "global_admin").Allow(roles.Read, "locale_reader")
					}

					meta.SetPermission(permission)
				}
			}
		}

		// Roles
		role := res.Permission.Role
		if _, ok := role.Get("global_admin"); !ok {
			role.Register("global_admin", func(req *http.Request, currentUser interface{}) bool {
				if getLocaleFromContext(&qor.Context{Request: req}) == Global {
					for _, locale := range getEditableLocales(req, currentUser) {
						if locale == Global {
							return true
						}
					}
				}
				return false
			})
		}

		if _, ok := role.Get("locale_admin"); !ok {
			role.Register("locale_admin", func(req *http.Request, currentUser interface{}) bool {
				currentLocale := getLocaleFromContext(&qor.Context{Request: req})
				for _, locale := range getEditableLocales(req, currentUser) {
					if locale == currentLocale {
						return true
					}
				}
				return false
			})
		}

		if _, ok := role.Get("locale_reader"); !ok {
			role.Register("locale_reader", func(req *http.Request, currentUser interface{}) bool {
				currentLocale := getLocaleFromContext(&qor.Context{Request: req})
				for _, locale := range getAvailableLocales(req, currentUser) {
					if locale == currentLocale {
						return true
					}
				}
				return false
			})
		}

		// Inject for l10n
		Admin.RegisterViewPath("github.com/qor/l10n/views")

		// Middleware
		Admin.GetRouter().Use(&admin.Middleware{
			Name: "l10n_set_locale",
			Handler: func(context *admin.Context, middleware *admin.Middleware) {
				db := context.GetDB().Set("l10n:locale", getLocaleFromContext(context.Context))
				if mode := context.Request.URL.Query().Get("locale_mode"); mode != "" {
					db = db.Set("l10n:mode", mode)
				}

				usingLanguageCodeAsPrimaryKey := false
				if res := context.Resource; res != nil {
					for idx, primaryField := range res.PrimaryFields {
						if primaryField.Name == "LanguageCode" {
							_, params := res.ToPrimaryQueryParams(res.GetPrimaryValue(context.Request), context.Context)
							if len(params) > idx {
								usingLanguageCodeAsPrimaryKey = true
								db = db.Set("l10n:locale", params[idx])

								// PUT usually used for localize
								if context.Request.Method == "PUT" {
									if _, ok := db.Get("l10n:localize_to"); !ok {
										db = db.Set("l10n:localize_to", getLocaleFromContext(context.Context))
									}
								}
								break
							}
						}
					}
				}

				if !usingLanguageCodeAsPrimaryKey {
					for key, values := range context.Request.URL.Query() {
						if regexp.MustCompile(`primary_key\[.+_language_code\]`).MatchString(key) {
							if len(values) > 0 {
								db = db.Set("l10n:locale", values[0])

								// PUT usually used for localize
								if context.Request.Method == "PUT" || context.Request.Method == "POST" {
									db = db.Set(key, "")
									if _, ok := db.Get("l10n:localize_to"); !ok {
										db = db.Set("l10n:localize_to", getLocaleFromContext(context.Context))
									}
								}
							}
						}
					}
				}

				if context.Request.URL.Query().Get("sorting") != "" {
					db = db.Set("l10n:mode", "locale")
				}
				context.SetDB(db)

				middleware.Next(context)
			},
		})

		// FunMap
		Admin.RegisterFuncMap("current_locale", func(context admin.Context) string {
			return getLocaleFromContext(context.Context)
		})

		Admin.RegisterFuncMap("global_locale", func() string {
			return Global
		})

		Admin.RegisterFuncMap("viewable_locales", func(context admin.Context) []string {
			return getAvailableLocales(context.Request, context.CurrentUser)
		})

		Admin.RegisterFuncMap("editable_locales", func(context admin.Context) []string {
			return getEditableLocales(context.Request, context.CurrentUser)
		})

		Admin.RegisterFuncMap("createable_locales", func(context admin.Context) []string {
			editableLocales := getEditableLocales(context.Request, context.CurrentUser)
			if _, ok := context.Resource.Value.(localeCreatableInterface); ok {
				return editableLocales
			}

			for _, locale := range editableLocales {
				if locale == Global {
					return []string{Global}
				}
			}
			return []string{}
		})

		if res.GetAction("Localize") == nil {
			argumentResource := Admin.NewResource(&LocalizeActionArgument{})
			argumentResource.Meta(&admin.Meta{
				Name: "From",
				Type: "select_one",
				Valuer: func(_ interface{}, context *qor.Context) interface{} {
					return Global
				},
				Collection: func(value interface{}, context *qor.Context) (results [][]string) {
					for _, locale := range getAvailableLocales(context.Request, context.CurrentUser) {
						results = append(results, []string{locale, locale})
					}
					return
				},
			})
			argumentResource.Meta(&admin.Meta{
				Name: "To",
				Type: "select_many",
				Valuer: func(_ interface{}, context *qor.Context) interface{} {
					return []string{getLocaleFromContext(context)}
				},
				Collection: func(value interface{}, context *qor.Context) (results [][]string) {
					for _, locale := range getEditableLocales(context.Request, context.CurrentUser) {
						results = append(results, []string{locale, locale})
					}
					return
				},
			})

			res.Action(&admin.Action{
				Name: "Localize",
				Handler: func(argument *admin.ActionArgument) error {
					var (
						db        = argument.Context.GetDB()
						arg       = argument.Argument.(*LocalizeActionArgument)
						results   = res.NewSlice()
						sqls      []string
						sqlParams []interface{}
					)

					for _, primaryValue := range argument.PrimaryValues {
						primaryQuerySQL, primaryParams := res.ToPrimaryQueryParams(primaryValue, argument.Context.Context)
						sqls = append(sqls, primaryQuerySQL)
						sqlParams = append(sqlParams, primaryParams...)
					}

					db.Set("l10n:locale", arg.From).Where(strings.Join(sqls, " OR "), sqlParams...).Find(results)

					reflectResults := reflect.Indirect(reflect.ValueOf(results))
					for i := 0; i < reflectResults.Len(); i++ {
						for _, to := range arg.To {
							if err := db.Set("l10n:localize_to", to).Unscoped().Save(reflectResults.Index(i).Interface()).Error; err != nil {
								return err
							}
						}
					}
					return nil
				},
				Modes:      []string{"index", "menu_item"},
				Permission: roles.Allow(roles.CRUD, roles.Anyone),
				Resource:   argumentResource,
			})
		}
	}
}
514273
func ServerResources(d DiscoveryInterface) ([]*metav1.APIResourceList, error) {
	_, rs, err := ServerGroupsAndResources(d)
	return rs, err
}
303908
func (c *cassandraRequester) Setup() error {
	cluster := gocql.NewCluster(c.urls...)
	cluster.Keyspace = c.keyspace
	cluster.Consistency = c.consistency
	session, err := cluster.CreateSession()
	if err != nil {
		return err
	}
	c.session = session
	return nil
}
86454
func (*DefaultScene) Setup(u engo.Updater) {
	w, _ := u.(*ecs.World)

	rs := new(common.RenderSystem)
	w.AddSystem(rs)

	pack := new(common.TexturePack)
	pack.RChannel, _ = common.LoadedSprite("flowers.png")
	pack.GChannel, _ = common.LoadedSprite("mud.png")
	pack.BChannel, _ = common.LoadedSprite("path.png")
	pack.Fallback, _ = common.LoadedSprite("grass.png")

	blendMap, _ := common.LoadedSprite("blendmap.png")

	ent := &sampleEntity{
		ecs.NewBasic(),
		common.SpaceComponent{},
		common.RenderComponent{
			Scale:    engo.Point{0.75, 0.75},
			Drawable: common.Blendmap{pack, blendMap},
		},
	}

	rs.Add(&ent.BasicEntity, &ent.RenderComponent, &ent.SpaceComponent)
}
1118271
func (b *Backend) Setup(ctx context.Context, config *logical.BackendConfig) error {
	b.logger = config.Logger
	b.system = config.System
	return nil
}
543920
func Setup(app *gramework.App) {
	err := app.UseAfterRequest(serveXHost)
	if err != nil {
		app.Logger.WithError(err).WithField("package", "mw/xhostname").Error("could not register middleware")
	}
}
482160
func (c *connectionBenchmark) setup() error {
	c.successHistogram.Reset()
	c.uncorrectedSuccessHistogram.Reset()
	c.errorHistogram.Reset()
	c.uncorrectedErrorHistogram.Reset()
	c.successTotal = 0
	c.errorTotal = 0
	return c.requester.Setup()
}