Beispiel #1
0
// ServeMessageWithStatus serves a HTTP status and messages.
func (baseController *BaseController) ServeMessagesWithStatus(status int, msgs []string) {
	tracelog.INFO("BaseController", "ServeMessagesWithStatus", "Application Error, Exiting : %#v", msgs)

	baseController.Ctx.Output.SetStatus(status)
	response := MessageResponse{Messages: msgs}
	baseController.Data["json"] = &response
	baseController.ServeJson()
}
Beispiel #2
0
// LogModel writes a specified model object into the logs
// as a formatted JSON document
func LogModel(obj interface{}, useTrace bool) {
	bArray, _ := json.MarshalIndent(obj, "", "    ")

	if useTrace {
		tracelog.TRACE("utils", "LogModel", "Obj => \n\n%s\n\n", string(bArray))
	} else {
		tracelog.INFO("utils", "LogModel", "Obj => \n\n%s\n\n", string(bArray))
	}
}
Beispiel #3
0
// loadResponse parse a response.
func loadResponse(resp *http.Response) ([]byte, error) {
	tracelog.STARTED("http_client", "loadResponse")

	contents, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}

	defer resp.Body.Close()

	tracelog.INFO("yodlee_api", "loadResponse", "Api Response => \n\n %s \n\n", contents)

	if resp.StatusCode != 200 {
		return nil, errors.New(string(contents))
	}

	tracelog.COMPLETED("http_client", "loadResponse")
	return contents, err
}
Beispiel #4
0
// loadTranslationFiles loads the found translation files into the i18n
// messaging system for use by the application
func loadTranslationFiles(directory string) {
	// Read the directory
	fileInfos, err := ioutil.ReadDir(directory)
	if err != nil {
		tracelog.COMPLETED_ERROR(err, "localize", "loadTranslationFiles")
		return
	}

	// Look for JSON files
	for _, fileInfo := range fileInfos {
		if path.Ext(fileInfo.Name()) != ".json" {
			continue
		}

		fileName := fmt.Sprintf("%s/%s", directory, fileInfo.Name())

		tracelog.INFO("localize", "loadTranslationFiles", "Loading %s", fileName)
		i18n.MustLoadTranslationFile(fileName)
	}
}
Beispiel #5
0
// LoadFiles looks for i18n folders inside the current directory and the GOPATH
// to find translation files to load
func LoadFiles(userLocale string, defaultLocal string) error {
	gopath := os.Getenv("GOPATH")
	pwd, err := os.Getwd()
	if err != nil {
		tracelog.COMPLETED_ERROR(err, "localize", "LoadFiles")
		return err
	}

	tracelog.INFO("localize", "LoadFiles", "PWD[%s] GOPATH[%s]", pwd, gopath)

	// Load any translation files we can find
	searchDirectory(pwd, pwd)
	if gopath != "" {
		searchDirectory(gopath, pwd)
	}

	// Create a translation function for use
	T, err = i18n.Tfunc(userLocale, defaultLocal)
	if err != nil {
		return err
	}

	return nil
}
Beispiel #6
0
// ServeUnAuthorized returns an Unauthorized error.
func (baseController *BaseController) ServeUnAuthorized() {
	tracelog.INFO("BaseController", "ServeUnAuthorized", "UnAuthorized, Exiting")

	baseController.ServeMessageWithStatus(appErrors.UNAUTHORIZED_ERROR_CODE, localize.T(appErrors.UNAUTHORIZED_ERROR_MSG))
}