Ejemplo n.º 1
0
// New returns a new HTTPServer
func New(conf *config.Config) (*Server, error) {
	directives := conf.GetDirectives()
	srv := &graceful.Server{
		NoSignalHandling: true,
		Timeout:          time.Duration(directives.Server.ShutdownTimeout) * time.Second,
		Server: &http.Server{
			Addr: fmt.Sprintf(":%d", directives.Server.Port),
		},
	}
	s := &Server{log: helpers.GetAppLogger(conf).WithField("module", "server"), srv: srv, conf: conf}
	if err := s.configureRouter(); err != nil {
		return nil, err
	}
	return s, nil
}
Ejemplo n.º 2
0
// New returns a new Daemon.
func New(conf *config.Config) (*Daemon, error) {
	d := &Daemon{}
	d.log = helpers.GetAppLogger(conf).WithField("module", "daemon")
	d.conf = conf
	d.stopChan = make(chan error, 1)
	d.trapChan = make(chan os.Signal, 1)
	d.printConfig()

	srv, err := server.New(conf)
	if err != nil {
		return nil, err
	}
	d.srv = srv
	return d, nil
}
Ejemplo n.º 3
0
// New returns an implementation of MetaDataController.
func New(conf *config.Config) (metadatacontroller.MetaDataController, error) {
	dirs := conf.GetDirectives()
	c := &Controller{
		namespace:          dirs.MetaData.OCSQL.Namespace,
		temporaryNamespace: dirs.MetaData.OCSQL.TemporaryNamespace,
		log:                helpers.GetAppLogger(conf).WithField("module", "metadata:controller:ocsql"),
		conf:               conf,
	}

	if err := os.MkdirAll(dirs.MetaData.OCSQL.Namespace, 0755); err != nil {
		return nil, err
	}

	if err := os.MkdirAll(dirs.MetaData.OCSQL.TemporaryNamespace, 0755); err != nil {
		return nil, err
	}

	db, err := gorm.Open("mysql", dirs.MetaData.OCSQL.DSN)
	if err != nil {
		c.log.Error(err)
		return nil, err
	}

	if dirs.MetaData.OCSQL.SQLLogEnabled {
		sqlLog := helpers.NewLogger("info", dirs.MetaData.OCSQL.SQLLog,
			dirs.MetaData.OCSQL.SQLLogMaxSize, dirs.MetaData.OCSQL.SQLLogMaxAge,
			dirs.MetaData.OCSQL.SQLLogMaxBackups)
		db.SetLogger(sqlLog)
		db.LogMode(true)
	}
	db.DB().SetMaxIdleConns(conf.GetDirectives().MetaData.OCSQL.MaxSQLIdleConnections)
	db.DB().SetMaxOpenConns(conf.GetDirectives().MetaData.OCSQL.MaxSQLConcurrentConnections)

	err = db.AutoMigrate(&Record{}).Error
	if err != nil {
		return nil, err
	}

	c.db = db
	return c, nil
}