github.com/gobwas/gtrace@v0.4.3/examples/buildtags/main.go (about)

     1  package main
     2  
     3  import (
     4  	"log"
     5  	"os"
     6  )
     7  
     8  //go:generate gtrace -tag gtrace
     9  
    10  //gtrace:gen
    11  //gtrace:set shortcut
    12  type Trace struct {
    13  	OnInput func(string) func()
    14  }
    15  
    16  func main() {
    17  	log.SetFlags(0)
    18  	log.SetPrefix("[logs] ")
    19  
    20  	t := logTrace(Trace{})
    21  	done := traceOnInput(t, os.Args[1])
    22  	defer done()
    23  }
    24  
    25  func logTrace(t Trace) Trace {
    26  	return t.Compose(Trace{
    27  		OnInput: func(s string) func() {
    28  			log.Printf("processing %q", s)
    29  			return func() {
    30  				log.Printf("processed %q", s)
    31  			}
    32  		},
    33  	})
    34  }