Exemplo n.º 1
0
//-----------------------------------------------------------------------------
// Test
//-----------------------------------------------------------------------------
func TestMail(t *testing.T) {

	type BodyInfo struct {
		ToName   string
		FromName string
	}

	conf := conf.GetConf().Mail

	//subject
	subject := conf.Content[0].Subject
	lg.Debugf("mail conf: %s", subject)

	//body
	path := os.Getenv("GOPATH") + conf.Content[0].Tplfile
	bodyParam := BodyInfo{ToName: "Hiroki", FromName: "Harry"}
	body, err := tpl.FilePathParser(path, bodyParam)
	if err != nil {
		t.Fatalf("FilePathParser error: %s", err)
	}

	//mails
	smtp := SMTP{Address: conf.Address, Pass: conf.Password, Server: conf.SMTP.Server, Port: conf.SMTP.Port}
	ml := &Info{ToAddress: []string{mailTo}, FromAddress: conf.Address,
		Subject: subject, Body: body, SMTP: smtp}
	ml.SendMail(conf.Timeout)
}
Exemplo n.º 2
0
//-----------------------------------------------------------------------------
// functions
//-----------------------------------------------------------------------------
func NewMySQL() {
	c := conf.GetConf().MySQL

	New(c.Host, c.DbName, c.User, c.Pass, c.Port)

	db = MySQL{}
	db.GR = GetDB()
}
Exemplo n.º 3
0
//For embedded type
func newMySQL2() {
	conf.SetTOMLPath("../../settings.toml")
	c := conf.GetConf().MySQL

	New(c.Host, c.DbName, c.User, c.Pass, c.Port)

	db2 = MySQL2{}
	db2.MS = GetDB()
}
Exemplo n.º 4
0
func setup() {
	c := conf.GetConf().Redis

	//New("localhost", 6379)
	New(c.Host, c.Port, c.Pass, 0)
	//if !tu.BenchFlg {
	//	GetRedis().Connection(0)
	//}
}
Exemplo n.º 5
0
func setup() {
	c := conf.GetConf().Mongo

	New(c.Host, c.DbName, c.User, c.Pass, c.Port)
	if c.DbName != "" {
		//GetMongo().GetDB("hiromaily")
		GetMongo().GetDB(c.DbName)
	}
}
Exemplo n.º 6
0
// New is to create sqs client
func New() {
	//set environment variable
	awslib.InitAwsEnv("", "")

	//get config
	conf := conf.GetConf()

	//create client for sqs
	svc = sqs.New(session.New(), aws.NewConfig().WithRegion(conf.Aws.Region))
}
Exemplo n.º 7
0
func connection() {
	c := conf.GetConf().Cassa

	hosts := []string{c.Host}
	//port := 9042
	err := New(hosts, int(c.Port), c.KeySpace)
	if err != nil {
		lg.Errorf("New() error: %s", err)
	}
}
Exemplo n.º 8
0
func purgeSQSData() {
	New()
	conf := conf.GetConf()

	inputParams := CreateInputParam(conf.Aws.Sqs.QueueName)
	sendMsgRes, err := CreateNewQueue(inputParams)
	if err != nil {
		panic(err.Error())
	}

	//fmt.Println(*sendMsgRes.QueueUrl)
	PurgeQueue(sendMsgRes.QueueUrl)
}
Exemplo n.º 9
0
// Set SQS on AWS
func setSQSData(num int, msg string) {
	conf := conf.GetConf()
	//conf.Aws.Sqs.QueueName -> test_message

	//1.オブジェクト作成
	New()
	//2.sqsにqueueがあるかチェック
	//3.なければ作成
	inputParams := CreateInputParam(conf.Aws.Sqs.QueueName)
	sendMsgRes, err := CreateNewQueue(inputParams)
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("sendMsgRes : %v \n", sendMsgRes)

	//4.deadMessage用も同じく、
	//5.なければ作成
	inputParamsForDead := CreateInputParam(conf.Aws.Sqs.DeadQueueName)
	deadMsgRes, err := CreateNewQueue(inputParamsForDead)
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("deadMsgRes : %v \n", deadMsgRes)

	//6.メッセージを作成
	//body := getContentBody("send message dayo")
	body := getContentBody(msg)
	acid := ""
	if num == 1 {
		sendInputParams := CreateSendMessageInput(sendMsgRes.QueueUrl, &body, &acid, *ot, *ct)

		//7.メッセージを送信
		SendMessageToQueue(sendInputParams)
	} else {
		var bulkCount = num / 10
		if bulkCount >= 1 {
			for i := 0; i < bulkCount; i++ {
				sendBulkProcedure(sendMsgRes.QueueUrl, &body, &acid, 10)
			}
			if num%10 != 0 {
				sendBulkProcedure(sendMsgRes.QueueUrl, &body, &acid, num%10)
			}
		} else {
			sendBulkProcedure(sendMsgRes.QueueUrl, &body, &acid, num)
		}
	}
}
Exemplo n.º 10
0
// CreateSendMessageBatchInput is to create input parameter for batch
// up to ten messages!!
func CreateSendMessageBatchInput(url *string, body *string, acid *string, ot string, ct string, num int) (params *sqs.SendMessageBatchInput) {
	var acidData = "736afbdc388752eb"
	if *acid != "" {
		acidData = *acid
	}
	conf := conf.GetConf()
	if ot == "0" {
		ot = conf.Aws.Sqs.MsgAttr.OpType
	}
	if ct == "0" {
		ct = conf.Aws.Sqs.MsgAttr.OpType
	}

	var entries []*sqs.SendMessageBatchRequestEntry
	for i := 0; i < num; i++ {
		entry := &sqs.SendMessageBatchRequestEntry{
			Id:          aws.String(strconv.Itoa(i + 1)),
			MessageBody: aws.String(*body),
			//QueueUrl:     aws.String(*url),
			DelaySeconds: aws.Int64(0),
			MessageAttributes: map[string]*sqs.MessageAttributeValue{
				"operationType": {
					DataType:    aws.String("Number"),
					StringValue: aws.String(ot),
				},
				"clientId": {
					DataType:    aws.String("String"),
					StringValue: aws.String(acidData),
				},
				"contentType": {
					DataType:    aws.String("Number"),
					StringValue: aws.String(ct),
				},
			},
		}
		entries = append(entries, entry)
	}

	params = &sqs.SendMessageBatchInput{
		Entries:  entries,
		QueueUrl: aws.String(*url), // Required
	}
	return
}
Exemplo n.º 11
0
func getSQSAttributes() {
	New()
	conf := conf.GetConf()

	inputParams := CreateInputParam(conf.Aws.Sqs.QueueName)
	sendMsgRes, err := CreateNewQueue(inputParams)
	if err != nil {
		panic(err.Error())
	}

	//check attribute
	params := CreateAttributesParams(sendMsgRes.QueueUrl)
	resp, err := GetQueueAttributes(params)

	//fmt.Printf("%s", resp)
	//fmt.Printf("%v", resp.Attributes)
	//fmt.Printf("%s", *resp.Attributes["ApproximateNumberOfMessages"])

	//暫定対応
	fmt.Printf("%s,%s", *resp.Attributes["ApproximateNumberOfMessages"], *resp.Attributes["ApproximateNumberOfMessagesNotVisible"])

	//ApproximateNumberOfMessages: "3",

}
Exemplo n.º 12
0
func newRedis() {
	r := conf.GetConf().Redis

	redis.New(r.Host, r.Port, r.Pass, 0)
	//redis.GetRedisInstance().Connection(0)
}