gopkg.in/easygen.v4@v4.1.0/egFilePath/EgFilePath.go (about) 1 //////////////////////////////////////////////////////////////////////////// 2 // Package: egFilePath 3 // Purpose: EasyGen Generic FilePath Functionalities 4 // Authors: Tong Sun (c) 2019, All rights reserved 5 //////////////////////////////////////////////////////////////////////////// 6 7 /* 8 9 Package egFilePath provides filepath manupilation functionalities. 10 11 egFilePath provides filepath manupilation manipulation, provided by "path/filepath". 12 13 */ 14 15 package egFilePath 16 17 import ( 18 "os" 19 "path/filepath" 20 "strings" 21 "text/template" 22 23 "github.com/go-easygen/easygen" 24 ) 25 26 //////////////////////////////////////////////////////////////////////////// 27 // Constant and data type/structure definitions 28 29 // EgFilePath -- EasyGen FilePath manupilation functionalities 30 type EgFilePath struct { 31 *easygen.EgBase 32 } 33 34 var egFuncMap = easygen.FuncMap{ 35 //"fpAbs": filepath.Abs, 36 "fpBase": filepath.Base, 37 "fpClean": filepath.Clean, 38 "fpDir": filepath.Dir, 39 //"fpEvalSymlinks": filepath.EvalSymlinks, 40 "fpExt": filepath.Ext, 41 "fpFromSlash": filepath.FromSlash, 42 //"fpGlob": filepath.Glob, 43 "fpHasPrefix": filepath.HasPrefix, 44 "fpIsAbs": filepath.IsAbs, 45 "fpJoin": filepath.Join, 46 //"fpMatch": filepath.Match, 47 "fpRel": filepath.Rel, 48 //"fpSplit": filepath.Split, 49 //"fpSplitList": filepath.SplitList, 50 "fpToSlash": filepath.ToSlash, 51 "fpVolumeName": filepath.VolumeName, 52 "isDir": IsDir, 53 "basename": Basename, 54 } 55 56 //////////////////////////////////////////////////////////////////////////// 57 // Function definitions 58 59 // FuncDefs returns the custom definition mapping for this specific package. 60 func FuncDefs() template.FuncMap { 61 return template.FuncMap(egFuncMap) 62 } 63 64 //========================================================================== 65 // support functions 66 67 func IsDir(path string) bool { 68 info, _ := os.Stat(path) 69 return info.IsDir() 70 } 71 72 func Basename(s string) string { 73 s = filepath.Base(s) 74 n := strings.LastIndexByte(s, '.') 75 if n > 0 { 76 return s[:n] 77 } 78 return s 79 }