code: 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)
  }
docs: // Init initializes the server. This function MUST be called before Loop.