Refactoring project to be more similar to other go project.

This commit is contained in:
Renan DelValle 2020-05-07 10:09:45 -07:00
parent bbccabcd27
commit d7db155d88
No known key found for this signature in database
GPG key ID: C240AD6D6F443EC9
10 changed files with 153 additions and 192 deletions

View file

@ -1,3 +1,17 @@
/**
* 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 internal
import (

View file

@ -27,15 +27,21 @@ import (
"github.com/spf13/cobra"
yaml "gopkg.in/yaml.v2"
)
type MonitorCmdConfig struct {
cmd *cobra.Command
monitorInterval, monitorTimeout time.Duration
statusList []string
Cmd *cobra.Command
MonitorInterval, MonitorTimeout time.Duration
StatusList []string
}
func toJSON(v interface{}) string {
var log *logrus.Logger
// Logger sets the logger available to the internal package
func Logger(l *logrus.Logger) {
log = l
}
// ToJSON converts an interface to a JSON formatted string
func ToJSON(v interface{}) string {
output, err := json.Marshal(v)
if err != nil {
@ -45,8 +51,7 @@ func toJSON(v interface{}) string {
return string(output)
}
func getLoggingLevels() string {
func GetLoggingLevels() string {
var buffer bytes.Buffer
for _, level := range logrus.AllLevels {
@ -57,16 +62,15 @@ func getLoggingLevels() string {
buffer.Truncate(buffer.Len() - 1)
return buffer.String()
}
func maintenanceMonitorPrint(hostResult map[string]bool, desiredStates []aurora.MaintenanceMode) {
func MaintenanceMonitorPrint(hostResult map[string]bool, desiredStates []aurora.MaintenanceMode, toJson bool) {
if len(hostResult) > 0 {
// Create anonymous struct for JSON formatting
output := struct {
DesiredStates []string `json:desired_states`
Transitioned []string `json:transitioned`
NonTransitioned []string `json:non-transitioned`
DesiredStates []string `json:"desired_states"`
Transitioned []string `json:"transitioned"`
NonTransitioned []string `json:"non-transitioned"`
}{
make([]string, 0),
make([]string, 0),
@ -86,7 +90,7 @@ func maintenanceMonitorPrint(hostResult map[string]bool, desiredStates []aurora.
}
if toJson {
fmt.Println(toJSON(output))
fmt.Println(ToJSON(output))
} else {
fmt.Printf("Entered %v status: %v\n", output.DesiredStates, output.Transitioned)
fmt.Printf("Did not enter %v status: %v\n", output.DesiredStates, output.NonTransitioned)

View file

@ -1,3 +1,17 @@
/**
* 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 internal
import (