Skip to content

Commit 8d9d9c5

Browse files
committed
update
1 parent 4a8cf87 commit 8d9d9c5

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

email/email.go

+11-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/chenjie199234/Corelib/util/ctime"
1616
)
1717

18-
type EmailClientConfig struct {
18+
type Config struct {
1919
EmailName string `json:"email_name"`
2020
MaxOpen uint16 `json:"max_open"` //0: default 100
2121
MaxConnIdletime ctime.Duration `json:"max_conn_idletime"` //<=0 means no idle time out
@@ -24,12 +24,12 @@ type EmailClientConfig struct {
2424
Account string `json:"account"`
2525
Password string `json:"password"`
2626
}
27-
type EmailClient struct {
28-
c *EmailClientConfig
27+
type Client struct {
28+
c *Config
2929
p *cpool.CPool[*smtp.Client]
3030
}
3131

32-
func NewEmailClient(c *EmailClientConfig) (*EmailClient, error) {
32+
func NewEmail(c *Config) (*Client, error) {
3333
if c.MaxOpen == 0 {
3434
c.MaxOpen = 100
3535
}
@@ -39,7 +39,7 @@ func NewEmailClient(c *EmailClientConfig) (*EmailClient, error) {
3939
if c.Account == "" || c.Password == "" {
4040
return nil, errors.New("missing account/password in the config")
4141
}
42-
client := &EmailClient{
42+
return &Client{
4343
c: c,
4444
p: cpool.NewCPool(uint32(c.MaxOpen), func() (*smtp.Client, error) {
4545
client, e := smtp.Dial(c.Host + ":" + strconv.FormatUint(uint64(c.Port), 10))
@@ -60,16 +60,15 @@ func NewEmailClient(c *EmailClientConfig) (*EmailClient, error) {
6060
}, c.MaxConnIdletime.StdDuration(), func(client *smtp.Client) {
6161
client.Close()
6262
}),
63-
}
64-
return client, nil
63+
}, nil
6564
}
66-
func (c *EmailClient) SendTextEmail(ctx context.Context, to []string, subject string, body []byte) error {
65+
func (c *Client) SendTextEmail(ctx context.Context, to []string, subject string, body []byte) error {
6766
return c.do(ctx, to, subject, "text/plain; charset=UTF-8", body)
6867
}
69-
func (c *EmailClient) SendHtmlEmail(ctx context.Context, to []string, subject string, body []byte) error {
68+
func (c *Client) SendHtmlEmail(ctx context.Context, to []string, subject string, body []byte) error {
7069
return c.do(ctx, to, subject, "text/html; charset=UTF-8", body)
7170
}
72-
func (c *EmailClient) do(ctx context.Context, to []string, subject string, mimetype string, body []byte) (e error) {
71+
func (c *Client) do(ctx context.Context, to []string, subject string, mimetype string, body []byte) (e error) {
7372
ctx, span := trace.NewSpan(ctx, "Corelib.Email", trace.Client, nil)
7473
span.GetSelfSpanData().SetStateKV("email", c.c.EmailName)
7574
span.GetSelfSpanData().SetStateKV("host", c.c.Host+":"+strconv.FormatUint(uint64(c.c.Port), 10))
@@ -115,7 +114,7 @@ func (c *EmailClient) do(ctx context.Context, to []string, subject string, mimet
115114
return
116115
}
117116
}
118-
func (c *EmailClient) formemail(to []string, subject string, mimetype string, body []byte) []byte {
117+
func (c *Client) formemail(to []string, subject string, mimetype string, body []byte) []byte {
119118
//from
120119
count := 6 + len(c.c.Account) + 2
121120
//to
@@ -154,7 +153,7 @@ func (c *EmailClient) formemail(to []string, subject string, mimetype string, bo
154153
buf = append(buf, body...)
155154
return buf
156155
}
157-
func (c *EmailClient) sendemail(client *smtp.Client, to []string, email []byte) (e error, del bool) {
156+
func (c *Client) sendemail(client *smtp.Client, to []string, email []byte) (e error, del bool) {
158157
defer func() {
159158
if e != nil && client.Reset() != nil {
160159
del = true

internal/version/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "fmt"
44

55
var major = 0
66
var minor = 0
7-
var patch = 114
7+
var patch = 115
88
var status = ""
99

1010
func String() string {

0 commit comments

Comments
 (0)