-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
2,315 additions
and
949 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
# Binaries for programs and plugins | ||
# OS | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
*.tar.gz | ||
target/ | ||
.DS_Store | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
# IDE | ||
.idea/ | ||
.vscode/ | ||
*.iml | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
# Program | ||
target/ | ||
*.test | ||
*.out | ||
|
||
# logs | ||
*.log | ||
|
||
# ide | ||
.idea/ | ||
*.iml | ||
.vscode/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,34 @@ | ||
# Copyright 2021 Ye Zi Jie. All rights reserved. | ||
# Use of this source code is governed by a MIT style | ||
# license that can be found in the LICENSE file. | ||
# | ||
# Postar 配置文件案例 | ||
# Author: FishGoddess | ||
|
||
# Global 是全局配置区块,主要用于配置整体的运行状态。 | ||
# sender_type 配置邮件发送器的类型,可选项为 smtp。默认是 smtp。 | ||
# server_type 配置网络服务器的类型,可选项为 http。默认是 http。 | ||
[global] | ||
#sender_type = "smtp" | ||
#server_type = "http" | ||
|
||
# Logger 是日志配置区块,主要用于配置日志的运行状态。 | ||
# level 配置日志记录的级别,可选项为 debug/info/warn/error/off,其中 off 表示关闭日志记录。默认是 info。 | ||
# time_format 配置日志记录的时间格式化模板,若配置为 "",则将时间记录为 unix 秒级时间戳。默认为 2006-01-02 15:04:05.000。 | ||
# output_file 配置非错误日志的输出文件路径。windows 默认是 ../log/postar.log,其他系统默认是 /opt/postar/log/postar.log。 | ||
# error_output_file 配置错误日志的输出文件路径。windows 默认是 ../log/postar.error.log,其他系统默认是 /opt/postar/log/postar.error.log。 | ||
[logger] | ||
#level = "info" | ||
#time_format = "2006-01-02 15:04:05.000" | ||
#output_file = "/opt/postar/log/postar.log" | ||
#error_output_file = "/opt/postar/log/postar.error.log" | ||
|
||
# Sender 是邮件发送器配置区块,主要用于配置邮件发送器的运行状态。 | ||
# smtp_host 配置 smtp 服务器的主机名。默认从环境变量中取 POSTAR_SMTP_HOST 的值。 | ||
# smtp_port 配置 smtp 服务器的端口号。默认为 587。 | ||
# smtp_user 配置 smtp 服务器的用户名。默认从环境变量中取 POSTAR_SMTP_USER 的值。 | ||
# smtp_password 配置 smtp 服务器的密码。默认从环境变量中取 POSTAR_SMTP_PASSWORD 的值。 | ||
# worker_number 配置邮件发送器的异步工作协程数,仅在 sender_type 为 smtp 时有效。默认为 64。 | ||
# request_channel_size 配置发送请求任务队列的最大大小,若任务堆积导致队列满了,则新的发送请求会被阻塞。默认为 65536。 | ||
[sender] | ||
#smtp_host = "smtp.xxx.com" | ||
#smtp_port = 587 | ||
#smtp_user = "[email protected]" | ||
#smtp_password = "xxx" | ||
#worker_number = 64 | ||
#request_channel_size = 65536 | ||
|
||
# Server 是网络服务器配置区块,主要用于配置网络服务器的运行状态。 | ||
# address 配置网络服务器的绑定地址,包括 IP 和端口号。默认为 :5897。 | ||
# use_http2 选择是否使用 http2(建议使用 h2 标准配置证书),可选项为 true/false。默认为 false。 | ||
# tls_cert 配置 TLS 证书文件的路径,只有 use_http2 = true,该选项才会生效。windows 默认为 ../conf/postar_cert.pem,其它系统默认是 /opt/postar/conf/postar_cert.pem。 | ||
# tls_cert_key 配置 TLS 证书 key 文件的路径,只有 use_http2 = true,该选项才会生效。windows 默认为 ../conf/postar_cert.key,其它系统默认是 /opt/postar/conf/postar_cert.key。 | ||
# wait_for_closing 配置服务器关闭等待时间,服务关闭时会等待请求处理完成,若等待超过改时间,服务会强制退出。单位为秒,默认是 30 秒。 | ||
[task] | ||
# Start how many workers to finish tasks. | ||
# Default is 64. | ||
worker_number = 64 | ||
# The max size of task queue, tasks will be blocked if queue is full. | ||
# Set to 0 if you want queue is unlimited. | ||
queue_size = 0 | ||
# The sending mode of task, available values: true, false. | ||
# This will apply to all tasks and you can use options to override this value in request. | ||
# Default is false. | ||
async = false | ||
# The sending timeout in millisecond of task. | ||
# This will apply to all tasks and you can use options to override this value in request. | ||
# Default is 10s. | ||
timeout = 10000 | ||
[server] | ||
#address = ":5897" | ||
#use_http2 = false | ||
#tls_cert = "../conf/postar_cert.pem" | ||
#tls_cert_key = "../conf/postar_cert.key" | ||
#wait_for_closing = 30 | ||
# Available values: http, grpc. | ||
# Default is http. | ||
type = "http" | ||
# You can bind a specific ip and port for your server. | ||
address = ":5897" | ||
# The closing timeout in second of server. | ||
# Default is 30s. | ||
stop_timeout = 30 | ||
[smtp] | ||
# Specify your smtp server host. | ||
host = "" | ||
# Specify your smtp server port. | ||
# Default is 587. | ||
port = 587 | ||
# Specify your smtp server user. | ||
user = "" | ||
# Specify your smtp server password. | ||
password = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/avinoplan/postar/api" | ||
"google.golang.org/grpc" | ||
"os" | ||
) | ||
|
||
func main() { | ||
conn, err := grpc.Dial("127.0.0.1:5897", grpc.WithInsecure()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer conn.Close() | ||
|
||
req := &api.SendEmailRequest{ | ||
Email: &api.Email{ | ||
Receivers: []string{os.Getenv("POSTAR_RECEIVER")}, | ||
Subject: "测试邮件", | ||
BodyType: "text/html", | ||
Body: "<p>邮件内容</p>", | ||
}, | ||
Options: nil, | ||
} | ||
fmt.Printf("client req: %+v\n", req) | ||
|
||
client := api.NewPostarServiceClient(conn) | ||
rsp, err := client.SendEmail(context.Background(), req) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Printf("server rsp: %+v\n", rsp) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"github.com/avinoplan/postar/api" | ||
"google.golang.org/protobuf/proto" | ||
"io/ioutil" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
func main() { | ||
url := "http://127.0.0.1:5897/sendEmail" | ||
|
||
emailReq := &api.SendEmailRequest{ | ||
Email: &api.Email{ | ||
Receivers: []string{os.Getenv("POSTAR_RECEIVER")}, | ||
Subject: "测试邮件", | ||
BodyType: "text/html", | ||
Body: "<p>邮件内容</p>", | ||
}, | ||
Options: nil, | ||
} | ||
fmt.Printf("client req: %+v\n", emailReq) | ||
|
||
marshaled, err := proto.Marshal(emailReq) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
resp, err := http.Post(url, "application/octet-stream", bytes.NewReader(marshaled)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer resp.Body.Close() | ||
|
||
body, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
emailRsp := new(api.SendEmailResponse) | ||
err = proto.Unmarshal(body, emailRsp) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Printf("server rsp: %+v\n", emailRsp) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.