本文整理匯總了Golang中github.com/fatih/color.Green函數的典型用法代碼示例。如果您正苦於以下問題:Golang Green函數的具體用法?Golang Green怎麽用?Golang Green使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Green函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: writeLevelDB
func writeLevelDB(channel string, userName string, userMessage string, levelId string) {
chanId := channels[channel]
//Check for duplicate LevelId for this channel
var duplicateLevel string
checkDuplicate := db.QueryRow("SELECT Level FROM Levels WHERE Level=? AND StreamID=?;", levelId, chanId).Scan(&duplicateLevel)
switch {
case checkDuplicate == sql.ErrNoRows:
color.Green("No such level, Adding...\n")
insertLevel, dberr := db.Prepare("INSERT Levels SET StreamID=?,Nick=?,Level=?,Message=?,Added=?;")
if dberr != nil {
log.Fatalf("Cannot prepare insertLevel on %s: %s\n", channel, dberr.Error())
}
defer insertLevel.Close()
timeNow := time.Now().Format(time.RFC3339)
execLevel, dberr := insertLevel.Exec(chanId, userName, levelId, userMessage, timeNow)
if dberr != nil {
log.Fatalf("Cannot exec insertLevel on %s: %s\n", channel, dberr.Error())
}
rowsAff, dberr := execLevel.RowsAffected()
if dberr != nil {
log.Fatalf("No rows changed on %s: %s\n", channel, dberr.Error())
}
lastId, dberr := execLevel.LastInsertId()
if dberr != nil {
log.Fatalf("No last id on %s: %s\n", channel, dberr.Error())
}
color.Green("Added level %s by %s for %d %s. Row|#: %d|%d\n", levelId, userName, chanId, channel, rowsAff, lastId)
case checkDuplicate != nil:
log.Fatalf("Checking duplicate level failed, error: %s\n", checkDuplicate.Error())
default:
color.Yellow("Duplicate level, not adding...\n")
}
}
示例2: testRCCSend
func testRCCSend() {
if err := rpio.Open(); err != nil {
fmt.Println(err)
os.Exit(1)
}
defer rpio.Close()
rccPin.Output()
testCode := [13]int{1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0}
// Toggle pin 20 times
for x := 0; x < len(testCode); x++ {
state := testCode[x]
if state == 1 {
color.Green("High: ", state)
rccPin.High()
} else {
color.Green("Low: ", state)
rccPin.Low()
}
time.Sleep(300)
}
}
示例3: startNotice
func startNotice() {
color.Green("******")
color.Green("~ Notice: ~\n")
color.White("When your download is complete,\nyou will find your files under:\n")
color.Magenta(setDownloadFolder())
color.Green("******" + "\n\n")
}
示例4: main
func main() {
Repo := [6]string{"https://github.com/EgeBalci/ARCANUS/blob/master/SOURCE/ARCANUS.go", "https://github.com/EgeBalci/ARCANUS/raw/master/ARCANUS_x64", "https://github.com/EgeBalci/ARCANUS/raw/master/ARCANUS_x64.exe", "https://github.com/EgeBalci/ARCANUS/raw/master/ARCANUS_x86", "https://github.com/EgeBalci/ARCANUS/raw/master/ARCANUS_x86.exe", "https://github.com/EgeBalci/ARCANUS/raw/master/README.md"}
if runtime.GOOS == "windows" {
exec.Command("cmd", "/C", "msg ARCANUS Update Started...").Run()
exec.Command("cmd", "/C", "del ARCANUS.go").Run()
exec.Command("cmd", "/C", "del ARCANUS_x64.exe").Run()
exec.Command("cmd", "/C", "del ARCANUS_x86.exe").Run()
exec.Command("cmd", "/C", "del ARCANUS_x64").Run()
exec.Command("cmd", "/C", "del ARCANUS_x86").Run()
color.Blue("[*] Updating ARCANUS...\n\n")
for i := 0; i < len(Repo); i++ {
response, _ := http.Get(Repo[i])
defer response.Body.Close()
body, _ := ioutil.ReadAll(response.Body)
Name := strings.Split(Repo[i], "/")
color.Green("# " + string(Name[(len(Name)-1)]) + " [OK]")
file, _ := os.Create(string(Name[(len(Name) - 1)]))
file.WriteString(string(body))
}
/*ARC, _ := exec.Command("cmd", "/C", "echo %PROCESSOR_ARCHITECTURE%").Output()
if strings.Contains(string(ARC), "x86") || strings.Contains(string(ARC), "X86") {
exec.Command("cmd", "/C", "ARCANUS_x86.exe").Start()
}else if strings.Contains(string(ARC), "AMD64") {
exec.Command("cmd", "/C", "ARCANUS_x64.exe").Start()
}*/
exec.Command("cmd", "/C", "msg * ARCANUS Updated Succesfuly !").Run()
} else if runtime.GOOS == "linux" {
exec.Command("sh", "-c", "zenity --info --text=\"ARCANUS Update Started... \"").Run()
exec.Command("sh", "-c", "rm ARCANUS.go").Run()
exec.Command("sh", "-c", "rm ARCANUS_x64.exe").Run()
exec.Command("sh", "-c", "rm ARCANUS_x86.exe").Run()
exec.Command("sh", "-c", "rm ARCANUS_x64").Run()
exec.Command("sh", "-c", "rm ARCANUS_x86").Run()
color.Blue("[*] Updating ARCANUS...\n\n")
for i := 0; i < len(Repo); i++ {
response, _ := http.Get(Repo[i])
defer response.Body.Close()
body, _ := ioutil.ReadAll(response.Body)
Name := strings.Split(Repo[i], "/")
color.Green("# " + string(Name[(len(Name)-1)]) + " [OK]")
file, _ := os.Create(string(Name[(len(Name) - 1)]))
file.WriteString(string(body))
}
exec.Command("sh", "-c", "zenity --info --text=\"ARCANUS Updated Succesfuly !\"").Run()
/*ARC, _ := exec.Command("sh", "-c", "uname -a").Output()
if strings.Contains(string(ARC), "x86") || strings.Contains(string(ARC), "X86") {
exec.Command("sh", "-c", "./ARCANUS_x86").Start()
}else if strings.Contains(string(ARC), "amd64") {
exec.Command("sh", "-c", "./ARCANUS_x64").Start()
}*/
}
}
示例5: endNotice
func endNotice() {
fmt.Print("\n\n")
color.Green("******")
color.Green("Download complete!\n")
color.White("Your files have been saved to " + setDownloadFolder() + "\n\n")
color.White("For your convenience, your files have been sorted by extension.")
color.Green("******")
}
示例6: handleInteractiveMode
func handleInteractiveMode() {
reader := bufio.NewReader(os.Stdin)
for {
red := color.New(color.FgCyan)
red.Printf("%s %s %s => ", time.Now().Format("15:04:05"), *serverFlag, *executorFlag)
line, err := reader.ReadString('\n')
if err != nil {
log.Fatal(color.RedString("ERROR reading string: %s", err.Error()))
}
line = strings.Trim(line, "\r\n")
if strings.EqualFold(line, "exit") {
color.Green("Exit command received. Good bye.")
os.Exit(0)
}
exeAndArgs, err := parsecommand.Parse(line)
if err != nil {
color.Red("Cannot parse line '%s', error: %s", line, err.Error())
continue
}
var exe string
var args []string = []string{}
exe = exeAndArgs[0]
if len(exeAndArgs) > 1 {
args = exeAndArgs[1:]
}
onFeedback := func(fb string) {
fmt.Println(fb)
}
color.Green("Exe '%s' and args '%#v'", exe, args)
color.Yellow("-------------------------------------")
println()
err = execute(false, onFeedback, *serverFlag, *executorFlag, *clientPemFlag, exe, args...)
if err != nil {
color.Red("Execute failed with error: %s", err.Error())
continue
}
println()
color.Yellow("-------------------------------------")
println()
println()
}
}
示例7: runAllProcessorTests
func runAllProcessorTests(t *testing.T, cases map[string]processorTestCase) {
color.NoColor = false
json := `{
"var1": "var1",
"var-var": "var-var",
"var": {"var": "1"},
"version": "{{ feature }}-{{ feature-suffix }}",
"feature": "value-unknown",
"feature-suffix": "{{ feature }}",
"list": [1, 2, 3]
}`
tree, err := gabs.ParseJSON([]byte(json))
if err != nil {
color.Red("%v: failed!\n", err)
t.Fail()
}
for name, test := range cases {
if res, err := Template(test.in, tree); err == nil {
if test.expect == res {
color.Green("%v: Ok\n", name)
} else {
color.Red("%v: %v != %v: failed!\n", name, test.expect, res)
t.Fail()
}
} else {
color.Red("error %v\n: failed!", err)
t.Fail()
}
}
}
示例8: exec
func exec(cmd *cobra.Command, args []string) {
if len(args) == 1 {
color.Green("Creando nueva aplicacion " + args[0])
gopath := os.Getenv("GOPATHs")
if gopath == "" {
color.Set(color.FgRed)
defer color.Unset()
log.Fatalln("GOPATH no found :(")
os.Exit(2)
}
src := fmt.Sprintf("%s\\src", gopath)
appName := args[0]
appDir := fmt.Sprintf("%s\\%s", src, appName)
createAppFolder(appDir, []string{})
fmt.Printf("appDir: %s\n", appDir)
createAppFolder(fmt.Sprintf("%s\\%s", appDir, "public"), []string{"assets"})
createAppFolder(fmt.Sprintf("%s\\%s", appDir, "app"), []string{"controllers", "models"})
createSubFolder(fmt.Sprintf("%s\\%s\\%s", appDir, "public", "assets"), []string{"js", "scss", "img", "fonts"})
// creamos la estructura basica
}
}
示例9: TestPlugin
func TestPlugin(t *testing.T) {
color.NoColor = false
casses := map[string]testrunnerTestCase{
"simple": {
first: map[string]interface{}{"name": "value"},
second: map[string]interface{}{"name": "value"},
expect: make(map[string]interface{}),
},
"diff": {
first: map[string]interface{}{"name1": "value"},
second: map[string]interface{}{"name": "value"},
expect: map[string]interface{}{"name": "<nil> != value", "name1": "value != <nil>"},
},
}
for name, test := range casses {
if d := diff(test.first, test.second); !reflect.DeepEqual(d, test.expect) {
color.Red("\n\nTest `%s` failed!", name)
color.Yellow("\n\nexpected: %v\n\ngiven: %v\n\n", test.expect, d)
t.Fail()
} else {
color.Green("\n%s: OK\n", name)
}
}
}
示例10: initDatabase
// Init basic strctures in the database
func initDatabase(dbPath string) (*bolt.DB, error) {
db, err := bolt.Open(dbPath, 0600, nil)
if err != nil {
return nil, err
}
color.Green("[DB: OK]")
// Init buckets if not present
for i := 0; i < 2; i++ {
err = db.Update(func(tx *bolt.Tx) error {
switch i {
// Init a bucket for the devices
case 0:
_, err := tx.CreateBucketIfNotExists([]byte("devices"))
if err != nil {
return fmt.Errorf("create bucket: %s", err)
}
return nil
// Init a bucket for the rooms
default:
_, err := tx.CreateBucketIfNotExists([]byte("rooms"))
if err != nil {
return fmt.Errorf("create bucket: %s", err)
}
return nil
}
})
}
if err != nil {
log.Fatal("Could not create bucket in DB", err)
}
return db, nil
}
示例11: TestAnchorMerger
func TestAnchorMerger(t *testing.T) {
color.NoColor = false
in := []byte(`---
vars: &v
env: qa
deploy:
env: live`)
expect := `{"deploy":{"env":"live"},"vars":{"env":"qa"}}`
if err := ioutil.WriteFile("/tmp/test", in, 0644); err != nil {
color.Red("Error file not create")
t.Error("Error file not create")
t.Fail()
}
defer os.Remove("/tmp/test")
if g, err := LoadFile("/tmp/test"); err != nil {
color.Red("%v\n", err)
t.Error(err)
t.Fail()
} else {
if g.String() == expect {
color.Green("\n%s: OK\n", "FileLoad")
} else {
color.Red("%s != %s", g.String(), expect)
t.Error(fmt.Errorf("%s != %s", g.String(), expect))
t.Fail()
}
}
}
示例12: Debugf
// Debugf is a convenience method appending a debug message to the logger
func Debugf(msg string, a ...interface{}) {
_, fn, line, _ := runtime.Caller(1)
msg = fmt.Sprintf(msg, a...)
msg = fmt.Sprintf("%+v%s:%d\n\n", msg, fn, line)
formattedMessage := formattedLogMessage("DEBUG", msg)
color.Green(formattedMessage)
}
示例13: Output
func (r Documentation) Output(results <-chan []resource.TestResult) (hasFail bool) {
testCount := 0
var failed []resource.TestResult
for resultGroup := range results {
for _, testResult := range resultGroup {
if testResult.Successful {
fmt.Println(humanizeResult(testResult))
testCount++
} else {
fmt.Println(humanizeResult(testResult))
failed = append(failed, testResult)
testCount++
}
}
fmt.Println("")
}
fmt.Print("\n")
if len(failed) > 0 {
color.Red("Failures:")
for _, testResult := range failed {
fmt.Println(humanizeResult(testResult))
}
fmt.Print("\n")
}
if len(failed) > 0 {
color.Red("Count: %d failed: %d\n", testCount, len(failed))
return true
}
color.Green("Count: %d failed: %d\n", testCount, len(failed))
return false
}
示例14: hitUrl
//Hit the chosen URL using a GET request and signal its completion using the waitGroup
//Prints out the URL and the Status code to the command line
func hitUrl(url string, failedUrl chan string) {
req, err := http.NewRequest("GET", url, nil)
//Add me some akamai debug headers
req.Header.Add("Pragma", "akamai-x-cache-on, akamai-x-check-cacheable")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
failedUrl <- err.Error()
return
}
//trim out everthing that isn't the cache hit type
fromIndex := strings.Index(resp.Header.Get("X-Cache"), " from")
cacheHit := "No Cache header"
if fromIndex > 0 {
cacheHit = resp.Header.Get("X-Cache")[:fromIndex]
}
responseString := fmt.Sprintf("Is cacheable? %s \t Cache hit: %s \t Url : %s Status: %s \n", resp.Header.Get("X-Check-Cacheable"), cacheHit, url, resp.Status)
if resp.StatusCode == http.StatusOK {
color.Green(responseString)
} else {
failedUrl <- responseString
}
}
示例15: Debug
// Debug is a convenience method appending a debug message to the logger
func Debug(obj interface{}) {
// Get the line number and calling func sig
_, fn, line, _ := runtime.Caller(1)
msg := fmt.Sprintf("%+v\n%s:%d\n\n", obj, fn, line)
formattedMessage := formattedLogMessage("DEBUG", msg)
color.Green(formattedMessage)
}