示例#1
0
文件: function.go 项目: thibran/gofn
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)
	}
}
示例#2
0
文件: run.go 项目: thibran/gofn
// checkHash is true, if the existing gofn function has the same fnv hash-value.
func (r *Run) checkHash(name string, newFnvHash uint32) (bool, error) {
	if ok := r.functionExists(name); !ok {
		return ok, nil
	}
	info, err := info.ByName(name, r.bindir, r.sep)
	if err != nil {
		return false, err
	}
	return info.FnvHash == newFnvHash, nil
}
示例#3
0
文件: clean.go 项目: thibran/gofn
// 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))
	}
}