Merge pull request #690 from harshavardhana/pr_out_add_missing_string_method_for_errormessage_struct_as_well
This commit is contained in:
-14
@@ -45,17 +45,3 @@ const (
|
||||
const (
|
||||
exampleHostURL = "YOUR-EXAMPLE.COM"
|
||||
)
|
||||
|
||||
// ErrorMessage container for message reason encapsulation
|
||||
type ErrorMessage struct {
|
||||
Message string
|
||||
Error error
|
||||
}
|
||||
|
||||
// Content container for content message structure
|
||||
type Content struct {
|
||||
Filetype string `json:"ContentType"`
|
||||
Time string `json:"LastModified"`
|
||||
Size string `json:"Size"`
|
||||
Name string `json:"Name"`
|
||||
}
|
||||
|
||||
@@ -34,18 +34,7 @@ const (
|
||||
printDate = "2006-01-02 15:04:05 MST"
|
||||
)
|
||||
|
||||
func (c Content) String() string {
|
||||
message := console.Time("[%s] ", c.Time)
|
||||
message = message + console.Size("%6s ", c.Size)
|
||||
message = func() string {
|
||||
if c.Filetype == "inode/directory" {
|
||||
return message + console.Dir("%s", c.Name)
|
||||
}
|
||||
return message + console.File("%s", c.Name)
|
||||
}()
|
||||
return message
|
||||
}
|
||||
|
||||
// parseContent parse client Content container into printer struct
|
||||
func parseContent(c *client.Content) Content {
|
||||
content := Content{}
|
||||
content.Time = c.Time.Local().Format(printDate)
|
||||
@@ -94,8 +83,7 @@ func doList(clnt client.Client, targetURL string, recursive bool) error {
|
||||
contentName = strings.TrimPrefix(contentName, strings.TrimSuffix(targetURL, "/")+"/")
|
||||
}
|
||||
contentCh.Content.Name = contentName
|
||||
content := parseContent(contentCh.Content)
|
||||
console.Println(content)
|
||||
console.Println(parseContent(contentCh.Content))
|
||||
}
|
||||
if err != nil {
|
||||
return iodine.New(err, map[string]string{"Target": targetURL})
|
||||
|
||||
+11
-20
@@ -51,14 +51,13 @@ type Theme struct {
|
||||
Print *color.Color
|
||||
}
|
||||
|
||||
func readErrordata(data interface{}) (string, error) {
|
||||
func readErrorFromdata(data interface{}) error {
|
||||
st := structs.New(data)
|
||||
if st.IsZero() {
|
||||
return "", nil
|
||||
return nil
|
||||
}
|
||||
msg := st.Field("Message")
|
||||
msgErr := st.Field("Error")
|
||||
return msg.Value().(string), msgErr.Value().(error)
|
||||
return msgErr.Value().(error)
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -107,12 +106,10 @@ var (
|
||||
// Fatal prints a error message and exits
|
||||
Fatal = func(data interface{}) {
|
||||
defer os.Exit(1)
|
||||
msg, err := readErrordata(data)
|
||||
err := readErrorFromdata(data)
|
||||
if err != nil {
|
||||
if NoJSONPrint {
|
||||
reason := "Reason: " + iodine.ToError(err).Error()
|
||||
message := msg + ", " + reason
|
||||
print(themesDB[currThemeName].Error, message)
|
||||
print(themesDB[currThemeName].Error, data)
|
||||
if !NoDebugPrint {
|
||||
print(themesDB[currThemeName].Error, err)
|
||||
}
|
||||
@@ -125,12 +122,10 @@ var (
|
||||
// Fatalln prints a error message with a new line and exits
|
||||
Fatalln = func(data interface{}) {
|
||||
defer os.Exit(1)
|
||||
msg, err := readErrordata(data)
|
||||
err := readErrorFromdata(data)
|
||||
if err != nil {
|
||||
if NoJSONPrint {
|
||||
reason := "Reason: " + iodine.ToError(err).Error()
|
||||
message := msg + ", " + reason
|
||||
println(themesDB[currThemeName].Error, message)
|
||||
println(themesDB[currThemeName].Error, data)
|
||||
if !NoDebugPrint {
|
||||
println(themesDB[currThemeName].Error, err)
|
||||
}
|
||||
@@ -143,12 +138,10 @@ var (
|
||||
|
||||
// Error prints a error message
|
||||
Error = func(data interface{}) {
|
||||
msg, err := readErrordata(data)
|
||||
err := readErrorFromdata(data)
|
||||
if err != nil {
|
||||
if NoJSONPrint {
|
||||
reason := "Reason: " + iodine.ToError(err).Error()
|
||||
message := msg + ", " + reason
|
||||
print(themesDB[currThemeName].Error, message)
|
||||
print(themesDB[currThemeName].Error, data)
|
||||
if !NoDebugPrint {
|
||||
print(themesDB[currThemeName].Error, err)
|
||||
}
|
||||
@@ -160,12 +153,10 @@ var (
|
||||
}
|
||||
// Errorln prints a error message with a new line
|
||||
Errorln = func(data interface{}) {
|
||||
msg, err := readErrordata(data)
|
||||
err := readErrorFromdata(data)
|
||||
if err != nil {
|
||||
if NoJSONPrint {
|
||||
reason := "Reason: " + iodine.ToError(err).Error()
|
||||
message := msg + ", " + reason
|
||||
println(themesDB[currThemeName].Error, message)
|
||||
println(themesDB[currThemeName].Error, err)
|
||||
if !NoDebugPrint {
|
||||
println(themesDB[currThemeName].Error, err)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Minio Client (C) 2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// This package contains all the structs, their method wrappers for printer
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
// ErrorMessage container for message reason encapsulation
|
||||
type ErrorMessage struct {
|
||||
Message string
|
||||
Error error
|
||||
}
|
||||
|
||||
func (e ErrorMessage) String() string {
|
||||
var message string
|
||||
if e.Error != nil {
|
||||
switch e.Error.(type) {
|
||||
case iodine.Error:
|
||||
reason := "Reason: " + iodine.ToError(e.Error).Error()
|
||||
message = e.Message + ", " + reason
|
||||
default:
|
||||
reason := "Reason: " + e.Error.Error()
|
||||
message = e.Message + ", " + reason
|
||||
}
|
||||
}
|
||||
return message
|
||||
}
|
||||
|
||||
// Content container for content message structure
|
||||
type Content struct {
|
||||
Filetype string `json:"ContentType"`
|
||||
Time string `json:"LastModified"`
|
||||
Size string `json:"Size"`
|
||||
Name string `json:"Name"`
|
||||
}
|
||||
|
||||
func (c Content) String() string {
|
||||
message := console.Time("[%s] ", c.Time)
|
||||
message = message + console.Size("%6s ", c.Size)
|
||||
message = func() string {
|
||||
if c.Filetype == "inode/directory" {
|
||||
return message + console.Dir("%s", c.Name)
|
||||
}
|
||||
return message + console.File("%s", c.Name)
|
||||
}()
|
||||
return message
|
||||
}
|
||||
Reference in New Issue
Block a user