1
0
mirror of https://github.com/minio/mc.git synced 2025-11-13 12:22:45 +03:00
Files
mc/print-structs.go

99 lines
2.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* 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 (
"fmt"
"github.com/minio/mc/pkg/console"
"github.com/minio/minio/pkg/iodine"
)
// ErrorMessage container for error reason encapsulation
type ErrorMessage struct {
Message string `json:"message"`
Error error `json:"error"`
}
// String string printer for error message
func (e ErrorMessage) String() string {
var message string
if e.Error != nil {
switch e.Error.(type) {
case iodine.Error:
reason := iodine.ToError(e.Error).Error()
message = e.Message + ", " + reason
default:
reason := e.Error.Error()
message = e.Message + ", " + reason
}
}
return message
}
// Content container for content message structure
type Content struct {
Filetype string `json:"content-type"`
Time string `json:"last-modified"`
Size string `json:"size"`
Name string `json:"name"`
}
// String string printer for Content metadata
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
}
// InfoMessage container for informational messages
type InfoMessage struct {
Message string `json:"message"`
}
// String string printer for informational message
func (i InfoMessage) String() string {
return i.Message
}
// CopyMessage container for file copy messages
type CopyMessage struct {
Message string `json:"message"`
Source string `json:"source"`
Target string `json:"target"`
}
// String string printer for copy message
func (c CopyMessage) String() string {
return fmt.Sprintf("%s -> %s", c.Source, c.Target)
}
// SyncMessage container for file sync messages, inherits CopyMessage
type SyncMessage CopyMessage
// String string printer for sync message
func (s SyncMessage) String() string {
return fmt.Sprintf("%s -> %s", s.Source, s.Target)
}