本文整理匯總了Golang中github.com/fatih/color.Yellow函數的典型用法代碼示例。如果您正苦於以下問題:Golang Yellow函數的具體用法?Golang Yellow怎麽用?Golang Yellow使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Yellow函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: parseGauges
func parseGauges(info string) map[string]int64 {
gauges_with_values := map[string]int64{
"blocked_clients": 0,
"connected_clients": 0,
"instantaneous_ops_per_sec": 0,
"latest_fork_usec": 0,
"mem_fragmentation_ratio": 0,
"migrate_cached_sockets": 0,
"pubsub_channels": 0,
"pubsub_patterns": 0,
"uptime_in_seconds": 0,
"used_memory": 0,
"used_memory_lua": 0,
"used_memory_peak": 0,
"used_memory_rss": 0,
}
color.White("-------------------")
color.White("GAUGES:")
for gauge, _ := range gauges_with_values {
r, _ := regexp.Compile(fmt.Sprint(gauge, ":([0-9]*)"))
matches := r.FindStringSubmatch(info)
if matches == nil {
color.Yellow(fmt.Sprint("WARN: ", gauge, "is not displayed in redis info"))
} else {
value := matches[len(matches)-1]
color.Cyan(fmt.Sprint(gauge, ": ", value))
v, _ := strconv.ParseInt(value, 10, 64)
gauges_with_values[gauge] = v
}
}
return gauges_with_values
}
示例2: getClientCredentials
func getClientCredentials(c *cli.Context) []string {
credentials := []string{c.GlobalString("client-id"), c.GlobalString("client-secret")}
if credentials[0] == "" || credentials[1] == "" {
color.Yellow("No client credentials given. Fallback to builtin default...")
color.Yellow("Keep in mind that your document might be visible to other users.")
color.Yellow("Your unique user-id is the only secret to protect your data.\n\n")
superSecretSecret := []byte("V;4nJvuANmoywKNYk.yewNhqwmAQctc3BvByxeozQVpiK")
// Decode HEX default credentials
credentialsBytes, err := hex.DecodeString(defaultClientCredentials)
if err != nil {
color.Red("Error: client-id and client-secret missing and fallback decoding (step 1) failed: %s\n\n", err)
cli.ShowCommandHelp(c, c.Command.FullName())
os.Exit(1)
}
decodedCredentials := strings.Split(string(xorBytes(credentialsBytes, superSecretSecret)), ":")
if len(decodedCredentials) < 2 {
color.Red("Error: client-id and client-secret missing and fallback decoding (step 2) failed: %s\n\n", err)
cli.ShowCommandHelp(c, c.Command.FullName())
os.Exit(1)
}
credentials = decodedCredentials
}
return credentials
}
示例3: copyfile
func copyfile() {
color.Yellow("開始執行文件發送:")
info, err := os.Lstat(all_ssh.ArgsInfo.File)
if err != nil || info.IsDir() {
color.Blue("檢查要發送的文件.")
return
}
for _, v := range all_ssh.ServerList {
go func() {
client := all_ssh.Connection(v)
if client != nil {
all_ssh.CopyFile(client, all_ssh.ArgsInfo.File, all_ssh.ArgsInfo.Dir)
}
}()
}
var num int
var Over chan os.Signal = make(chan os.Signal, 1)
go signal.Notify(Over, os.Interrupt, os.Kill)
go result(&num, Over)
<-Over
color.Yellow("一共有%d條錯誤.\n", len(all_ssh.ErrorList))
for _, v := range all_ssh.ErrorList {
color.Red(v)
}
color.Red("收到結果:%d條\n", num)
}
示例4: DisplayInfo
func DisplayInfo() {
color.Yellow("\n\n******* GO WORKER INFORMATION *******\n\n")
infoObj := GetInfoObj()
color.Green("%+v", infoObj)
color.Yellow("\n\n*************************************\n\n")
}
示例5: 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()
}
}
示例6: main
func main() {
if all_ssh.ArgsInfo.IP != "" {
color.Yellow("開始登錄:%s\n", all_ssh.ArgsInfo.IP)
var v all_ssh.ConnetctionInfo
for _, v = range all_ssh.ServerList {
if v.IP == all_ssh.ArgsInfo.IP {
break
}
}
v.IP = all_ssh.ArgsInfo.IP
client := all_ssh.Connection(v)
if client == nil {
return
}
err := all_ssh.TtyClient(client)
if err != nil {
println(err.Error())
}
if len(all_ssh.ErrorList) >= 1 {
color.Red(all_ssh.ErrorList[0])
}
return
}
if all_ssh.ArgsInfo.File != "" {
copyfile()
return
}
if all_ssh.ArgsInfo.Cmd != "" {
runcmd()
return
}
color.Blue("使用%s -h查看幫助.\n", os.Args[0])
}
示例7: Run
func (n *Notifier) Run(message string) {
switch n.Name {
case "slack":
if slack_api == nil {
color.Red("[!] Slack used as a notifier, but not configured with ENV vars.")
return
}
err = slack_api.ChatPostMessage(slack_channel.Id, message, &slack.ChatPostMessageOpt{IconEmoji: ":fire:"})
if err != nil {
color.Red(fmt.Sprintf("[!] Error posting to Slack: %s", err))
}
case "hipchat":
if hipchat_api == nil {
color.Red("[!] HipChat used as a notifier, but not configured with ENV vars.")
return
}
_, err = hipchat_api.Room.Notification(os.Getenv("HIPCHAT_ROOM_ID"), &hipchat.NotificationRequest{Message: "Testing", Color: "red"})
if err != nil {
color.Red(fmt.Sprintf("[!] Error posting to HipChat: %s", err))
}
case n.Name: // default
color.Yellow(fmt.Sprintf("[>] Unknown notifier: %s", n.Name))
}
}
示例8: 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)
}
}
}
示例9: Warn
// Warn is a convenience method appending a warning message to the logger
func Warn(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("WARN", msg)
color.Yellow(formattedMessage)
}
示例10: writeWarning
func writeWarning(format string, a ...interface{}) {
if silent {
return
}
color.Yellow(format, a...)
}
示例11: parseCounters
func parseCounters(info string) map[string]int64 {
counters := map[string]int64{
"evicted_keys": 0,
"expired_keys": 0,
"keyspace_hits": 0,
"keyspace_misses": 0,
"rejected_connections": 0,
"sync_full": 0,
"sync_partial_err": 0,
"sync_partial_ok": 0,
"total_commands_processed": 0,
"total_connections_received": 0,
}
color.White("-------------------")
color.White("COUNTERS:")
for counter, _ := range counters {
r, _ := regexp.Compile(fmt.Sprint(counter, ":([0-9]*)"))
matches := r.FindStringSubmatch(info)
if matches == nil {
color.Yellow(fmt.Sprint("ERROR: ", counter, "is not displayed in redis info"))
} else {
value := matches[len(matches)-1]
color.Cyan(fmt.Sprint(counter, ": ", value))
v, _ := strconv.ParseInt(value, 10, 64)
counters[counter] = v
}
}
return counters
}
示例12: Warnf
// Warnf is a convenience method appending a warning message to the logger
func Warnf(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("WARN", msg)
color.Yellow(formattedMessage)
}
示例13: isWatching
func isWatching(channel string, name string) (bool, error) {
chanName := strings.Replace(channel, "#", "", 1)
if k+60 <= time.Now().Unix() {
var err error
url := "http://tmi.twitch.tv/group/user/" + chanName + "/chatters"
response, err := http.Get(url)
if err != nil {
log.Printf("Cannot get URL response: %s\n", err.Error())
return false, err
}
defer response.Body.Close()
dec := json.NewDecoder(response.Body)
if err := dec.Decode(&v); err != nil {
log.Printf("Parse error: %s\n", err.Error())
return false, err
}
k = time.Now().Unix()
color.Yellow("Updating chatters")
}
//fmt.Printf("%q\n", v)
chats := v["chatters"].(map[string]interface{})
views := chats["viewers"].([]interface{})
mods := chats["moderators"].([]interface{})
for _, b := range views {
if b == strings.ToLower(name) {
return true, nil
}
}
for _, b := range mods {
if b == strings.ToLower(name) {
return true, nil
}
}
return false, nil
}
示例14: 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")
}
}
示例15: main
func main() {
color.Yellow("Job Worker Client")
jobworker.Run()
}