func main() {
	var configPath = flag.String("c", "", "configuration file path")
	flag.Parse()

	var config Config
	_, err := LoadConfig(*configPath, &config)
	if err != nil {
		fmt.Println(err)
		return
	}
	setLogLevel(config.Log)
	sleep := time.Duration(config.SleepTime*60) * time.Second

	var googlePlayURL string
	var appStoreURL string
	payload := golack.Payload{
		config.Slack,
	}

	checkIos := true
	if config.Ios.AppId == "" {
		checkIos = false
		log.Debug("AppId is empty.")
	} else {
		appStoreURL = createAppStoreURL(config.Ios)
		log.Info("Check App Store URL : " + appStoreURL)
	}
	checkAndroid := true
	if config.Android.Package == "" {
		checkAndroid = false
		log.Debug("Package is empty.")
	} else {
		googlePlayURL = createGooglePlayURL(config.Android)
		log.Info("Check Google Play URL : " + googlePlayURL)
	}

	log.Info("Slack Post Message : " + config.Slack.Text)

	for {
		if checkAndroid {
			if checkUpdate(googlePlayURL) {
				golack.Post(payload, config.Webhook)
				log.Info("Update!!!!!!!!!!!")
				break
			} else {
				log.Info("No Update")
			}
		}
		if checkIos {
			if checkUpdateIos(appStoreURL) {
				golack.Post(payload, config.Webhook)
				log.Info("Update!!!!!!!!!!!")
				break
			} else {
				log.Info("No Update")
			}
		}
		time.Sleep(sleep)
	}

	log.Info("Update check end.")
}
Exemple #2
0
func main() {
	var configPath = flag.String("c", "", "configuration file path")
	var version = flag.Bool("v", false, "version")
	flag.Parse()

	if *version {
		fmt.Printf(`tonkotus version %s`, VERSION)
		return
	}

	var config Config
	_, err := LoadConfig(*configPath, &config)
	if err != nil {
		fmt.Println(err)
		return
	}
	setLogLevel(config.Log)
	sleep := time.Duration(config.SleepTime*60) * time.Second

	var googlePlayURL string
	var appStoreURL string
	uPayload := golack.Payload{
		config.SlackUpdatePost,
	}

	ePayload := golack.Payload{
		config.SlackErrorPost,
	}

	if config.SlackStartPost.Text != "" {
		sPayload := golack.Payload{
			config.SlackStartPost,
		}
		golack.Post(sPayload, config.Webhook)
	}

	checkIos := true
	if config.Ios.AppID == "" {
		checkIos = false
		log.Debug("AppId is empty.")
	} else {
		appStoreURL = createAppStoreURL(config.Ios)
		log.Info("Check App Store URL : " + appStoreURL)
	}
	checkAndroid := true
	if config.Android.Package == "" {
		checkAndroid = false
		log.Debug("Package is empty.")
	} else {
		googlePlayURL = createGooglePlayURL(config.Android)
		log.Info("Check Google Play URL : " + googlePlayURL)
	}

	log.Info("Slack Post Message : " + config.SlackUpdatePost.Text)
	log.Info("Slack Errro Message : " + config.SlackErrorPost.Text)

	for {
		if checkAndroid {
			isUpdate, err := checkUpdate(googlePlayURL)
			if err != nil && config.ErrorPost {
				ePayload.Slack.Text = ePayload.Slack.Text + "\n" + err.Error()
				log.Error("Slack Errro Message : " + ePayload.Slack.Text)
				golack.Post(ePayload, config.Webhook)
			}
			if isUpdate {
				golack.Post(uPayload, config.Webhook)
				log.Info("Update!!!!!!!!!!!")
				break
			} else {
				log.Info("No Update")
			}
		}
		if checkIos {
			isUpdate, err := checkUpdateIos(appStoreURL)
			if err != nil && config.ErrorPost {
				golack.Post(ePayload, config.Webhook)
			}
			if isUpdate {
				golack.Post(uPayload, config.Webhook)
				log.Info("Update!!!!!!!!!!!")
				break
			} else {
				log.Info("No Update")
			}
		}
		time.Sleep(sleep)
	}

	log.Info("Update check end.")
}