Implementing the new logging infrastructure

Moved logging to the new logging infrastructure by removing the use of
ColorLog() function. Added more documentation. Also fixed some typos in
comments and function names.
This commit is contained in:
Faissal Elamraoui
2016-11-13 15:14:48 +01:00
parent 0e54238559
commit cf7aef47f0
26 changed files with 421 additions and 525 deletions

21
fix.go
View File

@ -1,6 +1,7 @@
package main
import (
"fmt"
"go/parser"
"go/token"
"io/ioutil"
@ -8,7 +9,6 @@ import (
"path/filepath"
"regexp"
"strings"
"fmt"
)
var cmdFix = &Command{
@ -28,11 +28,12 @@ func init() {
func runFix(cmd *Command, args []string) int {
ShowShortVersionBanner()
ColorLog("[INFO] Upgrading the application...\n")
logger.Info("Upgrading the application...")
dir, err := os.Getwd()
if err != nil {
ColorLog("[ERRO] GetCurrent Path:%s\n", err)
logger.Fatalf("Error while getting the current working directory: %s", err)
}
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
if strings.HasPrefix(info.Name(), ".") {
@ -49,11 +50,11 @@ func runFix(cmd *Command, args []string) int {
err = fixFile(path)
fmt.Println("\tfix\t", path)
if err != nil {
ColorLog("[ERRO] Could not fix file: %s\n", err)
logger.Errorf("Could not fix file: %s", err)
}
return err
})
ColorLog("[INFO] Upgrade done!\n")
logger.Success("Upgrade done!")
return 0
}
@ -167,18 +168,18 @@ func fixFile(file string) error {
}
fixed := rp.Replace(string(content))
// forword the RequestBody from the replace
// Forword the RequestBody from the replace
// "Input.Request", "Input.Context.Request",
fixed = strings.Replace(fixed, "Input.Context.RequestBody", "Input.RequestBody", -1)
// regexp replace
// Regexp replace
pareg := regexp.MustCompile(`(Input.Params\[")(.*)("])`)
fixed = pareg.ReplaceAllString(fixed, "Input.Param(\"$2\")")
pareg = regexp.MustCompile(`(Input.Data\[\")(.*)(\"\])(\s)(=)(\s)(.*)`)
fixed = pareg.ReplaceAllString(fixed, "Input.SetData(\"$2\", $7)")
pareg = regexp.MustCompile(`(Input.Data\[\")(.*)(\"\])`)
fixed = pareg.ReplaceAllString(fixed, "Input.Data(\"$2\")")
// fix the cache object Put method
// Fix the cache object Put method
pareg = regexp.MustCompile(`(\.Put\(\")(.*)(\",)(\s)(.*)(,\s*)([^\*.]*)(\))`)
if pareg.MatchString(fixed) && strings.HasSuffix(file, ".go") {
fixed = pareg.ReplaceAllString(fixed, ".Put(\"$2\", $5, $7*time.Second)")
@ -199,11 +200,11 @@ func fixFile(file string) error {
fixed = strings.Replace(fixed, "import (", "import (\n\t\"time\"", 1)
}
}
// replace the v.Apis in docs.go
// Replace the v.Apis in docs.go
if strings.Contains(file, "docs.go") {
fixed = strings.Replace(fixed, "v.Apis", "v.APIs", -1)
}
// replace the config file
// Replace the config file
if strings.HasSuffix(file, ".conf") {
fixed = strings.Replace(fixed, "HttpCertFile", "HTTPSCertFile", -1)
fixed = strings.Replace(fixed, "HttpKeyFile", "HTTPSKeyFile", -1)