func NewApp(cfg *Config) (*App, error) { app := new(App) app.closed = false app.cfg = cfg var err error if strings.Contains(cfg.Addr, "/") { app.listener, err = net.Listen("unix", cfg.Addr) } else { app.listener, err = net.Listen("tcp", cfg.Addr) } if err != nil { return nil, err } app.ldb, err = ledis.OpenWithConfig(&cfg.DB) if err != nil { return nil, err } return app, nil }
func NewApp(cfg *Config) (*App, error) { if len(cfg.DataDir) == 0 { return nil, fmt.Errorf("must set data_dir first") } if len(cfg.DB.DataDir) == 0 { cfg.DB.DataDir = cfg.DataDir } app := new(App) app.quit = make(chan struct{}) app.closed = false app.cfg = cfg var err error if strings.Contains(cfg.Addr, "/") { app.listener, err = net.Listen("unix", cfg.Addr) } else { app.listener, err = net.Listen("tcp", cfg.Addr) } if err != nil { return nil, err } if len(cfg.AccessLog) > 0 { if path.Dir(cfg.AccessLog) == "." { app.access, err = newAcessLog(path.Join(cfg.DataDir, cfg.AccessLog)) } else { app.access, err = newAcessLog(cfg.AccessLog) } if err != nil { return nil, err } } if app.ldb, err = ledis.OpenWithConfig(&cfg.DB); err != nil { return nil, err } app.m = newMaster(app) return app, nil }