本文整理匯總了Golang中github.com/minio/minio-xl/pkg/quick.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestDeepDiff
func (s *MySuite) TestDeepDiff(c *C) {
type myStruct struct {
Version string
User string
Password string
Folders []string
}
saveMe := myStruct{"1", "guest", "nopassword", []string{"Work", "Documents", "Music"}}
config, err := quick.New(&saveMe)
c.Assert(err, IsNil)
c.Assert(config, Not(IsNil))
mismatch := myStruct{"1", "Guest", "nopassword", []string{"Work", "documents", "Music"}}
newConfig, err := quick.New(&mismatch)
c.Assert(err, IsNil)
c.Assert(newConfig, Not(IsNil))
fields, err := config.DeepDiff(newConfig)
c.Assert(err, IsNil)
c.Assert(len(fields), Equals, 2)
// Uncomment for debugging
// for i, field := range fields {
// fmt.Printf("DeepDiff[%d]: %s=%v\n", i, field.Name(), field.Value())
// }
}
示例2: TestSaveLoad
func (s *MySuite) TestSaveLoad(c *C) {
defer os.RemoveAll("test.json")
type myStruct struct {
Version string
User string
Password string
Folders []string
}
saveMe := myStruct{"1", "guest", "nopassword", []string{"Work", "Documents", "Music"}}
config, err := quick.New(&saveMe)
c.Assert(err, IsNil)
c.Assert(config, Not(IsNil))
err = config.Save("test.json")
c.Assert(err, IsNil)
loadMe := myStruct{Version: "1"}
newConfig, err := quick.New(&loadMe)
c.Assert(err, IsNil)
c.Assert(newConfig, Not(IsNil))
err = newConfig.Load("test.json")
c.Assert(err, IsNil)
c.Assert(config.Data(), DeepEquals, newConfig.Data())
c.Assert(config.Data(), DeepEquals, &loadMe)
mismatch := myStruct{"1.1", "guest", "nopassword", []string{"Work", "Documents", "Music"}}
c.Assert(newConfig.Data(), Not(DeepEquals), &mismatch)
}
示例3: getMcConfig
// getMcConfig - reads configuration file and returns config
func getMcConfig() (*configV5, *probe.Error) {
if !isMcConfigExists() {
return nil, errInvalidArgument().Trace()
}
configFile, err := getMcConfigPath()
if err != nil {
return nil, err.Trace()
}
// Cached in private global variable.
if v := cache.Get(); v != nil { // Use previously cached config.
return v.(quick.Config).Data().(*configV5), nil
}
conf := new(configV5)
conf.Version = globalMCConfigVersion
qconf, err := quick.New(conf)
if err != nil {
return nil, err.Trace()
}
err = qconf.Load(configFile)
if err != nil {
return nil, err.Trace()
}
cache.Put(qconf)
return qconf.Data().(*configV5), nil
}
示例4: migrateSessionV2ToV3
func migrateSessionV2ToV3() {
for _, sid := range getSessionIDs() {
oldSessionV2Header, err := loadSessionV2(sid)
fatalIf(err.Trace(sid), "Unable to load version ‘1.1.0’. Migration failed please report this issue at https://github.com/minio/mc/issues.")
if oldSessionV2Header.Version == "3" {
return
}
newSessionV3Header := &sessionV3Header{}
newSessionV3Header.Version = "3"
newSessionV3Header.When = oldSessionV2Header.When
newSessionV3Header.RootPath = oldSessionV2Header.RootPath
newSessionV3Header.CommandType = oldSessionV2Header.CommandType
newSessionV3Header.CommandArgs = oldSessionV2Header.CommandArgs
newSessionV3Header.LastCopied = oldSessionV2Header.LastCopied
newSessionV3Header.TotalBytes = oldSessionV2Header.TotalBytes
newSessionV3Header.TotalObjects = oldSessionV2Header.TotalObjects
qs, err := quick.New(newSessionV3Header)
fatalIf(err.Trace(sid), "Unable to initialize quick config.")
sessionFile, err := getSessionFile(sid)
fatalIf(err.Trace(sid), "Unable to get session file.")
err = qs.Save(sessionFile)
fatalIf(err.Trace(sid), "Saving new session file for version ‘3’ failed.")
}
}
示例5: removeAlias
// removeAlias - remove alias
func removeAlias(alias string) {
if strings.TrimSpace(alias) == "" {
fatalIf(errDummy().Trace(), "Alias or URL cannot be empty.")
}
config, err := newConfig()
fatalIf(err.Trace(), "Failed to initialize ‘quick’ configuration data structure.")
configPath := mustGetMcConfigPath()
err = config.Load(configPath)
fatalIf(err.Trace(configPath), "Unable to load config path")
if !isValidAliasName(alias) {
fatalIf(errDummy().Trace(), fmt.Sprintf("Alias name ‘%s’ is invalid, valid examples are: mybucket, Area51, Grand-Nagus", alias))
}
// convert interface{} back to its original struct
newConf := config.Data().(*configV5)
if _, ok := newConf.Aliases[alias]; !ok {
fatalIf(errDummy().Trace(), fmt.Sprintf("Alias ‘%s’ does not exist.", alias))
}
delete(newConf.Aliases, alias)
newConfig, err := quick.New(newConf)
fatalIf(err.Trace(globalMCConfigVersion), "Failed to initialize ‘quick’ configuration data structure.")
err = writeConfig(newConfig)
fatalIf(err.Trace(alias), "Unable to save alias ‘"+alias+"’.")
Prints("%s\n", AliasMessage{
op: "remove",
Alias: alias,
})
}
示例6: migrateConfigV101ToV2
// Migrate from config ‘1.0.1’ to ‘2’. Drop semantic versioning and move to integer versioning. No other changes.
func migrateConfigV101ToV2() {
if !isMcConfigExists() {
return
}
mcCfgV101, err := quick.Load(mustGetMcConfigPath(), newConfigV101())
fatalIf(err.Trace(), "Unable to load config version ‘1.0.1’.")
// update to newer version
if mcCfgV101.Version() != "1.0.1" {
return
}
cfgV2 := newConfigV2()
// Copy aliases.
for k, v := range mcCfgV101.Data().(*configV101).Aliases {
cfgV2.Aliases[k] = v
}
// Copy hosts.
for k, hostCfgV101 := range mcCfgV101.Data().(*configV101).Hosts {
cfgV2.Hosts[k] = hostConfigV2{
AccessKeyID: hostCfgV101.AccessKeyID,
SecretAccessKey: hostCfgV101.SecretAccessKey,
}
}
mcCfgV2, err := quick.New(cfgV2)
fatalIf(err.Trace(), "Unable to initialize quick config for config version ‘2’.")
err = mcCfgV2.Save(mustGetMcConfigPath())
fatalIf(err.Trace(), "Unable to save config version ‘2’.")
console.Infof("Successfully migrated %s from version ‘1.0.1’ to version ‘2’.\n", mustGetMcConfigPath())
}
示例7: removeHost
func removeHost(hostGlob string) {
if strings.TrimSpace(hostGlob) == "" {
fatalIf(errDummy().Trace(), "Alias or URL cannot be empty.")
}
if strings.TrimSpace(hostGlob) == "dl.minio.io:9000" {
fatalIf(errDummy().Trace(), "‘"+hostGlob+"’ is reserved hostname and cannot be removed.")
}
config, err := newConfig()
fatalIf(err.Trace(globalMCConfigVersion), "Failed to initialize ‘quick’ configuration data structure.")
configPath := mustGetMcConfigPath()
err = config.Load(configPath)
fatalIf(err.Trace(configPath), "Unable to load config path")
// convert interface{} back to its original struct
newConf := config.Data().(*configV5)
if _, ok := newConf.Hosts[hostGlob]; !ok {
fatalIf(errDummy().Trace(), fmt.Sprintf("Host glob ‘%s’ does not exist.", hostGlob))
}
delete(newConf.Hosts, hostGlob)
newConfig, err := quick.New(newConf)
fatalIf(err.Trace(globalMCConfigVersion), "Failed to initialize ‘quick’ configuration data structure.")
err = writeConfig(newConfig)
fatalIf(err.Trace(hostGlob), "Unable to save host glob ‘"+hostGlob+"’.")
printMsg(hostMessage{op: "remove", Host: hostGlob})
}
示例8: migrateConfigV4ToV5
// Migrate config version ‘4’ to ‘5’
func migrateConfigV4ToV5() {
if !isMcConfigExists() {
return
}
mcConfigV4, err := quick.Load(mustGetMcConfigPath(), newConfigV4())
fatalIf(err.Trace(), "Unable to load mc config V2.")
// update to newer version
if mcConfigV4.Version() == "4" {
confV5 := new(configV5)
confV5.Aliases = mcConfigV4.Data().(*configV4).Aliases
confV5.Hosts = make(map[string]hostConfig)
for host, hostConf := range mcConfigV4.Data().(*configV4).Hosts {
confV5.Hosts[host] = hostConfig{
AccessKeyID: hostConf.AccessKeyID,
SecretAccessKey: hostConf.SecretAccessKey,
API: "S3v4",
}
}
confV5.Version = globalMCConfigVersion
mcNewConfigV5, err := quick.New(confV5)
fatalIf(err.Trace(), "Unable to initialize quick config for config version ‘5’.")
err = mcNewConfigV5.Save(mustGetMcConfigPath())
fatalIf(err.Trace(), "Unable to save config version ‘5’.")
console.Infof("Successfully migrated %s from version ‘4’ to version ‘5’.\n", mustGetMcConfigPath())
}
}
示例9: newConfig
// newConfig - get new config interface
func newConfig() (config quick.Config, err *probe.Error) {
config, err = quick.New(newConfigV5())
if err != nil {
return nil, err.Trace()
}
return config, nil
}
示例10: migrateConfigV6ToV7
// Migrate config version ‘6’ to ‘7'. Remove alias map and introduce
// named Host config. Also no more glob match for host config entries.
func migrateConfigV6ToV7() {
if !isMcConfigExists() {
return
}
mcCfgV6, err := quick.Load(mustGetMcConfigPath(), newConfigV6())
fatalIf(err.Trace(), "Unable to load mc config V6.")
if mcCfgV6.Version() != "6" {
return
}
cfgV7 := newConfigV7()
aliasIndex := 0
// We dropped alias support in v7. We only need to migrate host configs.
for host, hostCfgV6 := range mcCfgV6.Data().(*configV6).Hosts {
if hostCfgV6.AccessKeyID == "YOUR-ACCESS-KEY-ID-HERE" ||
hostCfgV6.SecretAccessKey == "YOUR-SECRET-ACCESS-KEY-HERE" ||
hostCfgV6.AccessKeyID == "" ||
hostCfgV6.SecretAccessKey == "" {
// Ignore default entries. configV7.loadDefaults() will re-insert them back.
} else if host == "https://s3.amazonaws.com" {
// Only one entry can exist for "s3" domain.
cfgV7.Hosts["s3"] = hostConfigV7{
URL: host,
AccessKey: hostCfgV6.AccessKeyID,
SecretKey: hostCfgV6.SecretAccessKey,
API: hostCfgV6.API,
}
} else if host == "https://storage.googleapis.com" {
// Only one entry can exist for "gcs" domain.
cfgV7.Hosts["gcs"] = hostConfigV7{
URL: host,
AccessKey: hostCfgV6.AccessKeyID,
SecretKey: hostCfgV6.SecretAccessKey,
API: hostCfgV6.API,
}
} else {
// Assign a generic "cloud1", cloud2..." key
// for all other entries that has valid keys set.
alias := fmt.Sprintf("cloud%d", aliasIndex)
aliasIndex++
cfgV7.Hosts[alias] = hostConfigV7{
URL: host,
AccessKey: hostCfgV6.AccessKeyID,
SecretKey: hostCfgV6.SecretAccessKey,
API: hostCfgV6.API,
}
}
}
// Load default settings.
cfgV7.loadDefaults()
mcNewCfgV7, err := quick.New(cfgV7)
fatalIf(err.Trace(), "Unable to initialize quick config for config version ‘7’.")
err = mcNewCfgV7.Save(mustGetMcConfigPath())
fatalIf(err.Trace(), "Unable to save config version ‘7’.")
console.Infof("Successfully migrated %s from version ‘6’ to version ‘7’.\n", mustGetMcConfigPath())
}
示例11: loadSessionV1
// loadSession - reads session file if exists and re-initiates internal variables
func loadSessionV1(sid string) (*sessionV1, *probe.Error) {
if !isSessionDirExists() {
return nil, probe.NewError(errors.New("Session folder does not exist."))
}
sessionFile, err := getSessionFileV1(sid)
if err != nil {
return nil, err.Trace(sid)
}
s := new(sessionV1)
s.Version = "1.0.0"
// map of command and files copied
s.URLs = nil
s.Lock = new(sync.Mutex)
s.Files = make(map[string]bool)
qs, err := quick.New(s)
if err != nil {
return nil, err.Trace(s.Version)
}
err = qs.Load(sessionFile)
if err != nil {
return nil, err.Trace(sessionFile, s.Version)
}
return qs.Data().(*sessionV1), nil
}
示例12: migrateConfigV2ToV3
// Migrate from config ‘2’ to ‘3’
func migrateConfigV2ToV3() {
if !isMcConfigExists() {
return
}
mcConfigV2, err := quick.Load(mustGetMcConfigPath(), newConfigV2())
fatalIf(err.Trace(), "Unable to load mc config V2.")
// update to newer version
if mcConfigV2.Version() == "2" {
confV3 := new(configV3)
confV3.Aliases = mcConfigV2.Data().(*configV2).Aliases
confV3.Hosts = make(map[string]struct {
AccessKeyID string `json:"access-key-id"`
SecretAccessKey string `json:"secret-access-key"`
})
for host, hostConf := range mcConfigV2.Data().(*configV2).Hosts {
newHostConf := struct {
AccessKeyID string `json:"access-key-id"`
SecretAccessKey string `json:"secret-access-key"`
}{}
newHostConf.AccessKeyID = hostConf.AccessKeyID
newHostConf.SecretAccessKey = hostConf.SecretAccessKey
confV3.Hosts[host] = newHostConf
}
confV3.Version = "3"
mcNewConfigV3, err := quick.New(confV3)
fatalIf(err.Trace(), "Unable to initialize quick config for config version ‘3’.")
err = mcNewConfigV3.Save(mustGetMcConfigPath())
fatalIf(err.Trace(), "Unable to save config version ‘3’.")
console.Infof("Successfully migrated %s from version ‘2’ to version ‘3’.\n", mustGetMcConfigPath())
}
}
示例13: migrateConfigV4ToV5
// Migrate config version ‘4’ to ‘5’. Rename hostConfigV4.Signature -> hostConfigV5.API.
func migrateConfigV4ToV5() {
if !isMcConfigExists() {
return
}
mcCfgV4, err := quick.Load(mustGetMcConfigPath(), newConfigV4())
fatalIf(err.Trace(), "Unable to load mc config V4.")
// update to newer version
if mcCfgV4.Version() != "4" {
return
}
cfgV5 := newConfigV5()
for k, v := range mcCfgV4.Data().(*configV4).Aliases {
cfgV5.Aliases[k] = v
}
for host, hostCfgV4 := range mcCfgV4.Data().(*configV4).Hosts {
cfgV5.Hosts[host] = hostConfigV5{
AccessKeyID: hostCfgV4.AccessKeyID,
SecretAccessKey: hostCfgV4.SecretAccessKey,
API: "v4", // Rename from .Signature to .API
}
}
mcNewCfgV5, err := quick.New(cfgV5)
fatalIf(err.Trace(), "Unable to initialize quick config for config version ‘5’.")
err = mcNewCfgV5.Save(mustGetMcConfigPath())
fatalIf(err.Trace(), "Unable to save config version ‘5’.")
console.Infof("Successfully migrated %s from version ‘4’ to version ‘5’.\n", mustGetMcConfigPath())
}
示例14: addAlias
// addAlias - add new aliases
func addAlias(alias, url string) {
if alias == "" || url == "" {
fatalIf(errDummy().Trace(), "Alias or URL cannot be empty.")
}
config, err := newConfig()
fatalIf(err.Trace(globalMCConfigVersion), "Failed to initialize ‘quick’ configuration data structure.")
err = config.Load(mustGetMcConfigPath())
fatalIf(err.Trace(), "Unable to load config path")
url = strings.TrimSuffix(url, "/")
if !strings.HasPrefix(url, "http") {
fatalIf(errDummy().Trace(), fmt.Sprintf("Invalid alias URL ‘%s’. Valid examples are: http://s3.amazonaws.com, https://yourbucket.example.com.", url))
}
if !isValidAliasName(alias) {
fatalIf(errDummy().Trace(), fmt.Sprintf("Alias name ‘%s’ is invalid, valid examples are: mybucket, Area51, Grand-Nagus", alias))
}
// convert interface{} back to its original struct
newConf := config.Data().(*configV5)
if oldURL, ok := newConf.Aliases[alias]; ok {
fatalIf(errDummy().Trace(), fmt.Sprintf("Alias ‘%s’ already exists for ‘%s’.", alias, oldURL))
}
newConf.Aliases[alias] = url
newConfig, err := quick.New(newConf)
fatalIf(err.Trace(globalMCConfigVersion), "Failed to initialize ‘quick’ configuration data structure.")
err = writeConfig(newConfig)
fatalIf(err.Trace(alias, url), "Unable to save alias ‘"+alias+"’.")
Prints("%s\n", AliasMessage{
op: "add",
Alias: alias,
URL: url,
})
}
示例15: Load
// Load shareDB entries from disk. Any entries held in memory are reset.
func (s *shareDBV1) Load(filename string) *probe.Error {
s.mutex.Lock()
defer s.mutex.Unlock()
// Check if the db file exist.
if _, err := os.Stat(filename); err != nil {
return probe.NewError(err)
}
// Initialize and load using quick package.
qs, err := quick.New(newShareDBV1())
if err != nil {
return err.Trace(filename)
}
err = qs.Load(filename)
if err != nil {
return err.Trace(filename)
}
// Copy map over.
for k, v := range qs.Data().(*shareDBV1).Shares {
s.Shares[k] = v
}
// Filter out expired entries and save changes back to disk.
s.deleteAllExpired()
s.save(filename)
return nil
}