mirror of
https://github.com/minio/mc.git
synced 2025-11-14 23:42:27 +03:00
Handle json and regular printing for all commands in their own respective files for readability
This commit is contained in:
52
session-json.go
Normal file
52
session-json.go
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/minio/mc/pkg/console"
|
||||
)
|
||||
|
||||
// SessionJSONMessage json container for session messages
|
||||
type SessionJSONMessage struct {
|
||||
SessionID string `json:"sessionid"`
|
||||
Time string `json:"time"`
|
||||
CommandType string `json:"command-type"`
|
||||
CommandArgs []string `json:"command-args"`
|
||||
}
|
||||
|
||||
func (s sessionV2) String() string {
|
||||
if !globalJSONFlag {
|
||||
message := console.SessionID("%s -> ", s.SessionID)
|
||||
message = message + console.Time("[%s]", s.Header.When.Local().Format(printDate))
|
||||
message = message + console.Command(" %s %s", s.Header.CommandType, strings.Join(s.Header.CommandArgs, " "))
|
||||
return message + "\n"
|
||||
}
|
||||
sessionMesage := SessionJSONMessage{
|
||||
SessionID: s.SessionID,
|
||||
Time: s.Header.When.Local().Format(printDate),
|
||||
CommandType: s.Header.CommandType,
|
||||
CommandArgs: s.Header.CommandArgs,
|
||||
}
|
||||
sessionJSONBytes, err := json.Marshal(sessionMesage)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return string(sessionJSONBytes) + "\n"
|
||||
}
|
||||
Reference in New Issue
Block a user