Example #1
0
func printFunctions() {
	c := make(chan string, 20)
	var wg sync.WaitGroup
	sep := string(os.PathSeparator)
	bindir, err := bindir.Path()
	if err != nil {
		log.Fatalln(err)
	}
	go func() {
		for _, name := range info.ListFunctions(bindir) {
			wg.Add(1)
			go func(name, bindir, sep string) {
				info, err := info.ByName(name, bindir, sep)
				if err != nil {
					return
				}
				time := info.Time.Format("2006-01-02 15:04")
				c <- fmt.Sprintf("%s  %v  %s", name, time, info.Goversion)
				wg.Done()
			}(name, bindir, sep)
		}
		wg.Wait()
		close(c)
	}()
	for row := range c {
		fmt.Println(row)
	}
}
Example #2
0
File: run.go Project: thibran/gofn
func (r *Run) functionExists(name string) bool {
	for _, fn := range info.ListFunctions(r.bindir) {
		if name == fn {
			return true
		}
	}
	return false
}
Example #3
0
// Clean removes the oldest gofn functions if there are more than itemMax.
// itemMax is specified by the environment variable GOFN_MAX or defaults to 200.
func (c *Cleaner) Clean() {
	var arr cleanItems
	for _, name := range info.ListFunctions(c.bindir) {
		info, err := info.ByName(name, c.bindir, c.sep)
		if err != nil {
			continue
		}
		//arr = append(arr, info.Time.Unix())
		arr = append(arr, cleanItem{
			name: name,
			time: info.Time.Unix(),
		})
	}
	sort.Sort(arr)
	for _, item := range arr.notNeeded(c.itemMax) {
		deleteGofn(item.nameToPath(c.bindir, c.sep))
	}
}