more go.wit.com/log
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
b97b51855e
commit
bfdc9780f7
15
chomp.go
15
chomp.go
|
@ -6,11 +6,14 @@ package shell
|
||||||
send it anything, always get back a string
|
send it anything, always get back a string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import "log"
|
import (
|
||||||
import "fmt"
|
"fmt"
|
||||||
import "reflect"
|
"reflect"
|
||||||
import "strings"
|
"strings"
|
||||||
import "bytes"
|
"bytes"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
// import "github.com/davecgh/go-spew/spew"
|
// import "github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
|
@ -81,7 +84,7 @@ func Chomp(a interface{}) string {
|
||||||
default:
|
default:
|
||||||
tmp := fmt.Sprint("shell.Chomp() NO HANDLER FOR TYPE: %T", a)
|
tmp := fmt.Sprint("shell.Chomp() NO HANDLER FOR TYPE: %T", a)
|
||||||
handleError(fmt.Errorf(tmp), -1)
|
handleError(fmt.Errorf(tmp), -1)
|
||||||
log.Printf("shell.Chomp() NEED TO MAKE CONVERTER FOR type =", reflect.TypeOf(t))
|
log.Warn("shell.Chomp() NEED TO MAKE CONVERTER FOR type =", reflect.TypeOf(t))
|
||||||
}
|
}
|
||||||
tmp := "shell.Chomp() THIS SHOULD NEVER HAPPEN"
|
tmp := "shell.Chomp() THIS SHOULD NEVER HAPPEN"
|
||||||
handleError(fmt.Errorf(tmp), -1)
|
handleError(fmt.Errorf(tmp), -1)
|
||||||
|
|
30
wget.go
30
wget.go
|
@ -10,18 +10,16 @@ package shell
|
||||||
global variables
|
global variables
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import "io"
|
import (
|
||||||
import "os"
|
"io"
|
||||||
import "fmt"
|
"os"
|
||||||
import "log"
|
"fmt"
|
||||||
import "bytes"
|
"bytes"
|
||||||
import "strings"
|
"strings"
|
||||||
import "net/http"
|
"net/http"
|
||||||
|
|
||||||
/*
|
"go.wit.com/log"
|
||||||
import "go.wit.com/shell"
|
)
|
||||||
import "github.com/davecgh/go-spew/spew"
|
|
||||||
*/
|
|
||||||
|
|
||||||
func Wget(url string) (*bytes.Buffer) {
|
func Wget(url string) (*bytes.Buffer) {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
@ -34,7 +32,7 @@ func Wget(url string) (*bytes.Buffer) {
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
log.Printf("res.StatusCode: %d\n", resp.StatusCode)
|
log.Log(INFO, "res.StatusCode: %d\n", resp.StatusCode)
|
||||||
if (resp.StatusCode != 200) {
|
if (resp.StatusCode != 200) {
|
||||||
handleError(fmt.Errorf(fmt.Sprint("%d", resp.StatusCode)), -1)
|
handleError(fmt.Errorf(fmt.Sprint("%d", resp.StatusCode)), -1)
|
||||||
return nil
|
return nil
|
||||||
|
@ -45,8 +43,8 @@ func Wget(url string) (*bytes.Buffer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func WgetToFile(filepath string, url string) error {
|
func WgetToFile(filepath string, url string) error {
|
||||||
log.Println("WgetToFile() filepath =", filepath)
|
log.Log(INFO, "WgetToFile() filepath =", filepath)
|
||||||
log.Println("WgetToFile() URL =", url)
|
log.Log(INFO, "WgetToFile() URL =", url)
|
||||||
// Get the data
|
// Get the data
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -81,7 +79,7 @@ func Write(filepath string, data string) bool {
|
||||||
data = Chomp(data) + "\n"
|
data = Chomp(data) + "\n"
|
||||||
// Create the file
|
// Create the file
|
||||||
ospath := Path(filepath)
|
ospath := Path(filepath)
|
||||||
log.Println("shell.Write() START ospath =", ospath, "filepath =", filepath)
|
log.Log(INFO, "shell.Write() START ospath =", ospath, "filepath =", filepath)
|
||||||
out, err := os.Create(ospath)
|
out, err := os.Create(ospath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
|
@ -96,6 +94,6 @@ func Write(filepath string, data string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
handleError(nil, int(count))
|
handleError(nil, int(count))
|
||||||
log.Println("shell.Write() END", ospath)
|
log.Log(INFO, "shell.Write() END", ospath)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,15 +4,17 @@
|
||||||
|
|
||||||
package shell
|
package shell
|
||||||
|
|
||||||
import "log"
|
import (
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
// import "go.wit.com/shell"
|
// import "go.wit.com/shell"
|
||||||
// import "github.com/davecgh/go-spew/spew"
|
// import "github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
func handleSignal(err interface{}, ret int) {
|
func handleSignal(err interface{}, ret int) {
|
||||||
log.Println("handleSignal() windows doesn't do signals")
|
log.Warn("handleSignal() windows doesn't do signals")
|
||||||
}
|
}
|
||||||
|
|
||||||
func UseJournalctl() {
|
func UseJournalctl() {
|
||||||
log.Println("journalctl doesn't exist on windows")
|
log.Warn("journalctl doesn't exist on windows")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package shell
|
package shell
|
||||||
|
|
||||||
import "log"
|
import (
|
||||||
import "runtime"
|
"runtime"
|
||||||
import "strings"
|
"strings"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
func Execname(filename string) string {
|
func Execname(filename string) string {
|
||||||
if runtime.GOOS != "windows" {
|
if runtime.GOOS != "windows" {
|
||||||
|
@ -12,12 +15,12 @@ func Execname(filename string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Path(filename string) string {
|
func Path(filename string) string {
|
||||||
log.Println("shell.Path() START filename =", filename)
|
log.Log(INFO, "Path() START filename =", filename)
|
||||||
if runtime.GOOS != "windows" {
|
if runtime.GOOS != "windows" {
|
||||||
log.Println("shell.Path() END filename =", filename)
|
log.Log(INFO, "Path() END filename =", filename)
|
||||||
return filename
|
return filename
|
||||||
}
|
}
|
||||||
filename = strings.Replace(filename, "/", "\\", -1)
|
filename = strings.Replace(filename, "/", "\\", -1)
|
||||||
log.Println("shell.Path() END filename =", filename)
|
log.Log(INFO, "Path() END filename =", filename)
|
||||||
return filename
|
return filename
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue