-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.helpers.go
113 lines (104 loc) · 3.23 KB
/
main.helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"strconv"
_ "strings"
_ "time"
"github.com/hornbill/goHornbillHelpers"
)
// loadConfig -- Function to Load Configruation File
func loadConfig() (importConfStruct, bool) {
boolLoadConf := true
//-- Check Config File File Exists
cwd, _ := os.Getwd()
configurationFilePath := cwd + "/" + configFileName
logger(1, "Loading Config File: "+configurationFilePath, false)
if _, fileCheckErr := os.Stat(configurationFilePath); os.IsNotExist(fileCheckErr) {
logger(4, "No Configuration File", true)
os.Exit(102)
}
//-- Load Config File
file, fileError := os.Open(configurationFilePath)
//-- Check For Error Reading File
if fileError != nil {
logger(4, "Error Opening Configuration File: "+fmt.Sprintf("%v", fileError), true)
boolLoadConf = false
}
//-- New Decoder
decoder := json.NewDecoder(file)
//-- New Var based on importConfStruct
edbConf := importConfStruct{}
//-- Decode JSON
err := decoder.Decode(&edbConf)
//-- Error Checking
if err != nil {
logger(4, "Error Decoding Configuration File: "+fmt.Sprintf("%v", err), true)
boolLoadConf = false
}
//-- Return New Config
return edbConf, boolLoadConf
}
// parseFlags - grabs and parses command line flags
func parseFlags() {
flag.StringVar(&configFileName, "file", "conf.json", "Name of the configuration file to load")
flag.StringVar(&configOutputFolder, "output", "", "Folder to store downloads in - overrides AttachmentFolder from the conf.json")
flag.BoolVar(&configDryRun, "dryrun", false, "Do not delete the files from the server")
flag.IntVar(&configCutOff, "cutoff", globalDefaultCutOff, "Set the cut off date in weeks ("+strconv.Itoa(globalUltimateCutOff)+" or greater)")
flag.IntVar(&configPageSize, "pagesize", 100, "Set the Query Page Size (default: 100)")
flag.BoolVar(&configRequestUpdate, "updateRequest", false, "Set this to true to update the request with the log of syphoned off files")
flag.BoolVar(&configDoNotArchiveFiles, "DoNotArchiveFiles", false, "Set this to true to and the files will NOT be archived, BUT the files WILL be removed (if not dryrun)")
flag.BoolVar(&configOverride, "override", false, "Set this to true to override the "+strconv.Itoa(globalUltimateCutOff)+" week limit")
flag.StringVar(&configCall, "call", "", "Specify the Request ID")
flag.Parse()
}
func logger(t int, s string, outputToCLI bool) {
hornbillHelpers.Logger(t, s, outputToCLI, localLogFileName)
}
/*
func parseDateTime(dateTime string) string {
layout := "2006-01-02 15:04:05"
t, err := time.Parse(layout, dateTime)
if err != nil && dateTime != "" {
//return first 19 chars of string
dateString := dateTime[0:18]
return dateString
}
return fmt.Sprintf("%s", t)
}
*/
/*
func loggerGen(t int, s string) string {
var errorLogPrefix = ""
//-- Create Log Entry
switch t {
case 1:
errorLogPrefix = "[DEBUG] "
case 2:
errorLogPrefix = "[MESSAGE] "
case 3:
errorLogPrefix = ""
case 4:
errorLogPrefix = "[ERROR] "
case 5:
errorLogPrefix = "[WARNING] "
case 6:
errorLogPrefix = ""
}
return errorLogPrefix + s + "\n\r"
}
*/
/*
func loggerWriteBuffer(s string) {
if s != "" {
logLines := strings.Split(s, "\n\r")
for _, line := range logLines {
if line != "" {
logger(0, line, false)
}
}
}
}
*/