Skip to content

Commit

Permalink
Merge pull request #14 from infra-io/develop
Browse files Browse the repository at this point in the history
v0.4.2-alpha
  • Loading branch information
FishGoddess authored Apr 1, 2024
2 parents 083da97 + 6db0ff9 commit f5cc6e5
Show file tree
Hide file tree
Showing 20 changed files with 247 additions and 90 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

# Program
target/
log/
cert/
*.test
*.out
*.log
2 changes: 1 addition & 1 deletion FUTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* [ ] ~~增加异步发送功能(邮件插入到发送队列表,然后通知任务扫描表进行发送)~~
> 感觉这个特性暂时不是很适合,会让现有系统变得比较臃肿,就先取消这个特性的支持了
* [ ] 支持邮件携带附件(需要考虑附件怎么传输,协议怎么设计)
* [ ] TLS 证书支持
* [x] TLS 证书支持
* [ ] 增加监控上报
* [ ] ~~SMTP 连接池优化~~
> 由于库本身的性质并不太好支持连接复用,因此暂时取消这个特性的支持
Expand Down
7 changes: 7 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## ✒ 历史版本的特性介绍 (Features in old versions)

### v0.4.2-alpha

> 此版本发布于 2024-04-01
* 支持 TLS 安全连接
* 部分细节优化,完善配置注释

### v0.4.1-alpha

> 此版本发布于 2024-03-28
Expand Down
32 changes: 16 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
.PHONY: test fmt proto postar postaradmin build clean all
.PHONY: all fmt test build clean proto postar postaradmin

VERSION=v0.4.1-alpha
VERSION=v0.4.2-alpha

test:
go mod tidy
go test -cover ./...
all:
make test && make clean && make build

fmt:
go fmt ./...

proto:
cd api && buf build && buf generate

postar:
go mod tidy
go run cmd/postar/main.go -conf ./configs/postar.toml

postaradmin:
test:
go mod tidy
go run cmd/postar-admin/main.go -conf ./configs/postar_admin.toml
go test -cover ./...

build:
go mod tidy
Expand All @@ -29,5 +21,13 @@ build:
clean:
rm -rf ./target

all:
make test && make clean && make build
proto:
cd api && buf build && buf generate

postar:
go mod tidy
go run cmd/postar/main.go -conf ./configs/postar.toml

postaradmin:
go mod tidy
go run cmd/postar-admin/main.go -conf ./configs/postar_admin.toml
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
### 🥇 Features

* Plain and HTML form email supports
* Synchronous/Asynchronous mode supports, and timeout is available in synchronous mode
* Multi spaces supports, accounts and templates configuration supports
* Support http/grpc protocol
* Gracefully shutdown with signal mechanism

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
### 🥇 功能特性

* 支持发送文本邮件和 HTML 邮件
* 支持同步、异步邮件发送,同步模式可配置超时
* 多业务空间隔离机制,支持账号和模板独立配置
* 支持 http/grpc 等网络协议
* 支持 signal 通知的平滑下线

Expand Down
8 changes: 4 additions & 4 deletions api/requests/postar/email.http
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ X-Postar-Space-Token: alYxRWwwdHg2MWhMc3R1Y25DcXFOU2R5cURGWWUzeXBwWThQdHdCWGpyUk
"cc": [],
"bcc": [],
"subject_params": {
"num": "1",
"subject": "HTML"
"num": "666999",
"subject": "测试 tls 连接"
},
"content_params": {
"p": "哈哈哈哈哈",
"img": "xxx"
"p": "太难嘞这个 server neme",
"img": ""
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ const (
)

type ServerConfig struct {
Type string `json:"type" toml:"type"`
GrpcEndpoint string `json:"grpc_endpoint" toml:"grpc_endpoint"`
HttpEndpoint string `json:"http_endpoint" toml:"http_endpoint"`
RequestTimeout timex.Duration `json:"request_timeout" toml:"request_timeout"`
MaxCloseWaitTime timex.Duration `json:"max_close_wait_time" toml:"max_close_wait_time"`
Type string `json:"type" toml:"type"`
GrpcEndpoint string `json:"grpc_endpoint" toml:"grpc_endpoint"`
HttpEndpoint string `json:"http_endpoint" toml:"http_endpoint"`
UseTLS bool `json:"use_tls" toml:"use_tls"`
CertFile string `json:"cert_file" toml:"cert_file"`
KeyFile string `json:"key_file" toml:"key_file"`
RequestTimeout timex.Duration `json:"request_timeout" toml:"request_timeout"`
CloseServerTimeout timex.Duration `json:"close_server_timeout" toml:"close_server_timeout"`
}

type DatabaseConfig struct {
Address string `json:"address" toml:"address"`
Username string `json:"username" toml:"username"`
Password string `json:"-" toml:"password"`
Database string `json:"database" toml:"database"`
MaxIdleConns int `json:"max_idle_conns" toml:"max_idle_conns"`
MaxOpenConns int `json:"max_open_conns" toml:"max_open_conns"`
ConnMaxLifetime timex.Duration `json:"conn_max_lifetime" toml:"conn_max_lifetime"`
Expand Down
27 changes: 18 additions & 9 deletions configs/postar.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ type PostarConfig struct {
func NewPostarConfig() *PostarConfig {
conf := &PostarConfig{
Logger: logitconf.Config{
Level: "debug",
Level: "debug",
Handler: "tape",
Writer: logitconf.WriterConfig{
Target: "./postar.log",
Target: "./log/postar.log",
FileRotate: true,
FileMaxSize: "128MB",
FileMaxAge: "30d",
Expand All @@ -35,22 +36,30 @@ func NewPostarConfig() *PostarConfig {
WithPID: false,
},
Server: ServerConfig{
Type: "grpc",
GrpcEndpoint: ":5897",
HttpEndpoint: ":6897",
RequestTimeout: timex.NewDuration(10 * time.Second),
MaxCloseWaitTime: timex.NewDuration(time.Minute),
Type: "gateway",
GrpcEndpoint: ":5897",
HttpEndpoint: ":6897",
UseTLS: false,
CertFile: "./cert/localhost.crt",
KeyFile: "./cert/localhost.key",
RequestTimeout: timex.NewDuration(10 * time.Second),
CloseServerTimeout: timex.NewDuration(time.Minute),
},
Database: DatabaseConfig{
Address: "127.0.0.1:6033",
Username: "postar",
Password: "123456",
Database: "postar",
MaxOpenConns: 64,
MaxIdleConns: 16,
ConnMaxLifetime: timex.NewDuration(5 * time.Minute),
ConnMaxIdleTime: timex.NewDuration(3 * time.Second),
ConnMaxIdleTime: timex.NewDuration(5 * time.Minute),
ConnMaxLifetime: timex.NewDuration(15 * time.Minute),
ReportStatsTime: timex.NewDuration(time.Minute),
},
Crypto: CryptoConfig{
AESKey: "",
AESIV: "",
},
}

return conf
Expand Down
37 changes: 26 additions & 11 deletions configs/postar.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,50 @@
# level has some available values: debug, info, warn, error.
# handler has some available values: tape, text, json.
# target is the logging destination for writing logs.
# file_rotate will rotate log files if needs.
# file_max_size is the max size to rotate a new log file and rename the old log file.
# file_max_age is the max time to keep the old log files.
# file_max_backups is the max number to keep the old log files.
# file_max_backups is the max count to keep the old log files.
# Check `FishGoddess/logit` library in github to get more information.
[logger]
level = "debug"
handler = "tape"

[logger.writer]
target = "./logs/postar.log"
target = "./log/postar.log"
file_rotate = true
file_max_size = "128M"
file_max_age = "30d"
file_max_backups = 60

# All configurations of server.
# type has some available values: http, grpc.
# address includes ip and port and you can bind a specific ip and port for your server.
# close_timeout is the timeout of closing server.
# type has some available values: gateway, grpc.
# grpc_endpoint is the ip:port of the grpc server.
# http_endpoint is the ip:port of the http server when type is gateway.
# use_tls determines if the server uses tls or not.
# cert_file is the certificate file path. Necessary if use_tls = true.
# key_file is the private key file path. Necessary if use_tls = true.
# request_timeout is the timeout of requests.
# close_server_timeout is the timeout of closing server.
[server]
type = "gateway"
grpc_endpoint = ":5897"
http_endpoint = ":6897"
use_tls = false
cert_file = "./cert/localhost.crt"
key_file = "./cert/localhost.key"
request_timeout = "10s"
max_close_wait_time = "1m"
close_server_timeout = "1m"

# All configurations of database.
# You should specify the authentication of database with address, username and password.
# Of course, database is necessary.
# address is the ip:port of the database.
# username is the username of the database.
# password is the password of the database.
# max_open_conns is the max connected connections of the database.
# max_idle_conns is the max idle connections of the database.
# max_conn_idle_time is the max idle time of connections connected to database.
# max_conn_lifetime is the max lifetime of connections connected to database.
# report_stats_time is the duration for reporting the stats of database.
[database]
address = "127.0.0.1:6033"
username = "postar"
Expand All @@ -39,12 +54,12 @@ database = "postar"
max_open_conns = 64
max_idle_conns = 16
max_conn_idle_time = "5m"
max_conn_lifetime = "30m"
max_conn_lifetime = "15m"
report_stats_time = "1m"

# All configurations of crypto.
# aes_key is the key of aes, its length must be 24.
# aes_iv is the iv of aes, its length must be 16.
# aes_key is the key of aes which length must be 24.
# aes_iv is the iv of aes which length must be 16.
[crypto]
aes_key = "123456788765432112345678"
aes_iv = "1234567887654321"
27 changes: 18 additions & 9 deletions configs/postar_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ type PostarAdminConfig struct {
func NewPostarAdminConfig() *PostarAdminConfig {
conf := &PostarAdminConfig{
Logger: logitconf.Config{
Level: "debug",
Level: "debug",
Handler: "tape",
Writer: logitconf.WriterConfig{
Target: "./postar_admin.log",
Target: "./log/postar_admin.log",
FileRotate: true,
FileMaxSize: "128MB",
FileMaxAge: "60d",
Expand All @@ -35,22 +36,30 @@ func NewPostarAdminConfig() *PostarAdminConfig {
WithPID: false,
},
Server: ServerConfig{
Type: "grpc",
GrpcEndpoint: ":7985",
HttpEndpoint: ":7986",
RequestTimeout: timex.NewDuration(10 * time.Second),
MaxCloseWaitTime: timex.NewDuration(time.Minute),
Type: "gateway",
GrpcEndpoint: ":7985",
HttpEndpoint: ":7986",
UseTLS: false,
CertFile: "./cert/localhost.crt",
KeyFile: "./cert/localhost.key",
RequestTimeout: timex.NewDuration(time.Second),
CloseServerTimeout: timex.NewDuration(time.Minute),
},
Database: DatabaseConfig{
Address: "127.0.0.1:6033",
Username: "postar",
Password: "123456",
Database: "postar",
MaxOpenConns: 16,
MaxIdleConns: 4,
ConnMaxLifetime: timex.NewDuration(3 * time.Minute),
ConnMaxIdleTime: timex.NewDuration(time.Second),
ConnMaxIdleTime: timex.NewDuration(3 * time.Minute),
ConnMaxLifetime: timex.NewDuration(10 * time.Minute),
ReportStatsTime: timex.NewDuration(time.Minute),
},
Crypto: CryptoConfig{
AESKey: "",
AESIV: "",
},
}

return conf
Expand Down
37 changes: 26 additions & 11 deletions configs/postar_admin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,50 @@
# level has some available values: debug, info, warn, error.
# handler has some available values: tape, text, json.
# target is the logging destination for writing logs.
# file_rotate will rotate log files if needs.
# file_max_size is the max size to rotate a new log file and rename the old log file.
# file_max_age is the max time to keep the old log files.
# file_max_backups is the max number to keep the old log files.
# file_max_backups is the max count to keep the old log files.
# Check `FishGoddess/logit` library in github to get more information.
[logger]
level = "debug"
handler = "tape"

[logger.writer]
target = "./logs/postar_admin.log"
target = "./log/postar_admin.log"
file_rotate = true
file_max_size = "128M"
file_max_age = "60d"
file_max_backups = 90

# All configurations of server.
# type has some available values: http, grpc.
# address includes ip and port and you can bind a specific ip and port for your server.
# close_timeout is the timeout of closing server.
# type has some available values: gateway, grpc.
# grpc_endpoint is the ip:port of the grpc server.
# http_endpoint is the ip:port of the http server when type is gateway.
# use_tls determines if the server uses tls or not.
# cert_file is the certificate file path. Necessary if use_tls = true.
# key_file is the private key file path. Necessary if use_tls = true.
# request_timeout is the timeout of requests.
# close_server_timeout is the timeout of closing server.
[server]
type = "gateway"
grpc_endpoint = ":7985"
http_endpoint = ":7986"
request_timeout = "10s"
max_close_wait_time = "1m"
use_tls = false
cert_file = "./cert/localhost.crt"
key_file = "./cert/localhost.key"
request_timeout = "1s"
close_server_timeout = "1m"

# All configurations of database.
# You should specify the authentication of database with address, username and password.
# Of course, database is necessary.
# address is the ip:port of the database.
# username is the username of the database.
# password is the password of the database.
# max_open_conns is the max connected connections of the database.
# max_idle_conns is the max idle connections of the database.
# max_conn_idle_time is the max idle time of connections connected to database.
# max_conn_lifetime is the max lifetime of connections connected to database.
# report_stats_time is the duration for reporting the stats of database.
[database]
address = "127.0.0.1:6033"
username = "postar"
Expand All @@ -43,8 +58,8 @@ max_conn_lifetime = "10m"
report_stats_time = "1m"

# All configurations of crypto.
# aes_key is the key of aes, its length must be 24.
# aes_iv is the iv of aes, its length must be 16.
# aes_key is the key of aes which length must be 24.
# aes_iv is the iv of aes which length must be 16.
[crypto]
aes_key = "123456788765432112345678"
aes_iv = "1234567887654321"
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
package postar

const (
Version = "v0.4.1-alpha"
Version = "v0.4.2-alpha"
)
Loading

0 comments on commit f5cc6e5

Please sign in to comment.