template / files / internal / core / parameter_data.go
parameter_data.go
| 1 | package core |
| 2 | |
| 3 | import ( |
| 4 | "path/filepath" |
| 5 | "time" |
| 6 | ) |
| 7 | |
| 8 | type PrePatternData struct { |
| 9 | ProjectName string |
| 10 | Year, Month, Day, Hour, Minute, Second string |
| 11 | YYYY_MM_DD string |
| 12 | YYYY_MM_DD_HH_MM_SS string |
| 13 | Extras map[string]string |
| 14 | } |
| 15 | |
| 16 | type PostPatternData struct { |
| 17 | PrePatternData |
| 18 | FileName string |
| 19 | FileNameWithoutExtension string |
| 20 | FullPath string |
| 21 | } |
| 22 | |
| 23 | func createPrePatternData(now time.Time, projectName string, extras map[string]string) PrePatternData { |
| 24 | prePatternData := PrePatternData{ |
| 25 | Year: now.Format("2006"), |
| 26 | Month: now.Format("01"), |
| 27 | Day: now.Format("02"), |
| 28 | Hour: now.Format("15"), |
| 29 | Minute: now.Format("04"), |
| 30 | Second: now.Format("05"), |
| 31 | YYYY_MM_DD: now.Format("2006-01-02"), |
| 32 | YYYY_MM_DD_HH_MM_SS: now.Format("2006-01-02-15-04-05"), |
| 33 | ProjectName: projectName, |
| 34 | Extras: extras, |
| 35 | } |
| 36 | return prePatternData |
| 37 | } |
| 38 | |
| 39 | func createPostPatternData(fullPath string, prePatternData PrePatternData) PostPatternData { |
| 40 | fileName := filepath.Base(fullPath) |
| 41 | fileNameWithoutExt := fileName[:len(fileName)-len(filepath.Ext(fileName))] |
| 42 | return PostPatternData{ |
| 43 | FullPath: fullPath, |
| 44 | FileName: fileName, |
| 45 | FileNameWithoutExtension: fileNameWithoutExt, |
| 46 | PrePatternData: prePatternData, |
| 47 | } |
| 48 | } |