Пример #1
0
func main() {
	var db *membersys.MembershipDB
	var config membersys.MembersysConfig
	var config_contents []byte
	var config_path string
	var prev_key string
	var help bool
	var err error

	flag.BoolVar(&help, "help", false, "Display help")
	flag.StringVar(&config_path, "config", "",
		"Path to the member creator configuration file")
	flag.Parse()

	if help || config_path == "" {
		flag.Usage()
		os.Exit(1)
	}

	config_contents, err = ioutil.ReadFile(config_path)
	if err != nil {
		log.Fatal("Unable to read ", config_path, ": ", err)
	}
	err = proto.Unmarshal(config_contents, &config)
	if err != nil {
		err = proto.UnmarshalText(string(config_contents), &config)
	}
	if err != nil {
		log.Fatal("Error parsing ", config_path, ": ", err)
	}

	db, err = membersys.NewMembershipDB(
		config.DatabaseConfig.GetDatabaseServer(),
		config.DatabaseConfig.GetDatabaseName(),
		time.Duration(config.DatabaseConfig.GetDatabaseTimeout())*time.Millisecond)
	if err != nil {
		log.Fatal("Unable to connect to the cassandra DB ",
			config.DatabaseConfig.GetDatabaseServer(), " at ",
			config.DatabaseConfig.GetDatabaseName(), ": ", err)
	}

	for {
		var members []*membersys.Member
		var member *membersys.Member

		members, err = db.EnumerateMembers(prev_key, 25)

		if err != nil {
			log.Fatal("Error fetching data starting from ", prev_key, ": ",
				err)
		}
		if len(members) == 0 {
			break
		}

		for _, member = range members {
			fmt.Printf("Name:\t\t%s\r\nAddress:\t%s, %s\r\nEmail:\t\t%s\r\n"+
				"Username:\t%s\r\n\r\n",
				member.GetName(), member.GetStreet(), member.GetCity(),
				member.GetEmail(), member.GetUsername())
			prev_key = member.GetEmail() + "\000"
		}
	}
}
Пример #2
0
func main() {
	var db *membersys.MembershipDB
	var agreement *membersys.MembershipAgreement
	var config membersys.MemberCreatorConfig
	var wm *membersys.WelcomeMail
	var config_contents []byte
	var config_path string
	var lookup_key string
	var help bool
	var err error

	flag.BoolVar(&help, "help", false, "Display help")
	flag.StringVar(&config_path, "config", "",
		"Path to the member creator configuration file")
	flag.StringVar(&lookup_key, "key", "",
		"Key of the user record to look up")
	flag.Parse()

	if help || config_path == "" {
		flag.Usage()
		os.Exit(1)
	}

	config_contents, err = ioutil.ReadFile(config_path)
	if err != nil {
		log.Fatal("Unable to read ", config_path, ": ", err)
	}
	err = proto.Unmarshal(config_contents, &config)
	if err != nil {
		err = proto.UnmarshalText(string(config_contents), &config)
	}
	if err != nil {
		log.Fatal("Error parsing ", config_path, ": ", err)
	}

	db, err = membersys.NewMembershipDB(
		config.DatabaseConfig.GetDatabaseServer(),
		config.DatabaseConfig.GetDatabaseName(),
		time.Duration(config.DatabaseConfig.GetDatabaseTimeout())*time.Millisecond)
	if err != nil {
		log.Fatal("Unable to connect to the cassandra DB ",
			config.DatabaseConfig.GetDatabaseServer(), " at ",
			config.DatabaseConfig.GetDatabaseName(), ": ", err)
	}

	wm, err = membersys.NewWelcomeMail(config.GetWelcomeMailConfig())
	if err != nil {
		log.Fatal("Error setting up mailer: ", err)
	}

	agreement, err = db.GetMemberDetail(lookup_key)
	if err != nil {
		log.Fatal("Error fetching member ", lookup_key, ": ", err)
	}

	err = wm.SendMail(agreement.GetMemberData())
	if err != nil {
		log.Fatal("Error sending mail to ",
			agreement.GetMemberData().GetEmail(), ": ", err)
	}
}