Exemplo n.º 1
0
func init() {
	Logger.Info("init config ...")
	fmt.Println("init config")
	Logger.Info("read auth_pages.yaml")
	file, err := os.Open("properties/auth.pages.yaml")
	if err != nil {
		panic(err)
	}
	defer file.Close()
	bytes, err := ioutil.ReadAll(file)
	if err != nil {
		panic(err)
	}

	var pageConfig authPageConfig
	err = yaml.Unmarshal(bytes, &pageConfig)
	if err != nil {
		panic(err)
	}

	pages := collections.NewSet(10)
	for _, v := range pageConfig.LoginPaths {
		pages.Add(v)
	}
	AuthPageConfig.LoginPaths = pages

	pages = collections.NewSet(10)
	for _, v := range pageConfig.LoginPages {
		pages.Add(v)
	}
	AuthPageConfig.LoginPages = pages

	Logger.Info("required login pages: %v", AuthPageConfig.LoginPages)
	Logger.Info("login paths: %v", AuthPageConfig.LoginPaths)
	Logger.Info("config inited")
}
Exemplo n.º 2
0
//解析 分,时,天,月,星期
func parseArgument(arg string, unitMinValue, unitMaxValue int, unitTye string) (result *collections.Set, isTicker bool, err error) {
	result = collections.NewSet(unitMaxValue - unitMinValue + 1)

	monthesAbbr := map[string]int{"Jan": 1, "Feb": 2, "Mar": 3, "Apr": 4, "May": 5, "Jun": 6, "Jul": 7, "Aug": 8, "Sep": 9, "Oct": 10, "Nov": 11, "Dec": 12}

	monthes := map[string]int{"January": 1, "February": 2, "March": 3, "April": 4,
		"May": 5, "June": 6, "July": 7, "Auguet": 8, "September": 9, "October": 10, "November": 11, "December": 12}

	weekdays := map[string]int{"Sunday": 0, "Monday": 1, "Tuesday": 2, "Wednesday": 3, "Thursday": 4, "Friday": 5, "Saturday": 6}
	weekdaysAbbr := map[string]int{"Sun": 0, "Mon": 1, "Tue": 2, "Wed": 3, "Thu": 4, "Fri": 5, "Sat": 6}

	//先根据comma分割, 因为有 2-4,6格式
	values := strings.Split(arg, ",")
	for _, param := range values {
		var startVal, endVal int
		var convErr error

		if pos := strings.Index(param, "-"); pos != -1 { //类似 1-4 的格式
			startParam := param[:pos]
			endParam := param[pos+1:]

			if unitTye == "month" {
				if montheIndex, ok := monthes[strings.Title(startParam)]; ok { //是英文书写形式
					startVal = montheIndex
					endVal = monthes[endParam]
				} else if montheIndex, ok = monthesAbbr[strings.Title(startParam)]; ok { //是英文简写形式
					startVal = montheIndex
					endVal = monthesAbbr[strings.Title(endParam)]
				} else { //是数字
					startVal, convErr = strconv.Atoi(startParam)
					if convErr != nil {
						err = errors.New(FORMAT_ERROR + " at:" + startParam)
						return
					}

					endVal, convErr = strconv.Atoi(endParam)
					if convErr != nil {
						err = errors.New(FORMAT_ERROR + " at:" + endParam)
						return
					}
				}

			} else if unitTye == "week" {
				if weekIndex, ok := weekdays[strings.Title(startParam)]; ok { //是英文书写形式
					startVal = weekIndex
					endVal = weekdays[endParam]
				} else if weekIndex, ok = weekdaysAbbr[strings.Title(startParam)]; ok { //是英文简写形式
					startVal = weekIndex
					endVal = weekdaysAbbr[strings.Title(endParam)]
				} else { //是数字
					startVal, convErr = strconv.Atoi(startParam)
					if convErr != nil {
						err = errors.New(FORMAT_ERROR + " at:" + startParam)
						return
					}

					endVal, convErr = strconv.Atoi(endParam)
					if convErr != nil {
						err = errors.New(FORMAT_ERROR + " at:" + endParam)
						return
					}
				}
			} else { //不是week和month
				startVal, convErr = strconv.Atoi(startParam)
				if convErr != nil {
					err = errors.New(FORMAT_ERROR + " at:" + startParam)
					return
				}

				endVal, convErr = strconv.Atoi(endParam)
				if convErr != nil {
					err = errors.New(FORMAT_ERROR + " at:" + endParam)
					return
				}
			}

			if endVal < startVal {
				for i := startVal; i <= unitMaxValue; i++ {
					result.Add(i)
				}

				for i := unitMinValue; i <= endVal; i++ {
					result.Add(i)
				}
			} else {
				for i := startVal; i <= endVal; i++ {
					result.Add(i)
				}
			}
		} else if param == "*" {
			for i := unitMinValue; i <= unitMaxValue; i++ {
				result.Add(i)
			}
			return
		} else if idx := strings.Index(param, "*/"); idx != -1 {
			value, convErr := strconv.Atoi(param[idx+2:])
			if convErr != nil {
				err = convErr
				return
			}

			isTicker = true
			result.Add(value)
			return
		} else { //是 单个数字或者单个单词
			if unitTye == "month" {
				if montheIndex, ok := monthes[strings.Title(param)]; ok { //是英文书写形式
					result.Add(montheIndex)
				} else if montheIndex, ok := monthesAbbr[strings.Title(param)]; ok { //是英文书写形式
					result.Add(montheIndex)
				}
			} else if unitTye == "week" {
				if weekIndex, ok := weekdays[strings.Title(param)]; ok { //是英文书写形式
					result.Add(weekIndex)
				} else if weekIndex, ok := weekdaysAbbr[strings.Title(param)]; ok { //是英文书写形式
					result.Add(weekIndex)
				}
			} else {
				convValue, convErr := strconv.Atoi(param)
				if convErr != nil {
					err = errors.New(FORMAT_ERROR + " at:" + param)
					return
				}
				result.Add(convValue)
			}
		}
	}

	for _, v := range result.Values() {
		val, _ := v.(int)
		if val < unitMinValue || val > unitMaxValue {
			err = errors.New(FORMAT_ERROR + " invalid range")
			return
		}
	}

	return
}