utils

command module
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2022 License: MIT Imports: 10 Imported by: 0

README

Golang项目中可能常用到的工具库

邮件发送

# install the package
$ go get -v github.com/goops-top/utils/mail

# update the mail data
$ cat test-mail.go

package main

import (
	"fmt"

	"github.com/goops-top/utils/mail"
)

func main() {
	maildata := &mail.EmailMetaData{
		Smtp:        "smtp.qq.com",
		From:        "goops@qq.com",
		Pass:        "passwoed",
		To:          []string{"goops@qq.com"},
		Cc:          []string{"weichuangxxb@qq.com"},
		Subject:     "test",
		ContentType: "text",
		Content:     []byte("hahahah"),
	}
	emailErr := maildata.PostEmail()
	if emailErr != nil {
		fmt.Printf("邮件发送失败:%v\n", emailErr)
	} else {
		fmt.Println("邮件已发送")
	}

}


# test mail
$ go run test-mail.go
邮件已发送

kafka


$ go get -v github.com/goops-top/utils/kafka

$ cat consumer.go
package main 
import (
    "os/signal"
    "syscall"
    "os"

    "github.com/goops-top/utils/kafka"
    log "github.com/sirupsen/logrus"
)


func main() {

	brokers := []string{"127.0.0.1:9092"}
	consumerApi := kafka.NewConsumerApi(brokers,"consumerGroup","latest")

	defer consumerApi.Close()

	c := consumerApi.ConsumerMsgFromTopics("topicName")

	sigterm := make(chan os.Signal, 1)
	signal.Notify(sigterm, syscall.SIGINT, syscall.SIGTERM)
	select {
	case <-sigterm:
		log.Warnln("terminating: via signal")
	}
	c()


}

Documentation

Overview

Copyright 2020 BGBiao Ltd. All rights reserved. @File : sasl-kafka.go @Time : 2021/03/18 20:51:21 @Update : 2021/03/18 20:51:21 @Author : BGBiao @Version: 1.0 @Contact: weichaungxxb@qq.com @Desc : None

Directories

Path Synopsis
================================================================ *Copyright (C) 2020 BGBiao Ltd.
================================================================ *Copyright (C) 2020 BGBiao Ltd.
================================================================ *Copyright (C) 2020 BGBiao Ltd.
================================================================ *Copyright (C) 2020 BGBiao Ltd.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL