func New(cfg *config.Config) (*Daemon, error) {
	lock, err := lockfile.New(cfg.PidPath)
	if err != nil {
		return nil, fmt.Errorf("Failed to create lockfile object: %s", err)
	}

	err = lock.TryLock()
	if err != nil {
		return nil, fmt.Errorf(
			"Failed to create lockfile[%s]: %s", cfg.PidPath, err)
	}

	// Recover from the panic and return the error; this way we can
	// delete the lockfile!
	defer func() {
		if r := recover(); r != nil {
			err, _ = r.(error)
		}
	}()

	db, err := db.NewDB(cfg.DBPath)
	if err != nil {
		return nil, err
	}

	session := session.NewSession()
	cryptoEngine := crypto.NewEngine(session)
	transport := socket.CreateHTTPTransport(cfg)
	client := registry.NewClient(cfg.RegistryURI.String(), cfg.APIVersion,
		cfg.Version, session, transport)
	logic := logic.NewEngine(cfg, session, db, cryptoEngine, client)

	proxy, err := socket.NewAuthProxy(cfg, session, db, transport, client, logic)
	if err != nil {
		return nil, fmt.Errorf("Failed to create auth proxy: %s", err)
	}

	daemon := &Daemon{
		proxy:       proxy,
		lock:        lock,
		session:     session,
		config:      cfg,
		db:          db,
		logic:       logic,
		hasShutdown: false,
	}

	return daemon, nil
}
// New creates a new Daemon.
New creates a new Daemon.
// New creates a new Daemon .
func New(cfg *config.Config) (*Daemon, error) {
	lock, err := lockfile.New(cfg.PidPath)
	if err != nil {
		return nil, fmt.Errorf("Failed to create lockfile object: %s", err)
	}
	err = lock.TryLock()
	if err != nil {
		return nil, fmt.Errorf(
			"Failed to create lockfile[%s]: %s", cfg.PidPath, err)
	}
	defer func() {
		if r := recover(); r != nil {
			err, _ = r.(error)
		}
	}()
	db, err := db.NewDB(cfg.DBPath)
	if err != nil {
		return nil, err
	}
	session := session.NewSession()
	cryptoEngine := crypto.NewEngine(session)
	transport := socket.CreateHTTPTransport(cfg)
	client := registry.NewClient(cfg.RegistryURI.String(), cfg.APIVersion,
		cfg.Version, session, transport)
	logic := logic.NewEngine(cfg, session, db, cryptoEngine, client)
	proxy, err := socket.NewAuthProxy(cfg, session, db, transport, client, logic)
	if err != nil {
		return nil, fmt.Errorf("Failed to create auth proxy: %s", err)
	}
	daemon := &Daemon{
		proxy:       proxy,
		lock:        lock,
		session:     session,
		config:      cfg,
		db:          db,
		logic:       logic,
		hasShutdown: false,
	}
	return daemon, nil
}
func New ( cfg * config . Config ) ( * Daemon , error ) { lock , err := lockfile . New ( cfg . PidPath ) if err != nil { return nil , fmt . Errorf ( " " , err ) } err = lock . TryLock ( ) if err != nil { return nil , fmt . Errorf ( " " , cfg . PidPath , err ) } defer func ( ) { if r := recover ( ) ; r != nil { err , _ = r . ( error ) } } ( ) db , err := db . NewDB ( cfg . DBPath ) if err != nil { return nil , err } session := session . NewSession ( ) cryptoEngine := crypto . NewEngine ( session ) transport := socket . CreateHTTPTransport ( cfg ) client := registry . NewClient ( cfg . RegistryURI . String ( ) , cfg . APIVersion , cfg . Version , session , transport ) logic := logic . NewEngine ( cfg , session , db , cryptoEngine , client ) proxy , err := socket . NewAuthProxy ( cfg , session , db , transport , client , logic ) if err != nil { return nil , fmt . Errorf ( " " , err ) } daemon := & Daemon { proxy : proxy , lock : lock , session : session , config : cfg , db : db , logic : logic , hasShutdown : false , } return daemon , nil }
New creates a new Daemon.
New creates a new Daemon .
// Recover from the panic and return the error; this way we can // delete the lockfile!