// Init is the plugin entry point called by Agent Core
// - It prepares Gorilla MUX HTTP Router
421481
func (p *Plugin) Init() (err error) {
	if p.Config == nil {
		p.Config = DefaultConfig()
	}
	if err := PluginConfig(p.Cfg, p.Config, p.PluginName); err != nil {
		return err
	}

	// if there is no injected authenticator and there are credentials defined in the config file
	// instantiate staticAuthenticator otherwise do not use basic Auth
	if p.Authenticator == nil && len(p.Config.ClientBasicAuth) > 0 {
		p.Authenticator, err = newStaticAuthenticator(p.Config.ClientBasicAuth)
		if err != nil {
			return err
		}
	}

	p.mx = mux.NewRouter()
	p.formatter = render.New(render.Options{
		IndentJSON: true,
	})

	// Enable authentication if defined by config
	if p.EnableTokenAuth {
		p.Log.Info("Token authentication for HTTP enabled")
		p.auth = security.NewAuthenticator(p.mx, &security.Settings{
			Users:     p.Users,
			ExpTime:   p.TokenExpiration,
			Cost:      p.PasswordHashCost,
			Signature: p.TokenSignature,
		}, p.Log)
	}

	return err
}
633331
func (ens *NetpluginNameServer) Init(sd core.StateDriver) error {
	dnsLog = logrus.WithField("module", "nameserver")
	ens.bucketSize = 64
	ens.stateDriver = sd

	// don't change buffering
	ens.epChan = make(chan core.WatchState, 64)
	ens.epErrChan = make(chan error)
	ens.svcChan = make(chan core.WatchState, 8)
	ens.svcErrChan = make(chan error)
	ens.buckets = make([]tenantBucket, ens.bucketSize)
	ens.k8sService = cmap.New()

	for i := uint(0); i < ens.bucketSize; i++ {
		ens.buckets[i].tenantTables = make(map[string]*dnsTables)
		ens.stats.tenantStats = make(map[string]map[string]uint64)
	}
	ens.epKeyPath = mastercfg.StateConfigPath + "eps/"
	ens.svcKeyPath = mastercfg.StateConfigPath + "serviceLB/"
	go ens.processStateEvent()
	go ens.startSvcWatch()
	go ens.startEndpointWatch()
	ens.readStateStore()
	dnsLog.Infof("nameserver started")
	return nil
}
259956
func (op *CaasOperatorAgent) Init(args []string) error {
	if op.ApplicationName == "" {
		return cmdutil.RequiredError("application-name")
	}
	if !names.IsValidApplication(op.ApplicationName) {
		return errors.Errorf(`--application-name option expects "<application>" argument`)
	}
	if err := op.AgentConf.CheckArgs(args); err != nil {
		return err
	}
	op.runner = worker.NewRunner(worker.RunnerParams{
		IsFatal:       cmdutil.IsFatal,
		MoreImportant: cmdutil.MoreImportant,
		RestartDelay:  jworker.RestartDelay,
	})
	return nil
}
486319
func (c *config) Init() error {
	err := c.handler.Init()
	c.log(INIT, err)
	return err
}
609414
func (c *Cmd) Init() {
	c.Lock()
	defer c.Unlock()

	c.exitCh = make(chan struct{})
}
891354
func (pm *PluginManager) Init() {
	err := pm.LoadPlugins()
	if err != nil {
		panic(err)
	}
}
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()
}
1103331
func init() {
	sock, err := net.Listen("tcp", "localhost:8080")
	if err != nil {
		log.Printf("net listen error: %v", err)
	}
	go func() {
		fmt.Println("Metrics available at http://localhost:8080/debug/vars")
		http.Serve(sock, nil)
	}()
}
715393
func (p *Plugin) Init() (err error) {
	if p.Config == nil {
		p.Config, err = p.getConfig()
		if err != nil || p.disabled {
			return err
		}
	}

	clientCfg, err := ConfigToClient(p.Config)
	if err != nil {
		return err
	}
	p.client, err = NewClient(clientCfg)
	if err != nil {
		p.Log.Errorf("Err: %v", err)
		return err
	}

	p.reconnectResync = p.Config.ReconnectResync
	p.protoWrapper = kvproto.NewProtoWrapper(p.client, &keyval.SerializerJSON{})

	// Register for providing status reports (polling mode)
	if p.StatusCheck != nil {
		p.StatusCheck.Register(p.PluginName, p.statusCheckProbe)
	} else {
		p.Log.Warnf("Unable to start status check for consul")
	}

	return nil
}
840460
func (m *Module) Init(c *service.Config) {
	c.Setup = func() error {
		m.HTTPRouter = httprouter.New()
		m.ErrorHandler = func(rw http.ResponseWriter, req *http.Request, err error) {
			_ = m.HandleError(rw, req, err)
		}
		m.ErrorPage = func(rw http.ResponseWriter, req *http.Request, status int) {
			http.Error(rw, fmt.Sprint(status), status)
		}

		// root handler
		m.Root = http.NewServeMux()
		m.Root.Handle("/", m.HTTPRouter)
		m.Middleware = middleware.NewServer(m.Root.ServeHTTP)
		m.Config.ReadConfig(&m.config)
		return nil
	}

	c.Start = func() {
		laddr := m.laddr()
		m.Logger.Infof("listening on %s", laddr)
		m.server = &http.Server{Addr: laddr, Handler: m.Middleware}
		go m.server.ListenAndServe()
	}

	c.Stop = func() {
		m.Shutdown(context.Background())
	}
}
415530
func (cniApp *cniAppInfo) init() {
	cniApp.serverURL = "http://localhost"

	trans := &http.Transport{Dial: func(network, addr string) (net.Conn,
		error) {
		return net.Dial("unix", cniapi.ContivMesosSocket)
	}}
	cniApp.httpClient = &http.Client{Transport: trans}
}
1236506
func (p *Plugin) Init() (err error) {
	var config Config
	found, err := p.Cfg.LoadValue(&config)
	if err != nil {
		return err
	}

	if !found {
		p.Log.Info("cryptodata config not found, skip loading this plugin")
		p.disabled = true
		return nil
	}

	// Read client config and create it
	clientConfig := ClientConfig{}
	for _, file := range config.PrivateKeyFiles {
		bytes, err := ioutil.ReadFile(file)
		if err != nil {
			p.Log.Infof("%v", err)
			return err
		}

		for {
			block, rest := pem.Decode(bytes)
			if block == nil {
				break
			}

			privateKey, err := x509.ParsePKCS1PrivateKey(block.Bytes)
			if err != nil {
				p.Log.Infof("%v", err)
				return err
			}

			err = privateKey.Validate()
			if err != nil {
				p.Log.Infof("%v", err)
				return err
			}

			privateKey.Precompute()
			clientConfig.PrivateKeys = append(clientConfig.PrivateKeys, privateKey)

			if rest == nil {
				break
			}

			bytes = rest
		}
	}

	p.ClientAPI = NewClient(clientConfig)
	return
}
759667
func (p *NetPlugin) Init(pluginConfig Config) error {
	var err error
	if pluginConfig.Instance.HostLabel == "" {
		return core.Errorf("empty host-label passed")
	}

	// initialize state driver
	p.StateDriver, err = utils.GetStateDriver()
	if err != nil {
		p.StateDriver, err = utils.NewStateDriver(pluginConfig.Drivers.State, &pluginConfig.Instance)
		if err != nil {
			return err
		}
	}
	defer func() {
		if err != nil {
			utils.ReleaseStateDriver()
		}
	}()

	// set state driver in instance info
	pluginConfig.Instance.StateDriver = p.StateDriver
	err = InitGlobalSettings(p.StateDriver, &pluginConfig.Instance)
	if err != nil {
		return err
	}

	// initialize network driver
	p.NetworkDriver, err = utils.NewNetworkDriver(pluginConfig.Drivers.Network, &pluginConfig.Instance)
	if err != nil {
		return err
	}
	p.PluginConfig = pluginConfig

	defer func() {
		if err != nil {
			p.NetworkDriver.Deinit()
		}
	}()

	return nil
}
1011976
func (p *MyPlugin) Init() error {
	p.Log.Debug("Registering handler..")

	p.REST.RegisterHTTPHandler("/greeting", p.fooHandler, "POST")

	return nil
}
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)
}
893787
func (j *Jenkins) Init() (*Jenkins, error) {
	j.initLoggers()

	// Check Connection
	j.Raw = new(ExecutorResponse)
	rsp, err := j.Requester.GetJSON("/", j.Raw, nil)
	if err != nil {
		return nil, err
	}

	j.Version = rsp.Header.Get("X-Jenkins")
	if j.Raw == nil {
		return nil, errors.New("Connection Failed, Please verify that the host and credentials are correct.")
	}

	return j, nil
}
1035412
func (r *Registration) Init(ic *InitContext) *Plugin {
	p, err := r.InitFn(ic)
	return &Plugin{
		Registration: r,
		Config:       ic.Config,
		Meta:         ic.Meta,
		instance:     p,
		err:          err,
	}
}