本文整理匯總了Golang中github.com/minio/mc/pkg/console.Fatalf函數的典型用法代碼示例。如果您正苦於以下問題:Golang Fatalf函數的具體用法?Golang Fatalf怎麽用?Golang Fatalf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Fatalf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runMakeBucketCmd
// runMakeBucketCmd is the handler for mc mb command
func runMakeBucketCmd(ctx *cli.Context) {
if !ctx.Args().Present() || ctx.Args().First() == "help" {
cli.ShowCommandHelpAndExit(ctx, "mb", 1) // last argument is exit code
}
if !isMcConfigExists() {
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
}
config := mustGetMcConfig()
for _, arg := range ctx.Args() {
targetURL, err := getExpandedURL(arg, config.Aliases)
if err != nil {
switch e := iodine.ToError(err).(type) {
case errUnsupportedScheme:
console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
default:
console.Fatalf("Unable to parse argument %s. %s\n", arg, err)
}
}
msg, err := doMakeBucketCmd(targetURL)
if err != nil {
console.Fatalln(msg)
}
console.Infoln(msg)
}
}
示例2: runListCmd
// runListCmd - is a handler for mc ls command
func runListCmd(ctx *cli.Context) {
args := ctx.Args()
if globalAliasFlag {
if !ctx.Args().Present() {
args = []string{"."}
}
} else if !ctx.Args().Present() || ctx.Args().First() == "help" {
cli.ShowCommandHelpAndExit(ctx, "ls", 1) // last argument is exit code
}
config := mustGetMcConfig()
for _, arg := range args {
targetURL, err := getExpandedURL(arg, config.Aliases)
if err != nil {
switch e := iodine.ToError(err).(type) {
case errUnsupportedScheme:
console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
default:
console.Fatalf("Unable to parse argument %s. %s\n", arg, err)
}
}
// if recursive strip off the "..."
newTargetURL := stripRecursiveURL(targetURL)
err = doListCmd(newTargetURL, isURLRecursive(targetURL))
if err != nil {
console.Fatalf("Failed to list : %s. %s\n", targetURL, err)
}
}
}
示例3: runAccessCmd
func runAccessCmd(ctx *cli.Context) {
if !ctx.Args().Present() || ctx.Args().First() == "help" {
cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code
}
config := mustGetMcConfig()
acl := bucketACL(ctx.Args().First())
if !acl.isValidBucketACL() {
console.Fatalf("Valid types are [private, public, readonly]. %s\n", errInvalidACL{acl: acl.String()})
}
for _, arg := range ctx.Args().Tail() {
targetURL, err := getExpandedURL(arg, config.Aliases)
if err != nil {
switch e := iodine.ToError(err).(type) {
case errUnsupportedScheme:
console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
default:
console.Fatalf("Unable to parse argument %s. %s\n", arg, err)
}
}
msg, err := doUpdateAccessCmd(targetURL, acl)
if err != nil {
console.Fatalln(msg)
}
console.Infoln(msg)
}
}
示例4: checkCopySyntaxTypeB
// checkCopySyntaxTypeB verifies if the source is a valid file and target is a valid dir.
func checkCopySyntaxTypeB(srcURLs []string, tgtURL string) {
if len(srcURLs) != 1 {
console.Fatalf("Invalid number of source arguments to copy command. %s\n", NewIodine(iodine.New(errInvalidArgument{}, nil)))
}
srcURL := srcURLs[0]
_, srcContent, err := url2Stat(srcURL)
// Source exist?.
if err != nil {
console.Fatalf("Unable to stat source ‘%s’. %s\n", srcURL, NewIodine(iodine.New(err, nil)))
}
if srcContent.Type.IsDir() {
console.Fatalf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively. %s\n", srcURL, srcURL, NewIodine(iodine.New(errInvalidArgument{}, nil)))
}
if !srcContent.Type.IsRegular() {
console.Fatalf("Source ‘%s’ is not a file. %s\n", srcURL, NewIodine(iodine.New(errInvalidArgument{}, nil)))
}
_, tgtContent, err := url2Stat(tgtURL)
// Target exist?.
if err == nil {
if !tgtContent.Type.IsDir() {
console.Fatalf("Target ‘%s’ is not a folder. %s\n", tgtURL, NewIodine(iodine.New(errInvalidArgument{}, nil)))
}
}
}
示例5: runCastCmd
func runCastCmd(ctx *cli.Context) {
checkCastSyntax(ctx)
session := newSessionV2()
var err error
session.Header.CommandType = "cast"
session.Header.RootPath, err = os.Getwd()
if err != nil {
session.Close()
session.Delete()
console.Fatalf("Unable to get current working folder. %s\n", err)
}
// extract URLs.
session.Header.CommandArgs, err = args2URLs(ctx.Args())
if err != nil {
session.Close()
session.Delete()
console.Fatalf("One or more unknown URL types found in %s. %s\n", ctx.Args(), err)
}
doCastCmdSession(session)
session.Close()
session.Delete()
}
示例6: runCatCmd
func runCatCmd(ctx *cli.Context) {
if !ctx.Args().Present() || ctx.Args().First() == "help" {
cli.ShowCommandHelpAndExit(ctx, "cat", 1) // last argument is exit code
}
if !isMcConfigExists() {
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
}
config := mustGetMcConfig()
// Convert arguments to URLs: expand alias, fix format...
for _, arg := range ctx.Args() {
sourceURL, err := getExpandedURL(arg, config.Aliases)
if err != nil {
switch e := iodine.ToError(err).(type) {
case errUnsupportedScheme:
console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
default:
console.Fatalf("Unable to parse argument %s. %s\n", arg, err)
}
}
errorMsg, err := doCatCmd(sourceURL)
if err != nil {
console.Fatalln(errorMsg)
}
}
}
示例7: checkConfig
// Check for the environment early on and gracefully report.
func checkConfig() {
_, err := user.Current()
if err != nil {
console.Fatalf("Unable to determine current user. %s\n", err)
}
// Ensures config file is sane
_, err = getMcConfig()
if err != nil {
console.Fatalf("Unable to read config file. %s\n", err)
}
}
示例8: mustGetHostConfig
// mustGetHostConfig retrieves host specific configuration such as access keys, exits upon error
func mustGetHostConfig(URL string) *hostConfig {
hostCfg, err := getHostConfig(URL)
if err != nil {
console.Fatalf("Unable to retrieve host configuration. %s\n", NewIodine(iodine.New(err, nil)))
}
return hostCfg
}
示例9: loadSessionV2
// loadSession - reads session file if exists and re-initiates internal variables
func loadSessionV2(sid string) (*sessionV2, error) {
if !isSessionDirExists() {
return nil, NewIodine(iodine.New(errInvalidArgument{}, nil))
}
sessionFile := getSessionFile(sid)
_, err := os.Stat(sessionFile)
if err != nil {
return nil, NewIodine(iodine.New(err, nil))
}
s := &sessionV2{}
s.Header = &sessionV2Header{}
s.SessionID = sid
s.Header.Version = "1.1.0"
qs, err := quick.New(s.Header)
if err != nil {
return nil, NewIodine(iodine.New(err, nil))
}
err = qs.Load(sessionFile)
if err != nil {
return nil, NewIodine(iodine.New(err, nil))
}
s.mutex = new(sync.Mutex)
s.Header = qs.Data().(*sessionV2Header)
s.DataFP, err = os.Open(getSessionDataFile(s.SessionID))
if err != nil {
console.Fatalf("Unable to open session data file \""+getSessionDataFile(s.SessionID)+"\". %s", NewIodine(iodine.New(errNotConfigured{}, nil)))
}
return s, nil
}
示例10: mustGetMcConfigDir
// mustGetMcConfigDir - construct minio client config folder or fail
func mustGetMcConfigDir() (configDir string) {
configDir, err := getMcConfigDir()
if err != nil {
console.Fatalf("Unable to determine default configuration folder. %s\n", NewIodine(iodine.New(err, nil)))
}
return configDir
}
示例11: mustGetMcConfigPath
// mustGetMcConfigPath - similar to getMcConfigPath, ignores errors
func mustGetMcConfigPath() string {
p, err := getMcConfigPath()
if err != nil {
console.Fatalf("Unable to determine default config path. %s\n", NewIodine(iodine.New(err, nil)))
}
return p
}
示例12: mustNewConfig
// mustNewConfig instantiates a new config handler, exists upon error
func mustNewConfig() quick.Config {
config, err := newConfig()
if err != nil {
console.Fatalf("Unable to instantiate a new config handler. %s\n", NewIodine(iodine.New(err, nil)))
}
return config
}
示例13: mustGetMcConfig
// mustGetMcConfig - reads configuration file and returns configs, exits on error
func mustGetMcConfig() *configV1 {
config, err := getMcConfig()
if err != nil {
console.Fatalf("Unable to retrieve mc configuration. %s\n", err)
}
return config
}
示例14: checkCopySyntax
// NOTE: All the parse rules should reduced to A: Copy(Source, Target).
//
// * VALID RULES
// =======================
// A: copy(f, f) -> copy(f, f)
// B: copy(f, d) -> copy(f, d/f) -> A
// C: copy(d1..., d2) -> []copy(d1/f, d1/d2/f) -> []A
//
// * INVALID RULES
// =========================
// A: copy(d, *)
// B: copy(d..., f)
// C: copy(*, d...)
//
func checkCopySyntax(ctx *cli.Context) {
if len(ctx.Args()) < 2 || ctx.Args().First() == "help" {
cli.ShowCommandHelpAndExit(ctx, "cp", 1) // last argument is exit code.
}
// extract URLs.
URLs, err := args2URLs(ctx.Args())
if err != nil {
console.Fatalf("One or more unknown URL types found %s. %s\n", ctx.Args(), iodine.New(err, nil))
}
srcURLs := URLs[:len(URLs)-1]
tgtURL := URLs[len(URLs)-1]
/****** Generic rules *******/
// Recursive URLs are not allowed in target.
if isURLRecursive(tgtURL) {
console.Fatalf("Target ‘%s’ cannot be recursive. %s\n", tgtURL, iodine.New(err, nil))
}
switch guessCopyURLType(srcURLs, tgtURL) {
case copyURLsTypeA: // Source is already a regular file.
// no verification needed, pass through
case copyURLsTypeB: // Source is already a regular file.
// no verification needed, pass through
case copyURLsTypeC:
for _, srcURL := range srcURLs {
srcURL = stripRecursiveURL(srcURL)
_, srcContent, err := url2Stat(srcURL)
// Source exist?.
if err != nil {
console.Fatalf("Unable to stat source ‘%s’. %s\n", srcURL, iodine.New(err, nil))
}
if srcContent.Type.IsRegular() { // Ellipses is supported only for directories.
console.Fatalf("Source ‘%s’ is not a directory. %s\n", stripRecursiveURL(srcURL), iodine.New(err, nil))
}
}
case copyURLsTypeD:
// only verify if target is a valid directory and exists
if !isTargetURLDir(tgtURL) {
console.Fatalf("Target ‘%s’ should be a directory and exist, when we have a mixture of files and folders in source\n", tgtURL)
}
default:
console.Fatalln("Invalid arguments. Unable to determine how to copy. Please report this issue at https://github.com/minio/mc/issues")
}
}
示例15: checkCastSyntaxTypeB
func checkCastSyntaxTypeB(srcURL string, tgtURLs []string) {
if len(tgtURLs) == 0 && tgtURLs == nil {
console.Fatalf("Invalid number of target arguments to cast command. %s\n", NewIodine(iodine.New(errInvalidArgument{}, nil)))
}
_, srcContent, err := url2Stat(srcURL)
// Source exist?.
if err != nil {
console.Fatalf("Unable to stat source ‘%s’. %s\n", srcURL, NewIodine(iodine.New(err, nil)))
}
if srcContent.Type.IsDir() {
console.Fatalf("Source ‘%s’ is a folder. Use ‘%s...’ argument to cast this folder and its contents recursively. %s\n", srcURL, srcURL, NewIodine(iodine.New(errInvalidArgument{}, nil)))
}
if !srcContent.Type.IsRegular() {
console.Fatalf("Source ‘%s’ is not a file. %s\n", srcURL, NewIodine(iodine.New(errInvalidArgument{}, nil)))
}
// targetURL can be folder or file, internally TypeB calls TypeA if it finds a file
}