本文整理汇总了Golang中github.com/wsxiaoys/terminal/color.Printf函数的典型用法代码示例。如果您正苦于以下问题:Golang Printf函数的具体用法?Golang Printf怎么用?Golang Printf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Printf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: purge
func (c *client) purge(host string, f gfind.File, k int, id int) {
var Url *url.URL
Url, err := url.Parse(host)
chkErr(err)
Url.Path += "/purge"
Url.Path += f.Relpath
var u string
u = Url.String()
if security != "" {
u += "?" + ParseNgxSecurityLink(security, host, f)
}
req, err := http.NewRequest("HEAD", u, nil)
req.Close = true
if vhost != "client.com" {
req.Host = vhost
}
resp, err := c.c.Do(req)
chkErr(err)
if resp.StatusCode == 200 {
color.Printf("%6v-%-2d @{g}%[email protected]{|} %v %v\n", k, id, "PURGE:SUCCESS", Url.String(), f.Size())
} else if resp.StatusCode == 404 {
color.Printf("%6v-%-2d @{y}%[email protected]{|} %v %v\n", k, id, "PURGE:NOFILE", Url.String(), f.Size())
}
}
示例2: output
func output(hostname, servicename, v interface{}) {
// define quick color/graphic view of output
var s, m, a string
if state(v) == 0 {
s = color.Sprintf("@{g}%-10s", "[OK]")
} else if state(v) == 1 {
s = color.Sprintf("@{y}%-10s", "[WARNING]")
} else if state(v) == 2 {
s = color.Sprintf("@{r}%-10s", "[CRITICAL]")
}
if notifications(v) {
m = color.Sprintf("@{g} %v ", ` `)
} else {
m = color.Sprintf("@{r} %v ", `Ø`)
}
if acknowledged(v) {
a = color.Sprintf("@{g} %v ", `√`)
} else {
a = color.Sprintf("@{g} %v ", ` `)
}
// this just incase if change mind use different syntax
switch v := v.(type) {
default:
case *nagiosToJson.Hoststatus:
// color.Printf("%-10s: %v %v %v %v %v\n", hostname, m, s, a, v.Plugin_output, time.Since(str2time(v.Last_check)))
color.Printf("%-10s: %-10v %v %v %v %v %v\n", hostname, servicename, m, s, a, v.Plugin_output, time.Since(str2time(v.Last_check)))
case *nagiosToJson.Servicestatus:
color.Printf("%-10s: %-10v %v %v %v %v %v\n", hostname, servicename, m, s, a, v.Plugin_output, time.Since(str2time(v.Last_check)))
}
}
示例3: readWholeNumber
func readWholeNumber(prompt string, bits int, unsigned bool, allowBlank bool, defaultValue int64) (out int64, err error) {
var iu uint64
var i int64
loop:
for {
fmt.Print(prompt)
line, err := readLine()
if strings.TrimSpace(line) == "" && allowBlank {
if unsigned {
iu = uint64(defaultValue)
} else {
i = defaultValue
}
break loop
}
if unsigned {
iu, err = strconv.ParseUint(string(line), 10, bits)
} else {
i, err = strconv.ParseInt(string(line), 10, bits)
}
if err != nil {
numError := err.(*strconv.NumError)
switch numError.Err {
case strconv.ErrSyntax:
if unsigned {
color.Printf("@{r}%s is not a non-negative integer\n", numError.Num)
} else {
color.Printf("@{r}%s is not a integer\n", numError.Num)
}
continue loop
case strconv.ErrRange:
color.Printf("@{r}%s does not fit in %d bits\n", numError.Num, bits)
continue loop
default:
color.Printf("@{r}Unknown error %s\n", numError)
continue loop
}
}
break loop
}
if unsigned {
out = int64(iu)
} else {
out = i
}
return
}
示例4: dumpResponse
// dump request , body true/false, print true/false
func dumpResponse(r *http.Response, b, p bool, host string) []byte {
dump, err := httputil.DumpResponse(r, b)
if err != nil {
log.Println(err.Error())
}
// isGzip := false
// if v, ok := r.Header["Accept-Encoding"]; ok {
// if strings.Contains(v[0], "gzip") {
// isGzip = true
// log.Println("is gzip")
// }
// }
if p {
index := bytes.Index(dump, []byte("\r\n\r\n"))
headers := dump[:index]
body := bytes.TrimLeft(dump[index:], "\r\n\r\n")
// body = bytes.TrimLeft(body, string([]byte{13, 10, 13, 10}))
// if isGzip {
// reader := bytes.NewReader(body)
// g, err := gzip.NewReader(reader)
// if err != nil {
// log.Println(err.Error())
// }
// body, err = ioutil.ReadAll(g)
// if err != nil {
// log.Println(err.Error())
// }
// }
if *veryverbose {
now := time.Now()
dirname := "/tmp/stfdump/" + host
if _, err := os.Stat(dirname); err != nil {
if err := os.MkdirAll(dirname, 0755); err != nil {
log.Fatalln(err.Error())
}
}
filename := fmt.Sprintf("%s/%d<", dirname, now.UnixNano())
ioutil.WriteFile(filename, body, 0644)
}
if *colors {
// color.Printf("@{b}%[email protected]{|}", string(dump))
color.Printf("@{c}%[email protected]{|}\n", string(headers))
if *showBody {
color.Printf("@{g}%[email protected]{|}\n", string(body))
}
// color.Printf("@{g}%[email protected]{|}\n", ehex.EncodeToString(body))
// color.Printf("@{g}%[email protected]{|}\n", body)
} else {
// fmt.Print(string(dump))
fmt.Println(string(headers))
fmt.Println(string(body))
}
}
return dump
}
示例5: reportFailWithDiff
func (self *Case) reportFailWithDiff(lhs, rhs interface{}) {
if lhs != nil && rhs != nil {
if s1, ok := lhs.(string); ok {
s2 := rhs.(string)
self.printDiff(s1, s2)
return
}
}
color.Printf("@[email protected]| expected @g%s = %[email protected]|\n", mustTypeName(lhs), lhs)
color.Printf("@[email protected]| actual @r%s = %[email protected]|\n", mustTypeName(rhs), rhs)
}
示例6: query
func query(name, qtype string) {
start := time.Now()
qname, err := idna.ToASCII(name)
if err != nil {
color.Fprintf(os.Stderr, "Invalid IDN domain name: %s\n", name)
os.Exit(1)
}
rrs, err := resolver.ResolveErr(qname, qtype)
color.Printf("\n")
if len(rrs) > 0 {
color.Printf("@{g};; RESULTS:\n")
}
for _, rr := range rrs {
color.Printf("@{g}%s\n", rr.String())
}
if err != nil {
color.Printf("@{r};; %s\t%s\t%s\n", err, name, qtype)
} else if rrs == nil {
color.Printf("@{y};; NIL\t%s\t%s\n", name, qtype)
} else if len(rrs) > 0 {
color.Printf("@{g};; TRUE\t%s\t%s\n", name, qtype)
} else {
color.Printf("@{r};; FALSE\t%s\t%s\n", name, qtype)
}
color.Printf("@{.w};; Elapsed: %s\n", time.Since(start).String())
}
示例7: reportFail
func (self *Case) reportFail(depth int, lhs, rhs interface{}, msg string, op int) {
self.location(depth + 1)
color.Printf("@[email protected]| FAIL %s\n", msg)
switch op {
case eq:
fallthrough
case throw:
self.reportFailWithDiff(lhs, rhs)
case ne:
color.Printf("@[email protected]| expected @g%s = %[email protected]|\n", mustTypeName(lhs), lhs)
color.Printf("@[email protected]| but is @[email protected]|\n")
}
self.numFail++
}
示例8: observeChannel
func observeChannel(resultRepository <-chan *github.Repository, networkErr <-chan error) (*github.Repository, error) {
var repository *github.Repository
var err error
getLoop:
for {
select {
case repository = <-resultRepository:
break getLoop
case getErr := <-networkErr:
fmt.Printf("\n\n")
color.Printf("@{r} !!! Error Occuered !!! ")
fmt.Printf("\n\n")
fmt.Println(getErr)
fmt.Printf("\n\n")
break getLoop
case <-time.After(time.Minute):
fmt.Println(" @{r} !!! Timeout !!! ")
break getLoop
default:
time.Sleep(time.Second / 2)
fmt.Printf(".")
}
}
return repository, err
}
示例9: main
func main() {
flag.Usage = func() {
color.Fprintf(os.Stderr, "Usage: %s [arguments] <name> [type]\n\nAvailable arguments:\n", os.Args[0])
flag.PrintDefaults()
os.Exit(1)
}
flag.Parse()
qtype := ""
args := flag.Args()
if len(args) == 0 {
flag.Usage()
} else if _, isType := dns.StringToType[args[len(args)-1]]; len(args) > 1 && isType {
qtype, args = args[len(args)-1], args[:len(args)-1]
}
if verbose {
dnsr.DebugLogger = os.Stderr
}
var wg sync.WaitGroup
start := time.Now()
for _, name := range args {
wg.Add(1)
go func(name string, qtype string) {
query(name, qtype)
wg.Done()
}(name, qtype)
}
wg.Wait()
if len(args) > 1 {
color.Printf("\[email protected]{.w};; Total elapsed: %s\n", time.Since(start).String())
}
}
示例10: Update
// Update project details
// http://docs.gemnasium.apiary.io/#patch-%2Fprojects%2F%7Bslug%7D
func (p *Project) Update(name, desc *string, monitored *bool) error {
if name == nil && desc == nil && monitored == nil {
return errors.New("Please specify at least one thing to update (name, desc, or monitored")
}
update := make(map[string]interface{})
if name != nil {
update["name"] = *name
}
if desc != nil {
update["desc"] = *desc
}
if monitored != nil {
update["monitored"] = *monitored
}
opts := &gemnasium.APIRequestOptions{
Method: "PATCH",
URI: fmt.Sprintf("/projects/%s", p.Slug),
Body: update,
}
err := gemnasium.APIRequest(opts)
if err != nil {
return err
}
color.Printf("@gProject %s updated succesfully\n", p.Slug)
return nil
}
示例11: Fail
func (self *Case) Fail() {
self.location(2)
color.Printf("@[email protected]| FAIL %s\n", self.what)
self.what = ""
self.numFail++
panic(self)
}
示例12: Printf
func (p *Printer) Printf(fmtstr string, args ...interface{}) {
if p.NoColors {
fmtstr = removeMeta.ReplaceAllLiteralString(fmtstr, "")
fmt.Printf(fmtstr, args...)
} else {
color.Printf(fmtstr, args...)
}
}
示例13: SearchFile
func (v *GRVisitor) SearchFile(fn string, content []byte) {
lines := IntList([]int{})
binary := false
if bytes.IndexByte(content, 0) != -1 {
binary = true
}
for _, info := range v.FindAllIndex(content) {
if lines.Contains(info.num) {
continue
}
if v.prependNewLine {
fmt.Println("")
v.prependNewLine = false
}
first := len(lines) == 0
lines = append(lines, info.num)
if first {
if binary && !*onlyName {
fmt.Printf("Binary file %s matches\n", fn)
break
} else {
color.Printf("@g%s\n", fn)
}
}
if *onlyName {
return
}
color.Printf("@[email protected]%d:", info.num)
coloredLine := v.pattern.ReplaceAllStringFunc(string(info.line),
func(wrap string) string {
return color.Sprintf("@Y%s", wrap)
})
fmt.Printf("%s\n", coloredLine)
}
if len(lines) > 0 {
v.prependNewLine = true
}
}
示例14: doCreate
func doCreate(c *cli.Context) {
name := c.Args().First()
if len(name) == 0 {
return
}
// check configuration
configuration, err := OpenConfiguration()
if err != nil {
fmt.Println(err)
return
}
if configuration.GithubToken == "" {
configuration.GithubToken = PromptPersonalGithubToken()
configuration.Persist()
}
// set repository attributes
newRepository := github.Repository{Name: &name}
prompt := c.Bool(flagDetail)
if description := GetRepositryField(flagDesc, c.String(flagDesc), prompt).(string); description != "" {
newRepository.Description = &description
}
if homepage := GetRepositryField(flagHP, c.String(flagHP), prompt).(string); homepage != "" {
newRepository.Homepage = &homepage
}
if teamid := GetRepositryField(flagTeamID, c.Int(flagTeamID), prompt).(int); teamid != 0 {
newRepository.TeamID = &teamid
}
private := GetRepositryField(flagPrivate, c.Bool(flagPrivate), prompt).(bool)
newRepository.Private = &private
issue := GetRepositryField(flagIssue, c.Bool(flagIssue), prompt).(bool)
newRepository.HasIssues = &issue
wiki := GetRepositryField(flagWiki, c.Bool(flagWiki), prompt).(bool)
newRepository.HasWiki = &wiki
download := GetRepositryField(flagDownload, c.Bool(flagDownload), prompt).(bool)
newRepository.HasDownloads = &download
// create repository
org := c.String(flagOrg)
client := NewClient(configuration)
repository, _ := observeChannel(client.CreateRepository(org, &newRepository))
if repository == nil {
return
}
output := "\n\n" +
"=========================\n" +
" \n" +
"@{g}* We are sccessful in Creating a repository! Push an existing repository from the command [email protected]{|}\n" +
" \n" +
"git remote add origin %s \n" +
"git push -u origin master\n" +
" \n" +
"=========================\n" +
"\n\n"
color.Printf(output, *repository.GitURL)
}
示例15: Printf
func (p *Printer) Printf(colorfmt, plainfmt string,
args ...interface{}) {
if p.NoColors {
fmt.Printf(plainfmt, args...)
} else {
color.Printf(colorfmt, args...)
}
}