本文整理汇总了Golang中fmt.Print函数的典型用法代码示例。如果您正苦于以下问题:Golang Print函数的具体用法?Golang Print怎么用?Golang Print使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Print函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestLRUCache
func TestLRUCache(t *testing.T) {
strategy := NewLRUPeriodFlushStrategy(3, 100, 0)
storage := NewInMemoryKeyValueStorage(10)
flusher := &FakeFlusher{}
cache := NewKeyValueCache(storage, strategy, flusher)
fmt.Print("Start LRU cache test ...\t")
for i := 0; i < 10; i++ {
str := fmt.Sprint(i)
cache.Show(str, str)
}
keys, _ := cache.Keys()
if !same(convert2string([]int{7, 9, 8}), keys) {
t.Errorf("should be [7 8 9], but %v", keys)
}
if v, _ := cache.Get("1"); v != nil {
t.Errorf("%v should not be in cache", v)
}
cache.Get("7")
cache.Show("1", "1")
if v, _ := cache.Get("8"); v != nil {
keys, _ := cache.Keys()
t.Errorf("%v should not be in cache; cache content: %v", v, keys)
}
fmt.Print("OK\n")
}
示例2: ExampleTerm_GetAll_optArgs
// Find all document with an indexed value.
func ExampleTerm_GetAll_optArgs() {
// Fetch the row from the database
res, err := DB("examples").Table("heroes").GetAll("man_of_steel").OptArgs(GetAllOpts{
Index: "code_name",
}).Run(session)
if err != nil {
fmt.Print(err)
return
}
defer res.Close()
if res.IsNil() {
fmt.Print("Row not found")
return
}
var hero map[string]interface{}
err = res.One(&hero)
if err != nil {
fmt.Printf("Error scanning database result: %s", err)
return
}
fmt.Print(hero["name"])
// Output: Superman
}
示例3: dump
func (char *Char) dump(s string) {
fmt.Print(s, " ");
for i := 0; i < len(char.field); i++ {
fmt.Printf("%s:%q ", fieldName[i], char.field[i])
}
fmt.Print("\n");
}
示例4: fail
func fail(run string, stdout, stderr bytes.Buffer) {
msg(fmt.Sprintf("Run %v stdout:", run))
fmt.Print(stdout.String())
msg(fmt.Sprintf("Run %v stderr:", run))
fmt.Print(stderr.String())
}
示例5:
func (server *IpcServer)Connect() chan string {
session := make(chan string, 0)
go func(c chan string){
for{
request := <-c
if request == "CLOSE" {
break
}
var req Request
err := json.Unmarshal([]byte(request), &req)
if err != nil{
fmt.Println("Invalid request format:", request)
}
resp := server.Handle(req.Method, req.Params)
b, err := json.Marshal(resp)
c <- string(b)
}
fmt.Print("Session closed.")
}(session)
fmt.Print("A new session has been created.")
return session
}
示例6: printFields
func printFields(datamap map[string]interface{}, fields string) {
for k, v := range datamap {
key := ""
fieldsslice := strings.Split(fields, ",")
if fields != "_all" {
for _, rawfield := range fieldsslice {
field := strings.TrimSpace(rawfield)
if strings.EqualFold(field, strings.TrimSpace(k)) {
key = strings.TrimSpace(k)
}
}
} else {
key = k
}
if key != "" {
kp := strings.TrimSpace(key)
fmt.Print(kp)
fmt.Print(": ")
if key == "id" {
fmt.Print(int(v.(float64)))
} else {
fmt.Print(v)
}
fmt.Print("\n")
}
}
}
示例7: Branch
func Branch(repo *libgit.Repository, args []string) {
switch len(args) {
case 0:
branches, err := repo.GetBranches()
if err != nil {
fmt.Fprintln(os.Stderr, "Could not get list of branches.")
return
}
head := getHeadBranch(repo)
for _, b := range branches {
if head == b {
fmt.Print("* ")
} else {
fmt.Print(" ")
}
fmt.Println(b)
}
case 1:
if head, err := getHeadId(repo); err == nil {
if cerr := libgit.CreateBranch(repo.Path, args[0], head); cerr != nil {
fmt.Fprintf(os.Stderr, "Could not create branch: %s\n", cerr.Error())
}
} else {
fmt.Fprintf(os.Stderr, "Could not create branch: %s\n", err.Error())
}
default:
fmt.Fprintln(os.Stderr, "Usage: go-git branch [branchname]")
}
}
示例8: main
func main() {
files, _ := filepath.Glob(path + "*")
namesSlice := []string{}
for _, basename := range files {
name := strings.TrimSuffix(basename, filepath.Ext(basename))
namesSlice = append(namesSlice, strings.Replace(name, path, "", -1))
}
fmt.Print("var ourskins = \"")
fmt.Print(strings.Join(namesSlice, ":"))
fmt.Println("\";")
fmt.Println("grabbing source from github")
return
/* a work in progress */
cmd := exec.Command("git", "clone", "https://github.com/electronoob/agarmods.git")
err := cmd.Start()
if err != nil {
fmt.Println("some dome error occured: ", err)
}
err = cmd.Wait()
if err != nil {
fmt.Println("Command finished with: ", err)
} else {
cmd := exec.Command("cp", "agarmods/mods.js", "mods.js")
cmd.Start()
cmd.Wait()
cmd = exec.Command("rm", "-rf", "agarmods")
cmd.Start()
cmd.Wait()
}
}
示例9: main
func main() {
app := cli.NewApp()
app.Name = "qunosy" // ヘルプを表示する際に使用される
app.Usage = "print arguments" // ヘルプを表示する際に使用される
app.Version = "0.1.0" // ヘルプを表示する際に使用される
absPath, _ := filepath.Abs("../qunosy")
app.Action = func(c *cli.Context) { // コマンド実行時の処理
if len(c.Args()) > 1 {
if c.Args()[0] == "reload" {
fmt.Println("Reloading qiita log ...")
reload := exec.Command("sh", absPath+"/reload.sh", c.Args()[1])
reloadOut, err := reload.Output()
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Print(string(reloadOut))
} else {
return
}
} else {
qunosy := exec.Command("sh", absPath+"/qunosy.sh")
qunosyOut, err := qunosy.Output()
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Print(string(qunosyOut))
}
}
app.Run(os.Args)
}
示例10: main
func main() {
// Socket to receive messages on
receiver, _ := zmq.NewSocket(zmq.PULL)
defer receiver.Close()
receiver.Bind("tcp://*:5558")
// Socket for worker control
controller, _ := zmq.NewSocket(zmq.PUB)
defer controller.Close()
controller.Bind("tcp://*:5559")
// Wait for start of batch
receiver.Recv(0)
// Start our clock now
start_time := time.Now()
// Process 100 confirmations
for task_nbr := 0; task_nbr < 100; task_nbr++ {
receiver.Recv(0)
if task_nbr%10 == 0 {
fmt.Print(":")
} else {
fmt.Print(".")
}
}
fmt.Println("\nTotal elapsed time:", time.Since(start_time))
// Send kill signal to workers
controller.Send("KILL", 0)
// Finished
time.Sleep(time.Second) // Give 0MQ time to deliver
}
示例11: printPath
func printPath(path []int, start int, end int) {
fmt.Print("[ ")
for i := start; i <= end; i++ {
fmt.Print(path[i], " ")
}
fmt.Print("]\n")
}
示例12: main
func main() {
b, err := ioutil.ReadFile("D:\\James\\Downloads\\kargerMinCut.txt")
if err != nil {
fmt.Println("Error:", err)
return
}
lines := strings.Split(string(b), "\n")
arr := make([][]int, 0, len(lines))
for _, v := range lines {
textints := strings.Split(v, "\t")
subarr := make([]int, 0, len(textints))
for _, w := range textints {
n, err := strconv.Atoi(w)
if err != nil {
fmt.Println("Error yo: ", err)
continue
}
subarr = append(subarr, n)
}
arr = append(arr, subarr)
}
for _, v := range arr {
for _, w := range v {
fmt.Print(w, "\t")
}
fmt.Print("\r\n")
}
}
示例13: main
func main() {
conn, err := net.Dial("tcp", "127.0.0.1:8081")
if err != nil {
fmt.Println("connect to server error!")
return
}
defer conn.Close()
message, _ := bufio.NewReader(conn).ReadString('\n')
fmt.Print(message)
for {
// read in input from stdin
reader := bufio.NewReader(os.Stdin)
fmt.Print("Text to send: ")
text, _ := reader.ReadString('\n')
// send to socket
_, _ = conn.Write([]byte(text))
//fmt.Fprintf(conn, text + "\n")
// listen for reply
message, _ := bufio.NewReader(conn).ReadString('\n')
if (message == "Good bye\n") {
break
} else {
fmt.Print("Message from server: " + message)
}
}
fmt.Println("conn is closed")
}
示例14: main
func main() {
var infile = flag.String("infile", "input13.txt", "Input file")
flag.Parse()
f, err := os.Open(*infile)
if err != nil {
log.Fatal(err)
}
rdr := bufio.NewReader(f)
edges := make(map[string]map[string]int64)
for {
line, err := rdr.ReadString('\n')
if err == io.EOF {
break
}
if err != nil {
log.Fatal(err)
}
AddEdge(edges, line)
}
names := make([]string, len(edges))
i := 0
for name, _ := range edges {
names[i] = name
i++
if edges["me"] == nil {
edges["me"] = make(map[string]int64)
}
edges["me"][name] = 0
edges[name]["me"] = 0
}
names = append(names, "me")
fmt.Print("names: ", names, "\n")
fmt.Print(FindHappiest(edges, names))
}
示例15: main
//A barebones IRC 'client' in the loosest sense of the word.
//Takes input from console. If command starts with a '/', everything after is sent as a raw IRC command.
//Otherwise the first argument is considered the channel/username, and the rest of the line is the message to send
// as a privmsg.
func main() {
flag.Parse()
fmt.Print("Simple Text-Based IRC Test Client\n\n")
fmt.Printf("Connecting to %s . . . \n", *address)
//LogClientHandler will handle printing out to stdio unless we change the default logger
client, err := irc.NewClient(*address, *ssl, irc.LogHandler)
if err != nil {
log.Fatalf("Error: %s", err.Error())
}
fmt.Print("Connected.\n\n")
client.Send(irc.UserMessage(*username, "host", "domain", "realname"))
client.Send(irc.NickMessage(*nick))
client.Send(irc.JoinMessage("#go_test"))
//Listen for input.
go readInput(client)
for { //Continuously read from the client until an error occurs
_, err := client.Read()
if err != nil {
fmt.Printf("ERROR: %s\n", err.Error())
fmt.Print("Exiting...")
return
}
}
}