go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/projects/nodes/pkg/funcs/stat_file.go (about) 1 /* 2 3 Copyright (c) 2023 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package funcs 9 10 import ( 11 "context" 12 "os" 13 "time" 14 ) 15 16 // StatFile stats a file yielding the modtime as a timestamp. 17 func StatFile(_ context.Context, filepath string) (time.Time, error) { 18 stat, err := os.Stat(os.ExpandEnv(filepath)) 19 if err == os.ErrNotExist { 20 return time.Time{}, nil 21 } 22 if err != nil { 23 return time.Time{}, err 24 } 25 return stat.ModTime(), nil 26 }