From: Kiran Kamineni Date: Mon, 8 Oct 2018 21:25:37 +0000 (-0700) Subject: Fix bug in directory read with json files X-Git-Tag: 3.0.0~1 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F20%2F70020%2F2;p=aaf%2Fsms.git Fix bug in directory read with json files The cmdline tool to preload json files is reading from CWD instead of using the provided commandline dir. Issue-ID: AAF-544 Change-Id: I8af23f0556ff678c33223e6f6acac402a39dd662 Signed-off-by: Kiran Kamineni --- diff --git a/sms-service/src/preload/preload.go b/sms-service/src/preload/preload.go index cbf345f..af6e1f6 100644 --- a/sms-service/src/preload/preload.go +++ b/sms-service/src/preload/preload.go @@ -28,7 +28,6 @@ import ( "net/http" "net/url" "path/filepath" - "strconv" "strings" "time" @@ -213,19 +212,26 @@ func main() { "Path to the CA Certificate file") serviceurl := flag.String("serviceurl", "https://aaf-sms.onap", "Url for the SMS Service") - serviceport := flag.Int("serviceport", 10443, + serviceport := flag.String("serviceport", "10443", "Service port if its different than the default") jsondir := flag.String("jsondir", ".", "Folder containing json files to upload") flag.Parse() + //Clear all trailing/leading spaces from incoming strings + *cacert = strings.TrimSpace(*cacert) + *serviceurl = strings.TrimSpace(*serviceurl) + *serviceport = strings.TrimSpace(*serviceport) + *jsondir = strings.TrimSpace(*jsondir) + files, err := ioutil.ReadDir(*jsondir) if err != nil { log.Fatal(pkgerrors.Cause(err)) } - serviceURL, err := url.Parse(*serviceurl + ":" + strconv.Itoa(*serviceport)) + //URL validity is checked here + serviceURL, err := url.Parse(*serviceurl + ":" + *serviceport) if err != nil { log.Fatal(pkgerrors.Cause(err)) } @@ -239,8 +245,8 @@ func main() { for _, file := range files { if filepath.Ext(file.Name()) == ".json" { - fmt.Println("Processing ", file.Name()) - d, err := processJSONFile(file.Name()) + fmt.Println("Processing ", filepath.Join(*jsondir, file.Name())) + d, err := processJSONFile(filepath.Join(*jsondir, file.Name())) if err != nil { log.Printf("Error Reading %s : %s", file.Name(), pkgerrors.Cause(err)) continue