本文整理匯總了Golang中github.com/clawio/clawiod/config.Config類的典型用法代碼示例。如果您正苦於以下問題:Golang Config類的具體用法?Golang Config怎麽用?Golang Config使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Config類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: New
// New returns a new Service.
func New(cfg *config.Config) (services.Service, error) {
dirs := cfg.GetDirectives()
authenticator := lib.NewAuthenticator(dirs.Server.JWTSecret, dirs.Server.JWTSigningMethod)
dataController, err := data.GetDataController(cfg)
if err != nil {
return nil, err
}
authenticationController, err := authentication.GetAuthenticationController(cfg)
if err != nil {
return nil, err
}
metaDataController, err := metadata.GetMetaDataController(cfg)
if err != nil {
return nil, err
}
if err := os.MkdirAll(dirs.OCWebDAV.ChunksNamespace, 0755); err != nil {
return nil, err
}
if err := os.MkdirAll(dirs.OCWebDAV.ChunksTemporaryNamespace, 0755); err != nil {
return nil, err
}
return &svc{conf: cfg, authenticator: authenticator, dataController: dataController, metaDataController: metaDataController, authenticationController: authenticationController}, nil
}
示例2: handleCPU
func handleCPU(cfg *config.Config) {
cpu := cfg.GetDirectives().Server.CPU
// Set CPU capacity
err := setCPU(cpu)
if err != nil {
log.Fatal("Cannot tweak CPU: ", err)
}
}
示例3: handleShowConfig
func handleShowConfig(cfg *config.Config) {
dirs := cfg.GetDirectives()
data, err := json.MarshalIndent(dirs, "", " ")
if err != nil {
log.Fatal(err)
}
fmt.Println(string(data))
os.Exit(0)
}
示例4: GetMetaDataController
// GetMetaDataController returns an already configured meta data controller.
func GetMetaDataController(conf *config.Config) (metadatacontroller.MetaDataController, error) {
dirs := conf.GetDirectives()
switch dirs.MetaData.Type {
case "simple":
return simple.New(conf)
case "ocsql":
return ocsql.New(conf)
default:
return nil, errors.New("metadata type " + dirs.MetaData.Type + "does not exist")
}
}
示例5: GetAuthenticationController
// GetAuthenticationController returns an already configured authentication controller.
func GetAuthenticationController(conf *config.Config) (authenticationcontroller.AuthenticationController, error) {
dirs := conf.GetDirectives()
switch dirs.Authentication.Type {
case "memory":
return memory.New(conf)
case "sql":
return sql.New(conf)
default:
return nil, errors.New("authentication type " + dirs.Authentication.Type + " does not exist")
}
}
示例6: New
// New returns an AuthenticationControler that
// stores users in memory. This controller is for testing purposes.
func New(conf *config.Config) (authenticationcontroller.AuthenticationController, error) {
dirs := conf.GetDirectives()
authenticator := lib.NewAuthenticator(dirs.Server.JWTSecret, dirs.Server.JWTSigningMethod)
users, err := decodeUsers(dirs.Authentication.Memory.Users)
if err != nil {
return nil, err
}
return &controller{
users: users,
authenticator: authenticator,
}, nil
}
示例7: New
// 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
}
示例8: New
// New returns an implementation of MetaDataController.
func New(conf *config.Config) (metadatacontroller.MetaDataController, error) {
dirs := conf.GetDirectives()
c := &controller{
namespace: dirs.MetaData.Simple.Namespace,
temporaryNamespace: dirs.MetaData.Simple.TemporaryNamespace,
}
if err := os.MkdirAll(dirs.MetaData.Simple.Namespace, 0755); err != nil {
return nil, err
}
if err := os.MkdirAll(dirs.MetaData.Simple.TemporaryNamespace, 0755); err != nil {
return nil, err
}
return c, nil
}
示例9: getServices
func getServices(conf *config.Config) ([]services.Service, error) {
enabledServices := conf.GetDirectives().Server.EnabledServices
services := []services.Service{}
if isServiceEnabled("authentication", enabledServices) {
authenticationService, err := authentication.New(conf)
if err != nil {
return services, err
}
services = append(services, authenticationService)
}
if isServiceEnabled("metadata", enabledServices) {
metaDataService, err := metadata.New(conf)
if err != nil {
return services, err
}
services = append(services, metaDataService)
}
if isServiceEnabled("data", enabledServices) {
dataService, err := data.New(conf)
if err != nil {
return services, err
}
services = append(services, dataService)
}
if isServiceEnabled("webdav", enabledServices) {
webDAVService, err := webdav.New(conf)
if err != nil {
return services, err
}
services = append(services, webDAVService)
}
if isServiceEnabled("ocwebdav", enabledServices) {
OCWebDAVService, err := ocwebdav.New(conf)
if err != nil {
return services, err
}
services = append(services, OCWebDAVService)
}
return services, nil
}
示例10: New
// New returns an AuthenticationControler that uses a SQL database for handling
// users and JWT for tokens.
func New(conf *config.Config) (authenticationcontroller.AuthenticationController, error) {
dirs := conf.GetDirectives()
authenticator := lib.NewAuthenticator(dirs.Server.JWTSecret, dirs.Server.JWTSigningMethod)
db, err := gorm.Open(dirs.Authentication.SQL.Driver, dirs.Authentication.SQL.DSN)
if err != nil {
return nil, err
}
err = db.AutoMigrate(&userRecord{}).Error
if err != nil {
return nil, err
}
return &controller{
conf: conf,
db: db,
authenticator: authenticator,
}, nil
}
示例11: New
// 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
}
示例12: New
// New returns a new Service.
func New(cfg *config.Config) (services.Service, error) {
dirs := cfg.GetDirectives()
authenticator := lib.NewAuthenticator(dirs.Server.JWTSecret, dirs.Server.JWTSigningMethod)
dataController, err := data.GetDataController(cfg)
if err != nil {
return nil, err
}
authenticationController, err := authentication.GetAuthenticationController(cfg)
if err != nil {
return nil, err
}
metaDataController, err := metadata.GetMetaDataController(cfg)
if err != nil {
return nil, err
}
return &svc{conf: cfg, authenticator: authenticator, dataController: dataController, metaDataController: metaDataController, authenticationController: authenticationController}, nil
}
示例13: GetHTTPAccessLogger
// GetHTTPAccessLogger returns an already configured log for logging out HTTP requests.
func GetHTTPAccessLogger(conf *config.Config) *logrus.Entry {
dirs := conf.GetDirectives()
return NewLogger(dirs.Server.HTTPAccessLogLevel, dirs.Server.HTTPAccessLog,
dirs.Server.HTTPAccessLogMaxSize, dirs.Server.HTTPAccessLogMaxAge, dirs.Server.HTTPAccessLogMaxBackups)
}