// Init registers a resource with the Container and sets up all the supported routes
432297
func (r Resource) Init(container *restful.Container, resource interface{}) {
	log.WithField("Resource", r.Name).Info("Registering Resource")
	ws := new(restful.WebService)
	r.Parent = resource

	ws.Path("/" + r.Config.PathPrefix + r.Endpoint).
		Doc(r.Doc).
		Consumes(restful.MIME_JSON).
		Produces(restful.MIME_JSON)

	isDatabaseItem := false
	if resource, ok := resource.(GetIDSupported); ok {
		isDatabaseItem = true
		route := ws.GET("/{id:*}").To(r.GetByIDs).
			Doc("get item by id").
			Returns(http.StatusOK, "OK", resource.Returns()).
			Returns(http.StatusNotFound, "Not found", ErrorResponse{}).
			Param(ws.PathParameter("id", "ID of "+r.TypeName).
				DataType("string").
				Required(true).
				AllowMultiple(false))

		if resource.GetByIDsAuthRequired() {
			route.Returns(http.StatusUnauthorized, "Authorization required", ErrorResponse{})
			route.Param(restful.QueryParameter("accesstoken", "accesstoken required for auth").
				DataType("string").
				Required(true).
				AllowMultiple(false))
		}

		ws.Route(route)
	}

	isGetSupported := false
	if resource, ok := resource.(GetSupported); ok {
		isGetSupported = true
		route := ws.GET("").To(r.Get).
			Doc(resource.GetDoc()).
			Returns(http.StatusOK, "OK", resource.Returns()).
			Returns(http.StatusNotFound, "Not found", ErrorResponse{})

		if resource.GetAuthRequired() {
			route.Returns(http.StatusUnauthorized, "Authorization required", ErrorResponse{})
			route.Param(restful.QueryParameter("accesstoken", "accesstoken required for auth").
				DataType("string").
				Required(true).
				AllowMultiple(false))
		}

		for _, p := range resource.GetParams() {
			route.Param(p)
		}
		if isDatabaseItem {
			route.Param(ws.QueryParameter("ids[]", "IDs of "+r.TypeName+"s").
				DataType("string").
				// Required(true).
				AllowMultiple(true))
		}
		ws.Route(route)
	}

	if isDatabaseItem && !isGetSupported {
		route := ws.GET("").To(r.GetByIDs).
			Doc("get "+r.TypeName+" by ids").
			Returns(http.StatusNotFound, "Not found", ErrorResponse{}).
			Param(ws.QueryParameter("ids[]", "IDs of "+r.TypeName+"s").
				DataType("string").
				// Required(true).
				AllowMultiple(true))

		ws.Route(route)
	}

	if resource, ok := resource.(PostSupported); ok {
		route := ws.POST("").To(r.Post).
			Doc(resource.PostDoc()).
			Reads(reflect.Indirect(reflect.ValueOf(resource.Reads())).Interface()).
			Returns(http.StatusOK, "OK", resource.Returns()).
			Returns(http.StatusBadRequest, "Invalid post data", ErrorResponse{})

		if resource.PostAuthRequired() {
			route.Returns(http.StatusUnauthorized, "Authorization required", ErrorResponse{})
			route.Param(restful.QueryParameter("accesstoken", "accesstoken required for auth").
				DataType("string").
				Required(true).
				AllowMultiple(false))
		}

		for _, p := range resource.PostParams() {
			route.Param(p)
		}

		ws.Route(route)
	}

	if resource, ok := resource.(PutSupported); ok {
		route := ws.PUT("/{"+r.TypeName+"-id}").To(r.Put).
			Doc(resource.PutDoc()).
			Reads(reflect.Indirect(reflect.ValueOf(resource.Reads())).Interface()).
			Returns(http.StatusOK, "OK", resource.Returns()).
			Returns(http.StatusNotFound, "Not found", ErrorResponse{}).
			Returns(http.StatusBadRequest, "Invalid put data", ErrorResponse{})

		if resource.PutAuthRequired() {
			route.Returns(http.StatusUnauthorized, "Authorization required", ErrorResponse{})
			route.Param(restful.QueryParameter("accesstoken", "accesstoken required for auth").
				DataType("string").
				Required(true).
				AllowMultiple(false))
		}

		for _, p := range resource.PutParams() {
			route.Param(p)
		}

		route.Param(restful.PathParameter(r.TypeName+"-id", "ID of a "+r.TypeName).
			Required(true).
			AllowMultiple(false))

		ws.Route(route)
	}

	if resource, ok := resource.(PatchSupported); ok {
		route := ws.PATCH("/{"+r.TypeName+"-id").To(r.Patch).
			Doc(resource.PatchDoc()).
			Reads(reflect.Indirect(reflect.ValueOf(resource.Reads())).Interface()).
			Returns(http.StatusOK, "OK", resource.Returns()).
			Returns(http.StatusNotFound, "Not found", ErrorResponse{}).
			Returns(http.StatusBadRequest, "Invalid patch data", ErrorResponse{})

		if resource.PatchAuthRequired() {
			route.Returns(http.StatusUnauthorized, "Authorization required", ErrorResponse{})
			route.Param(restful.QueryParameter("accesstoken", "accesstoken required for auth").
				DataType("string").
				Required(true).
				AllowMultiple(false))
		}

		for _, p := range resource.PatchParams() {
			route.Param(p)
		}

		route.Param(restful.PathParameter(r.TypeName+"-id", "ID of a "+r.TypeName).
			Required(true).
			AllowMultiple(false))

		ws.Route(route)
	}

	if resource, ok := resource.(DeleteSupported); ok {
		route := ws.DELETE("/{"+r.TypeName+"-id}").To(r.Delete).
			Doc(resource.DeleteDoc()).
			Returns(http.StatusNotFound, "Not found", ErrorResponse{})

		if resource.DeleteAuthRequired() {
			route.Returns(http.StatusUnauthorized, "Authorization required", ErrorResponse{})
			route.Param(restful.QueryParameter("accesstoken", "accesstoken required for auth").
				DataType("string").
				Required(true).
				AllowMultiple(false))
		}

		for _, p := range resource.DeleteParams() {
			route.Param(p)
		}

		route.Param(restful.PathParameter(r.TypeName+"-id", "ID of a "+r.TypeName).
			Required(true).
			AllowMultiple(false))

		ws.Route(route)
	}

	container.Add(ws)
}
338718
func (r *HiveResponse) Init(context smolder.APIContext) {
	r.Parent = r
	r.Context = context

	r.hives = make(map[string]*bees.BeeFactoryInterface)
}
310978
func Init(bucket *service.Bucket, objectKey string) *Image {
	return &Image{
		key:    &objectKey,
		bucket: bucket,
		input:  &service.ImageProcessInput{},
	}
}
1055090
func (all *assetLruList) Init() *assetLruList {
	all.root.next = &all.root
	all.root.prev = &all.root
	all.len = 0
	return all
}
835000
func (impl *adminImpl) init() {
	impl.ctl = &mapper.Controller{
		MapperQueue:  "mappers", // see queue.yaml
		ControlQueue: "default",
	}
	for _, m := range mappers { // see mappers.go
		impl.ctl.RegisterFactory(m.mapperID(), m.newMapper)
	}
	impl.ctl.Install(impl.tq)
}
1173980
func (s *Server) Init(ctx context.Context) (*Server, error) {

	s.initRouter()

	// Add authorization handler. This must come BEFORE authentication handler
	// so that the latter can run first.
	switch s.authorization {
	case AuthorizationBasic:
		s.Handler = authorizer.NewBasic(
			s.Handler,
			s.getCompiler,
			s.store,
			authorizer.Runtime(s.runtime),
			authorizer.Decision(s.manager.Config.DefaultAuthorizationDecisionRef))
	}

	switch s.authentication {
	case AuthenticationToken:
		s.Handler = identifier.NewTokenBased(s.Handler)
	case AuthenticationTLS:
		s.Handler = identifier.NewTLSBased(s.Handler)
	}

	txn, err := s.store.NewTransaction(ctx, storage.WriteParams)
	if err != nil {
		return nil, err
	}

	// Register triggers so that if runtime reloads the policies, the
	// server sees the change.
	config := storage.TriggerConfig{
		OnCommit: s.reload,
	}
	if _, err := s.store.Register(ctx, txn, config); err != nil {
		s.store.Abort(ctx, txn)
		return nil, err
	}

	s.manager.RegisterCompilerTrigger(s.migrateWatcher)

	s.watcher, err = watch.New(ctx, s.store, s.getCompiler(), txn)
	if err != nil {
		return nil, err
	}

	s.partials = map[string]rego.PartialResult{}

	bp := bundle.Lookup(s.manager)
	if bp != nil {
		s.bundleStatusMtx = new(sync.RWMutex)
		s.hasBundle = true
		bp.Register("REST API Server", func(status bundle.Status) {
			s.updateBundleStatus(status)
		})
	}

	return s, s.store.Commit(ctx, txn)
}
305376
func (c *Crawler) init(ctxs []*URLContext) {
	// Initialize the internal hosts map
	c.hosts = make(map[string]struct{}, len(ctxs))
	for _, ctx := range ctxs {
		// Add this normalized URL's host if it is not already there.
		if _, ok := c.hosts[ctx.normalizedURL.Host]; !ok {
			c.hosts[ctx.normalizedURL.Host] = struct{}{}
		}
	}

	hostCount := len(c.hosts)
	l := len(ctxs)
	c.logFunc(LogTrace, "init() - seeds length: %d", l)
	c.logFunc(LogTrace, "init() - host count: %d", hostCount)
	c.logFunc(LogInfo, "robot user-agent: %s", c.Options.RobotUserAgent)

	// Create a shiny new WaitGroup
	c.wg = new(sync.WaitGroup)

	// Initialize the visits fields
	c.visited = make(map[string]struct{}, l)
	c.pushPopRefCount, c.visits = 0, 0

	// Create the workers map and the push channel (the channel used by workers
	// to communicate back to the crawler)
	c.stop = make(chan struct{})
	if c.Options.SameHostOnly {
		c.workers, c.push = make(map[string]*worker, hostCount),
			make(chan *workerResponse, hostCount)
	} else {
		c.workers, c.push = make(map[string]*worker, c.Options.HostBufferFactor*hostCount),
			make(chan *workerResponse, c.Options.HostBufferFactor*hostCount)
	}
	// Create and pass the enqueue channel
	c.enqueue = make(chan interface{}, c.Options.EnqueueChanBuffer)
	c.setExtenderEnqueueChan()
}
873338
func (p PhysicalIndexScan) Init(ctx sessionctx.Context) *PhysicalIndexScan {
	p.basePhysicalPlan = newBasePhysicalPlan(ctx, TypeIdxScan, &p)
	return &p
}
511673
func (a *APIDocsGen) Init() error {
	for _, s := range a.services {
		logger.Log.Infof("loaded svc: %s", s.Name)
	}
	return nil
}
40686
func (f *FlagSet) Init(name string, errorHandling ErrorHandling) {
	f.name = name
	f.errorHandling = errorHandling
}
396213
func (r *Store) Init(ctx context.Context, alias, path string, ids ...string) error {
	out.Debug(ctx, "Instantiating new sub store %s at %s for %+v", alias, path, ids)
	// parse backend URL
	pathURL, err := backend.ParseURL(path)
	if err != nil {
		return errors.Wrapf(err, "failed to parse backend URL '%s': %s", path, err)
	}
	sub, err := sub.New(ctx, r.cfg, alias, pathURL, r.cfg.Directory(), r.agent)
	if err != nil {
		return errors.Wrapf(err, "failed to instantiate new sub store: %s", err)
	}
	if !r.store.Initialized(ctx) && alias == "" {
		r.store = sub
	}

	out.Debug(ctx, "Initializing sub store at %s for %+v", path, ids)
	if err := sub.Init(ctx, path, ids...); err != nil {
		return errors.Wrapf(err, "failed to initialize new sub store: %s", err)
	}

	return r.initConfig(ctx, alias, path)
}
399002
func (c *showCommand) Init(args []string) (err error) {
	if len(args) != 1 {
		return errors.New("must specify endpoint URL")
	}
	c.url = args[0]
	return nil
}
137749
func (h *loaderHandler) Init() error {
	var m = make(map[string]interface{})
	if err := h.loader.Load(&m); err != nil {
		return err
	}
	h.handler = MapUse(m)
	return h.handler.Init()
}
425447
func (h *Handler) init(cfg config.Configuration) error {
	if cfg.Sampler != nil && cfg.Sampler.SamplingServerURL == "" {
		cfg.Sampler.SamplingServerURL = h.samplingServerURL
	}
	if cfg.Reporter != nil && cfg.Reporter.LocalAgentHostPort == "" {
		cfg.Reporter.LocalAgentHostPort = h.agentHostPort
	}
	tracer, _, err := cfg.New(common.DefaultTracerServiceName)
	if err != nil {
		return err
	}
	h.tracers[cfg.Sampler.Type] = tracer
	return nil
}
956397
func (c *ConnWriter) Init(config map[string]interface{}) error {
	conf, err := json.Marshal(config)
	if err != nil {
		return err
	}
	return json.Unmarshal(conf, c)
}
486319
func (c *config) Init() error {
	err := c.handler.Init()
	c.log(INIT, err)
	return err
}
539291
func (p *Provider) Init() error {
	fm := template.FuncMap{
		"strsToItfs": func(values []string) []interface{} {
			var r []interface{}
			for _, v := range values {
				r = append(r, v)
			}
			return r
		},
	}

	defaultRuleTpl, err := provider.MakeDefaultRuleTemplate(p.DefaultRule, fm)
	if err != nil {
		return fmt.Errorf("error while parsing default rule: %v", err)
	}

	p.defaultRuleTpl = defaultRuleTpl
	return nil
}